COMPILE_DEFINITIONS property: ensure leading -D is removed in all cases

Fixes: #24186
This commit is contained in:
Marc Chevrier
2022-12-08 14:52:56 +01:00
parent ff875ed859
commit 7480fa0a5f
18 changed files with 114 additions and 2 deletions
+1
View File
@@ -693,6 +693,7 @@ add_RunCMake_test(target_link_options -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_I
set_property(TEST RunCMake.target_link_options APPEND
PROPERTY LABELS "CUDA")
add_RunCMake_test(add_compile_definitions)
add_RunCMake_test(target_compile_definitions)
add_RunCMake_test(target_compile_features)
add_RunCMake_test(target_compile_options
@@ -0,0 +1,11 @@
enable_language(C)
set_property(SOURCE foo.c PROPERTY COMPILE_DEFINITIONS -DDEF0 "$<1:-DDEF1>")
add_library(lib1 foo.c)
set_property(TARGET lib1 PROPERTY COMPILE_DEFINITIONS -DDEF2 "$<1:-DDEF3>")
set_property(TARGET lib1 PROPERTY INTERFACE_COMPILE_DEFINITIONS -DDEF4 "$<1:-DDEF5>")
add_library(lib2 foo.c)
target_link_libraries(lib2 PRIVATE lib1)
@@ -1,3 +1,16 @@
include(RunCMake)
run_cmake(SetEmpty)
macro(run_cmake_build test)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(${test} ${CMAKE_COMMAND} --build . --config Release)
unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN)
endmacro()
run_cmake(RemoveLeadingMinusD)
run_cmake_build(RemoveLeadingMinusD)
+4
View File
@@ -0,0 +1,4 @@
void foo()
{
}
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.11)
project(${RunCMake_TEST} LANGUAGES NONE)
include(${RunCMake_TEST}.cmake)
@@ -0,0 +1,13 @@
include(RunCMake)
macro(run_cmake_build test)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(${test} ${CMAKE_COMMAND} --build . --config Release)
unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN)
endmacro()
run_cmake(remove_leading_minusD)
run_cmake_build(remove_leading_minusD)
@@ -0,0 +1,4 @@
void foo()
{
}
@@ -0,0 +1,6 @@
enable_language(C)
add_compile_definitions(-DDEF0 "$<1:-DDEF1>")
add_library(lib1 foo.c)
@@ -2,3 +2,16 @@ include(RunCMake)
run_cmake(empty_keyword_args)
run_cmake(unknown_imported_target)
macro(run_cmake_build test)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(${test} ${CMAKE_COMMAND} --build . --config Release)
unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN)
endmacro()
run_cmake(remove_leading_minusD)
run_cmake_build(remove_leading_minusD)
@@ -0,0 +1,4 @@
void foo()
{
}
@@ -0,0 +1,9 @@
enable_language(C)
add_library(lib1 foo.c)
target_compile_definitions(lib1 PRIVATE -DDEF0 "$<1:-DDEF1>")
target_compile_definitions(lib1 PUBLIC -DDEF2 "$<1:-DDEF3>")
add_library(lib2 foo.c)
target_link_libraries(lib2 PRIVATE lib1)