summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2021-03-31 16:45:05 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2021-03-31 17:03:35 (GMT)
commit6cf81efe7d95e3cf43028ef5122a814d8d7f3aa0 (patch)
tree91a61bd9d7289b3f510d2f64097529cef294c0f8
parent36f1f7c449a4b213b207032a32082d78fd866348 (diff)
downloadCMake-6cf81efe7d95e3cf43028ef5122a814d8d7f3aa0.zip
CMake-6cf81efe7d95e3cf43028ef5122a814d8d7f3aa0.tar.gz
CMake-6cf81efe7d95e3cf43028ef5122a814d8d7f3aa0.tar.bz2
Genex: $<HOST_LINK:> and $<DEVICE_LINK:> must be usable in try_compile
Fixes: #22007
-rw-r--r--Source/cmExportTryCompileFileGenerator.cxx13
-rw-r--r--Tests/RunCMake/GenEx-DEVICE_LINK/DEVICE_LINK-try_compile.cmake9
-rw-r--r--Tests/RunCMake/GenEx-DEVICE_LINK/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/GenEx-HOST_LINK/HOST_LINK-try_compile.cmake9
-rw-r--r--Tests/RunCMake/GenEx-HOST_LINK/RunCMakeTest.cmake1
5 files changed, 31 insertions, 2 deletions
diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx
index c6b6184..cac60e1 100644
--- a/Source/cmExportTryCompileFileGenerator.cxx
+++ b/Source/cmExportTryCompileFileGenerator.cxx
@@ -3,9 +3,10 @@
#include "cmExportTryCompileFileGenerator.h"
#include <map>
-#include <memory>
#include <utility>
+#include <cm/memory>
+
#include "cmGeneratorExpression.h"
#include "cmGeneratorExpressionDAGChecker.h"
#include "cmGeneratorTarget.h"
@@ -66,7 +67,15 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
cmGeneratorExpression ge;
- cmGeneratorExpressionDAGChecker dagChecker(tgt, propName, nullptr, nullptr);
+ std::unique_ptr<cmGeneratorExpressionDAGChecker> parentDagChecker;
+ if (propName == "INTERFACE_LINK_OPTIONS") {
+ // To please constraint checks of DAGChecker, this property must have
+ // LINK_OPTIONS property as parent
+ parentDagChecker = cm::make_unique<cmGeneratorExpressionDAGChecker>(
+ tgt, "LINK_OPTIONS", nullptr, nullptr);
+ }
+ cmGeneratorExpressionDAGChecker dagChecker(tgt, propName, nullptr,
+ parentDagChecker.get());
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*prop);
diff --git a/Tests/RunCMake/GenEx-DEVICE_LINK/DEVICE_LINK-try_compile.cmake b/Tests/RunCMake/GenEx-DEVICE_LINK/DEVICE_LINK-try_compile.cmake
new file mode 100644
index 0000000..281f8aa
--- /dev/null
+++ b/Tests/RunCMake/GenEx-DEVICE_LINK/DEVICE_LINK-try_compile.cmake
@@ -0,0 +1,9 @@
+
+enable_language(C)
+
+add_library(demo INTERFACE IMPORTED)
+set_property(TARGET demo PROPERTY INTERFACE_LINK_OPTIONS "$<DEVICE_LINK:>")
+
+set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
+try_compile(result "${CMAKE_CURRENT_BINARY_DIR}/tc" "${CMAKE_CURRENT_SOURCE_DIR}/empty.c"
+ LINK_LIBRARIES demo)
diff --git a/Tests/RunCMake/GenEx-DEVICE_LINK/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-DEVICE_LINK/RunCMakeTest.cmake
index 1e44601..80633e2 100644
--- a/Tests/RunCMake/GenEx-DEVICE_LINK/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GenEx-DEVICE_LINK/RunCMakeTest.cmake
@@ -12,6 +12,7 @@ run_cmake(DEVICE_LINK-target_compile_options)
run_cmake(DEVICE_LINK-target_include_directories)
run_cmake(DEVICE_LINK-target_link_libraries)
run_cmake(DEVICE_LINK-target_link_directories)
+run_cmake(DEVICE_LINK-try_compile)
if(RunCMake_GENERATOR MATCHES "(Ninja|Makefile)")
run_cmake(DEVICE_LINK-link_depends)
endif()
diff --git a/Tests/RunCMake/GenEx-HOST_LINK/HOST_LINK-try_compile.cmake b/Tests/RunCMake/GenEx-HOST_LINK/HOST_LINK-try_compile.cmake
new file mode 100644
index 0000000..f221ff1
--- /dev/null
+++ b/Tests/RunCMake/GenEx-HOST_LINK/HOST_LINK-try_compile.cmake
@@ -0,0 +1,9 @@
+
+enable_language(C)
+
+add_library(demo INTERFACE IMPORTED)
+set_property(TARGET demo PROPERTY INTERFACE_LINK_OPTIONS "$<HOST_LINK:>")
+
+set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
+try_compile(result "${CMAKE_CURRENT_BINARY_DIR}/tc" "${CMAKE_CURRENT_SOURCE_DIR}/empty.c"
+ LINK_LIBRARIES demo)
diff --git a/Tests/RunCMake/GenEx-HOST_LINK/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-HOST_LINK/RunCMakeTest.cmake
index 329a7c6..9e3eeec 100644
--- a/Tests/RunCMake/GenEx-HOST_LINK/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GenEx-HOST_LINK/RunCMakeTest.cmake
@@ -12,6 +12,7 @@ run_cmake(HOST_LINK-target_compile_options)
run_cmake(HOST_LINK-target_include_directories)
run_cmake(HOST_LINK-target_link_libraries)
run_cmake(HOST_LINK-target_link_directories)
+run_cmake(HOST_LINK-try_compile)
if(RunCMake_GENERATOR MATCHES "(Ninja|Makefile)")
run_cmake(HOST_LINK-link_depends)
endif()