COMPILE_DEFINITIONS property: ensure leading -D is removed in all cases
Fixes: #24186
This commit is contained in:
parent
ff875ed859
commit
7480fa0a5f
@ -21,6 +21,9 @@ Function-style definitions are not supported. CMake will automatically
|
|||||||
escape the value correctly for the native build system (note that CMake
|
escape the value correctly for the native build system (note that CMake
|
||||||
language syntax may require escapes to specify some values).
|
language syntax may require escapes to specify some values).
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
Any leading ``-D`` on an item will be removed.
|
||||||
|
|
||||||
.. |command_name| replace:: ``add_compile_definitions``
|
.. |command_name| replace:: ``add_compile_definitions``
|
||||||
.. include:: GENEX_NOTE.txt
|
.. include:: GENEX_NOTE.txt
|
||||||
|
|
||||||
|
@ -19,6 +19,9 @@ directory's parent.
|
|||||||
CMake will automatically drop some definitions that are not supported
|
CMake will automatically drop some definitions that are not supported
|
||||||
by the native build tool.
|
by the native build tool.
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
Any leading ``-D`` on an item will be removed.
|
||||||
|
|
||||||
.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
|
.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
|
||||||
|
|
||||||
Contents of ``COMPILE_DEFINITIONS`` may use "generator expressions" with
|
Contents of ``COMPILE_DEFINITIONS`` may use "generator expressions" with
|
||||||
|
@ -16,6 +16,9 @@ CMake will automatically drop some definitions that are not supported
|
|||||||
by the native build tool. Xcode does not support per-configuration
|
by the native build tool. Xcode does not support per-configuration
|
||||||
definitions on source files.
|
definitions on source files.
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
Any leading ``-D`` on an item will be removed.
|
||||||
|
|
||||||
.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
|
.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
|
||||||
|
|
||||||
Contents of ``COMPILE_DEFINITIONS`` may use :manual:`cmake-generator-expressions(7)`
|
Contents of ``COMPILE_DEFINITIONS`` may use :manual:`cmake-generator-expressions(7)`
|
||||||
|
@ -13,6 +13,9 @@ values).
|
|||||||
CMake will automatically drop some definitions that are not supported
|
CMake will automatically drop some definitions that are not supported
|
||||||
by the native build tool.
|
by the native build tool.
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
Any leading ``-D`` on an item will be removed.
|
||||||
|
|
||||||
.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
|
.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
|
||||||
|
|
||||||
Contents of ``COMPILE_DEFINITIONS`` may use "generator expressions" with the
|
Contents of ``COMPILE_DEFINITIONS`` may use "generator expressions" with the
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
COMPILE_DEFINITIONS-property-cleanup
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
* For all ``COMPILE_DEFINITIONS`` properties, any leading ``-D`` on an item
|
||||||
|
will be removed regardless how to was defined: as is or inside a generator
|
||||||
|
expression.
|
@ -4995,7 +4995,13 @@ void cmGlobalXCodeGenerator::AppendDefines(
|
|||||||
std::string def;
|
std::string def;
|
||||||
for (auto const& define : defines) {
|
for (auto const& define : defines) {
|
||||||
// Start with -D if requested.
|
// Start with -D if requested.
|
||||||
def = cmStrCat(dflag ? "-D" : "", define);
|
if (dflag && !cmHasLiteralPrefix(define, "-D")) {
|
||||||
|
def = cmStrCat("-D", define);
|
||||||
|
} else if (!dflag && cmHasLiteralPrefix(define, "-D")) {
|
||||||
|
def = define.substr(2);
|
||||||
|
} else {
|
||||||
|
def = define;
|
||||||
|
}
|
||||||
|
|
||||||
// Append the flag with needed escapes.
|
// Append the flag with needed escapes.
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
|
@ -3377,7 +3377,12 @@ void cmLocalGenerator::AppendDefines(
|
|||||||
if (!this->CheckDefinition(d.Value)) {
|
if (!this->CheckDefinition(d.Value)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
defines.insert(d);
|
// remove any leading -D
|
||||||
|
if (cmHasLiteralPrefix(d.Value, "-D")) {
|
||||||
|
defines.emplace(d.Value.substr(2), d.Backtrace);
|
||||||
|
} else {
|
||||||
|
defines.insert(d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
set_property(TEST RunCMake.target_link_options APPEND
|
||||||
PROPERTY LABELS "CUDA")
|
PROPERTY LABELS "CUDA")
|
||||||
|
|
||||||
|
add_RunCMake_test(add_compile_definitions)
|
||||||
add_RunCMake_test(target_compile_definitions)
|
add_RunCMake_test(target_compile_definitions)
|
||||||
add_RunCMake_test(target_compile_features)
|
add_RunCMake_test(target_compile_features)
|
||||||
add_RunCMake_test(target_compile_options
|
add_RunCMake_test(target_compile_options
|
||||||
|
11
Tests/RunCMake/CompileDefinitions/RemoveLeadingMinusD.cmake
Normal file
11
Tests/RunCMake/CompileDefinitions/RemoveLeadingMinusD.cmake
Normal file
@ -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)
|
include(RunCMake)
|
||||||
|
|
||||||
run_cmake(SetEmpty)
|
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
Tests/RunCMake/CompileDefinitions/foo.c
Normal file
4
Tests/RunCMake/CompileDefinitions/foo.c
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
void foo()
|
||||||
|
{
|
||||||
|
}
|
5
Tests/RunCMake/add_compile_definitions/CMakeLists.txt
Normal file
5
Tests/RunCMake/add_compile_definitions/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.11)
|
||||||
|
|
||||||
|
project(${RunCMake_TEST} LANGUAGES NONE)
|
||||||
|
|
||||||
|
include(${RunCMake_TEST}.cmake)
|
13
Tests/RunCMake/add_compile_definitions/RunCMakeTest.cmake
Normal file
13
Tests/RunCMake/add_compile_definitions/RunCMakeTest.cmake
Normal file
@ -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)
|
4
Tests/RunCMake/add_compile_definitions/foo.c
Normal file
4
Tests/RunCMake/add_compile_definitions/foo.c
Normal file
@ -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(empty_keyword_args)
|
||||||
run_cmake(unknown_imported_target)
|
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)
|
||||||
|
4
Tests/RunCMake/target_compile_definitions/foo.c
Normal file
4
Tests/RunCMake/target_compile_definitions/foo.c
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user