mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
ASM: Record all assembler id information
Previously, `CMAKE_ASM${DIALECT}_COMPILER_FRONTEND_VARIANT` and
`CMAKE_ASM${DIALECT}_SIMULATE_ID` were not saved in with the build
configuration. As a result, these were left unpopulated on re-configure.
This is particularly problematic when `clang-cl` is used as the
assembler on Windows, since CMake would mistakenly identify the build as
being "GCC on Windows", resulting in include paths being passed with
forward slashes on re-configure, causing a full rebuild.
Fix the issue by saving the information so it persists across
re-configures.
This commit is contained in:
committed by
Brad King
parent
fd093f59e7
commit
d75d5dfadf
@@ -18,6 +18,8 @@ set(CMAKE_ASM@ASM_DIALECT@_COMPILER_LOADED 1)
|
||||
set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ID "@_CMAKE_ASM_COMPILER_ID@")
|
||||
set(CMAKE_ASM@ASM_DIALECT@_COMPILER_VERSION "@_CMAKE_ASM_COMPILER_VERSION@")
|
||||
set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ENV_VAR "@_CMAKE_ASM_COMPILER_ENV_VAR@")
|
||||
set(CMAKE_ASM@ASM_DIALECT@_COMPILER_FRONTEND_VARIANT "@_CMAKE_ASM_COMPILER_FRONTEND_VARIANT@")
|
||||
set(CMAKE_ASM@ASM_DIALECT@_SIMULATE_ID "@_CMAKE_ASM_SIMULATE_ID@")
|
||||
@_SET_CMAKE_ASM_COMPILER_ID_VENDOR_MATCH@
|
||||
set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ARCHITECTURE_ID "@_CMAKE_ASM_COMPILER_ARCHITECTURE_ID@")
|
||||
@_SET_CMAKE_ASM_COMPILER_SYSROOT@
|
||||
|
||||
@@ -297,7 +297,7 @@ endif()
|
||||
# configure variables set in this file for fast reload later on
|
||||
block()
|
||||
foreach(_var IN ITEMS
|
||||
# Keep in sync with Internal/CMakeTestASMLinker.
|
||||
# Keep in sync with Internal/CMakeInspectASMLinker.
|
||||
COMPILER
|
||||
COMPILER_ID
|
||||
COMPILER_ARG1
|
||||
@@ -306,6 +306,8 @@ block()
|
||||
COMPILER_RANLIB
|
||||
COMPILER_VERSION
|
||||
COMPILER_ARCHITECTURE_ID
|
||||
COMPILER_FRONTEND_VARIANT
|
||||
SIMULATE_ID
|
||||
)
|
||||
set(_CMAKE_ASM_${_var} "${CMAKE_ASM${ASM_DIALECT}_${_var}}")
|
||||
endforeach()
|
||||
|
||||
@@ -14,6 +14,8 @@ block()
|
||||
COMPILER_RANLIB
|
||||
COMPILER_VERSION
|
||||
COMPILER_ARCHITECTURE_ID
|
||||
COMPILER_FRONTEND_VARIANT
|
||||
SIMULATE_ID
|
||||
# Linker information.
|
||||
COMPILER_LINKER
|
||||
COMPILER_LINKER_ID
|
||||
|
||||
@@ -393,6 +393,7 @@ if(CMAKE_GENERATOR MATCHES "Make|Ninja")
|
||||
add_RunCMake_test(Color)
|
||||
endif()
|
||||
add_RunCMake_test(CompilerChange)
|
||||
add_RunCMake_test(CompilerInfo -DPSEUDO_ASM=$<TARGET_FILE:pseudo_asm>)
|
||||
add_RunCMake_test(CompilerNotFound)
|
||||
if(DEFINED CMake_TEST_OBJC)
|
||||
list(APPEND CMake_TEST_LANG_VARS -DCMake_TEST_OBJC=${CMake_TEST_OBJC})
|
||||
@@ -1288,6 +1289,7 @@ if(CMake_TEST_FindMatlab OR CMake_TEST_FindMatlab_MCR OR (NOT "${CMake_TEST_Find
|
||||
set_property(TEST RunCMake.FindMatlab APPEND PROPERTY LABELS "Matlab")
|
||||
endif()
|
||||
|
||||
add_executable(pseudo_asm pseudo_asm.c)
|
||||
add_executable(pseudo_emulator pseudo_emulator.c)
|
||||
add_executable(pseudo_emulator_custom_command pseudo_emulator_custom_command.c)
|
||||
add_executable(pseudo_emulator_custom_command_arg pseudo_emulator_custom_command_arg.c)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# The information file is what a later configure reloads, so load it the same
|
||||
# way and check that every field detection computed was recorded. The caller
|
||||
# sets the expect_* values for the assembler flavor under test.
|
||||
include("${RunCMake_TEST_BINARY_DIR}/CMakeFiles/${CMAKE_VERSION}/CMakeASMCompiler.cmake")
|
||||
|
||||
foreach(var
|
||||
CMAKE_ASM_COMPILER_ID
|
||||
CMAKE_ASM_SIMULATE_ID
|
||||
CMAKE_ASM_COMPILER_FRONTEND_VARIANT
|
||||
)
|
||||
if(NOT "${${var}}" STREQUAL "${expect_${var}}")
|
||||
string(APPEND RunCMake_TEST_FAILED
|
||||
"${var} was not recorded in the assembler information file:\n"
|
||||
" expected: '${expect_${var}}'\n"
|
||||
" reloaded: '${${var}}'\n")
|
||||
endif()
|
||||
endforeach()
|
||||
@@ -0,0 +1,4 @@
|
||||
set(expect_CMAKE_ASM_COMPILER_ID "Clang")
|
||||
set(expect_CMAKE_ASM_SIMULATE_ID "MSVC")
|
||||
set(expect_CMAKE_ASM_COMPILER_FRONTEND_VARIANT "MSVC")
|
||||
include("${RunCMake_SOURCE_DIR}/ASM-check-common.cmake")
|
||||
@@ -0,0 +1 @@
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/ASM-common.cmake")
|
||||
@@ -0,0 +1,5 @@
|
||||
# A GNU-like command-line leaves the simulate id empty.
|
||||
set(expect_CMAKE_ASM_COMPILER_ID "Clang")
|
||||
set(expect_CMAKE_ASM_SIMULATE_ID "")
|
||||
set(expect_CMAKE_ASM_COMPILER_FRONTEND_VARIANT "GNU")
|
||||
include("${RunCMake_SOURCE_DIR}/ASM-check-common.cmake")
|
||||
@@ -0,0 +1 @@
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/ASM-common.cmake")
|
||||
@@ -0,0 +1,15 @@
|
||||
# Assembler information is detected once and written to
|
||||
# CMakeASM<dialect>Compiler.cmake, then reloaded from that file on every later
|
||||
# configure. A field that detection computes but the file does not record
|
||||
# comes back empty, so a re-configure sees a different assembler than the one
|
||||
# that was detected. The -check script reloads the file and verifies this.
|
||||
|
||||
enable_language(ASM)
|
||||
|
||||
# Detection must identify the assembler in the first place.
|
||||
if(NOT CMAKE_ASM_COMPILER_ID)
|
||||
message(SEND_ERROR "CMAKE_ASM_COMPILER_ID was not detected")
|
||||
endif()
|
||||
if(NOT CMAKE_ASM_COMPILER_FRONTEND_VARIANT)
|
||||
message(SEND_ERROR "CMAKE_ASM_COMPILER_FRONTEND_VARIANT was not detected")
|
||||
endif()
|
||||
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 4.4)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
||||
@@ -0,0 +1,14 @@
|
||||
include(RunCMake)
|
||||
|
||||
block()
|
||||
# The stand-in assembler reports an MSVC-like command-line by default and a
|
||||
# GNU-like one when PSEUDO_ASM_GNU is set, which selects the two branches of
|
||||
# assembler identification that populate these fields differently.
|
||||
set(RunCMake_TEST_OPTIONS "-DCMAKE_ASM_COMPILER=${PSEUDO_ASM}")
|
||||
|
||||
run_cmake(ASM-clang-cl)
|
||||
|
||||
set(ENV{PSEUDO_ASM_GNU} 1)
|
||||
run_cmake(ASM-clang-gnu)
|
||||
unset(ENV{PSEUDO_ASM_GNU})
|
||||
endblock()
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
Usage: pseudo_asm [--version] [-?]
|
||||
|
||||
--version: print a banner that identifies this program as Clang.
|
||||
-?: return 0 for MSVC-like command-line, 1 for GNU-like command-line,
|
||||
depending on the presence of the PSEUDO_ASM_GNU environment variable.
|
||||
*/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "--version") == 0) {
|
||||
printf("clang version 99.0.0 (pseudo_asm)\n");
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(argv[i], "-?") == 0) {
|
||||
char const* gnu = getenv("PSEUDO_ASM_GNU");
|
||||
return (gnu && *gnu) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user