From 0fb923c46041d67110c8e0907afdf66b3b25f25a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 14 Jan 2023 23:58:28 -0500 Subject: cmGeneratorExpressionNode: implement `COMPILE_ONLY` genex This generator expression is the inverse of `LINK_ONLY` and only coveys usage requirements for the purposes of compilation. Its intended use is to avoid needing to export targets that do not have link usage requirements (e.g., header-only libraries) when used by another target. It will also be used to represent private usage requirements on exported C++ module-containing targets in the future. Eventually there should be logic to collapse nesting of `$` and `$` when generating instances of either. A TODO is left in the code for this case. See: #15415 --- .../GeneratorExpression/COMPILE_ONLY-not-compiling-result.txt | 1 + .../GeneratorExpression/COMPILE_ONLY-not-compiling-stderr.txt | 8 ++++++++ .../RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling.cmake | 1 + Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake | 1 + 4 files changed, 11 insertions(+) create mode 100644 Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling.cmake (limited to 'Tests') diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling-result.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling-stderr.txt new file mode 100644 index 0000000000..5e7fce2a1b --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at COMPILE_ONLY-not-compiling.cmake:1 \(add_custom_target\): + Error evaluating generator expression: + + \$ + + \$ may only be used via linking +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling.cmake new file mode 100644 index 0000000000..1bc75f98e5 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_ONLY-not-compiling.cmake @@ -0,0 +1 @@ +add_custom_target(Custom ALL COMMAND ${CMAKE_COMMAND} -E echo $) diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake index b139210d72..3fd994721b 100644 --- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake @@ -22,6 +22,7 @@ run_cmake(NonValidTarget-CXX_COMPILER_VERSION) run_cmake(NonValidTarget-Fortran_COMPILER_VERSION) run_cmake(NonValidTarget-TARGET_PROPERTY) run_cmake(NonValidTarget-TARGET_POLICY) +run_cmake(COMPILE_ONLY-not-compiling) run_cmake(LINK_ONLY-not-linking) run_cmake(TARGET_EXISTS-no-arg) run_cmake(TARGET_EXISTS-empty-arg) -- cgit v1.2.1