summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2024-03-22 09:48:00 (GMT)
committerCraig Scott <craig.scott@crascit.com>2024-03-22 10:35:51 (GMT)
commit98cc86e26545300c120481fc230b9fd270dbb226 (patch)
tree0994c94008971f3da20ccdc2aade869efcdd84f9
parent25d2850c190ba915a7527a29dda6efe61be901f0 (diff)
downloadCMake-98cc86e26545300c120481fc230b9fd270dbb226.zip
CMake-98cc86e26545300c120481fc230b9fd270dbb226.tar.gz
CMake-98cc86e26545300c120481fc230b9fd270dbb226.tar.bz2
try_compile(): Include languages with _ or - when passing linker vars
Fixes: #25809
-rw-r--r--Source/cmCoreTryCompile.cxx2
-rw-r--r--Tests/RunCMake/try_compile/ProjectVars-stdout.txt8
-rw-r--r--Tests/RunCMake/try_compile/ProjectVars.cmake18
-rw-r--r--Tests/RunCMake/try_compile/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/try_compile/proj_vars/CMakeLists.txt12
5 files changed, 41 insertions, 1 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index a4f36cc..324c5ad 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -1163,7 +1163,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
vars.insert(kCMAKE_LINKER_TYPE);
auto defs = this->Makefile->GetDefinitions();
cmsys::RegularExpression linkerTypeDef{
- "^CMAKE_[A-Za-z]+_USING_LINKER_"
+ "^CMAKE_[A-Za-z_-]+_USING_LINKER_"
};
for (auto const& def : defs) {
if (linkerTypeDef.find(def)) {
diff --git a/Tests/RunCMake/try_compile/ProjectVars-stdout.txt b/Tests/RunCMake/try_compile/ProjectVars-stdout.txt
new file mode 100644
index 0000000..1744bbc
--- /dev/null
+++ b/Tests/RunCMake/try_compile/ProjectVars-stdout.txt
@@ -0,0 +1,8 @@
+CMAKE_LINKER_TYPE = DEFAULT
+.*CMAKE_C_USING_LINKER_MODE = [^
+]*
+.*CMAKE_C_USING_LINKER_abc123 = /path/to/somewhere
+.*CMAKE_C_USING_LINKER_Hi_There = some-tool
+.*CMAKE_ASM_NASM_USING_LINKER_custom = /place/holder
+.*CMAKE_ASM-ATT_USING_LINKER_custom = /more/text
+.*CMAKE_ASM-ATT_USING_LINKER_MODE = TOOL
diff --git a/Tests/RunCMake/try_compile/ProjectVars.cmake b/Tests/RunCMake/try_compile/ProjectVars.cmake
new file mode 100644
index 0000000..f51fa7d
--- /dev/null
+++ b/Tests/RunCMake/try_compile/ProjectVars.cmake
@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 3.29)
+
+enable_language(C)
+
+set(CMAKE_LINKER_TYPE DEFAULT)
+set(CMAKE_C_USING_LINKER_abc123 /path/to/somewhere)
+set(CMAKE_C_USING_LINKER_Hi_There some-tool)
+set(CMAKE_ASM_NASM_USING_LINKER_custom /place/holder)
+set(CMAKE_ASM-ATT_USING_LINKER_custom /more/text)
+set(CMAKE_ASM-ATT_USING_LINKER_MODE TOOL)
+
+try_compile(RESULT
+ PROJECT TestProject
+ SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/proj_vars
+ OUTPUT_VARIABLE output
+)
+
+message(STATUS "\n${output}")
diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
index 29c0538..229c102 100644
--- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake
+++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
@@ -47,6 +47,8 @@ run_cmake(NonSourceCompileDefinitions)
run_cmake(Verbose)
+run_cmake(ProjectVars)
+
set(RunCMake_TEST_OPTIONS --debug-trycompile)
run_cmake(PlatformVariables)
run_cmake(WarnDeprecated)
diff --git a/Tests/RunCMake/try_compile/proj_vars/CMakeLists.txt b/Tests/RunCMake/try_compile/proj_vars/CMakeLists.txt
new file mode 100644
index 0000000..7f97ff2
--- /dev/null
+++ b/Tests/RunCMake/try_compile/proj_vars/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.29)
+project(TestProject LANGUAGES NONE)
+
+add_custom_target(show_vars ALL
+ COMMAND ${CMAKE_COMMAND} -E echo "CMAKE_LINKER_TYPE = ${CMAKE_LINKER_TYPE}"
+ COMMAND ${CMAKE_COMMAND} -E echo "CMAKE_C_USING_LINKER_MODE = ${CMAKE_C_USING_LINKER_MODE}"
+ COMMAND ${CMAKE_COMMAND} -E echo "CMAKE_C_USING_LINKER_abc123 = ${CMAKE_C_USING_LINKER_abc123}"
+ COMMAND ${CMAKE_COMMAND} -E echo "CMAKE_C_USING_LINKER_Hi_There = ${CMAKE_C_USING_LINKER_Hi_There}"
+ COMMAND ${CMAKE_COMMAND} -E echo "CMAKE_ASM_NASM_USING_LINKER_custom = ${CMAKE_ASM_NASM_USING_LINKER_custom}"
+ COMMAND ${CMAKE_COMMAND} -E echo "CMAKE_ASM-ATT_USING_LINKER_custom = ${CMAKE_ASM-ATT_USING_LINKER_custom}"
+ COMMAND ${CMAKE_COMMAND} -E echo "CMAKE_ASM-ATT_USING_LINKER_MODE = ${CMAKE_ASM-ATT_USING_LINKER_MODE}"
+)