diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-04-24 15:42:14 (GMT) |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-05-14 14:31:22 (GMT) |
commit | 3d4b70ea6474c8f29d6b5c057126582dcaad7ea7 (patch) | |
tree | d683c5a91d360982f740645dc45765b3b9d52089 /Tests/Properties | |
parent | 4dc95526868d903c7f9e9505001cb5dbeec259c0 (diff) | |
download | CMake-3d4b70ea6474c8f29d6b5c057126582dcaad7ea7.zip CMake-3d4b70ea6474c8f29d6b5c057126582dcaad7ea7.tar.gz CMake-3d4b70ea6474c8f29d6b5c057126582dcaad7ea7.tar.bz2 |
set_source_files_properties: Allow specification of directory scope
Both set_source_files_properties() and set_property(SOURCE) now accept
two new optional arguments: DIRECTORY and TARGET_DIRECTORY.
The DIRECTORY option takes a list of relative or absolute paths
pointing to processed source directories (add_subdirectory was
already called on them).
These paths specify directory scopes where the source file properties
will be set. Previously the scope was always the currently processed
source directory.
Similarly TARGET_DIRECTORY takes a list of targets, whose source
directories will be used as the list of scopes where to set the
source file properties.
get_property() and get_source_file_property() also get the same
new arguments, except only one value can be specified instead
of a list.
Fixes: #20128
Diffstat (limited to 'Tests/Properties')
-rw-r--r-- | Tests/Properties/CMakeLists.txt | 139 | ||||
-rw-r--r-- | Tests/Properties/SubDir2/CMakeLists.txt | 25 |
2 files changed, 164 insertions, 0 deletions
diff --git a/Tests/Properties/CMakeLists.txt b/Tests/Properties/CMakeLists.txt index a263061..f93f553 100644 --- a/Tests/Properties/CMakeLists.txt +++ b/Tests/Properties/CMakeLists.txt @@ -144,4 +144,143 @@ set_property(CACHE SOME_ENTRY PROPERTY ADVANCED "${expect_ADVANCED}") set_property(CACHE SOME_ENTRY PROPERTY STRINGS "${expect_STRINGS}") check_cache_props() +function(generate_file_for_set_property_test i target_name) + set(src_path "${CMAKE_CURRENT_BINARY_DIR}/src${i}.cpp") + file(GENERATE OUTPUT "${src_path}" CONTENT + "#ifndef def${i}\n\ + #error Expected def${i}\n\ + #endif\n\ + #ifdef _WIN32\n\ + __declspec(dllexport)\n\ + #endif\n\ + void dummy_symbol${i}() {}\n") + target_sources(${target_name} PRIVATE "${src_path}") +endfunction() + +add_library(maindirtest SHARED) add_subdirectory(SubDir2) + +set(src_prefix "${CMAKE_CURRENT_BINARY_DIR}/SubDir2/") + +# Set property + target directory +set_property(SOURCE "${src_prefix}/src1.cpp" + TARGET_DIRECTORY set_prop_lib_1 + PROPERTY COMPILE_DEFINITIONS def1) + +# Append property + target directory +set_property(SOURCE "${src_prefix}/src2.cpp" + TARGET_DIRECTORY set_prop_lib_1 + APPEND PROPERTY COMPILE_DEFINITIONS def2) + +# Set property + relative directory path +set_property(SOURCE "${src_prefix}/src3.cpp" + DIRECTORY SubDir2 + PROPERTY COMPILE_DEFINITIONS def3) + +# Set property + absolute directory path +set_property(SOURCE "${src_prefix}/src4.cpp" + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/SubDir2" + PROPERTY COMPILE_DEFINITIONS def4) + +# Append property + relative directory path +set_property(SOURCE "${src_prefix}/src5.cpp" + DIRECTORY SubDir2 + APPEND PROPERTY COMPILE_DEFINITIONS def5) + +# Append property + absolute directory path +set_property(SOURCE "${src_prefix}/src6.cpp" + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/SubDir2" + APPEND PROPERTY COMPILE_DEFINITIONS def6) + + +# Target directory +set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src10.cpp" + TARGET_DIRECTORY set_prop_lib_1 + PROPERTIES COMPILE_DEFINITIONS def10) + +# Relative directory path +set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src11.cpp" + DIRECTORY SubDir2 + PROPERTIES COMPILE_DEFINITIONS def11) + +# Absolute directory path +set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src12.cpp" + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/SubDir2" + PROPERTIES COMPILE_DEFINITIONS def12) + + +# Multiple files + absolute directory path +set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src20.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src21.cpp" + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/SubDir2" + PROPERTIES COMPILE_DEFINITIONS "def20;def21") + +# Multiple files + multiple target directories +set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src22.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src23.cpp" + TARGET_DIRECTORY set_prop_lib_2 set_prop_lib_3 + PROPERTIES COMPILE_DEFINITIONS "def22;def23") + + +# Multiple files in multiple relative directories +generate_file_for_set_property_test(30 maindirtest) +set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/src30.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src31.cpp" + DIRECTORY . SubDir2 + PROPERTIES COMPILE_DEFINITIONS "def30;def31") + +# Check that specifying files without any properties doesn't crash. +set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/src30.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src31.cpp") + +function(check_get_property_value expected) + if(NOT actual STREQUAL expected) + message(SEND_ERROR "Error: get_property returned unexpected value\n" + "actual: ${actual}\n" + "expected: ${expected}") + endif() +endfunction() + +# Get property + target directory +get_property(actual + SOURCE "${src_prefix}/src1.cpp" + TARGET_DIRECTORY set_prop_lib_1 + PROPERTY COMPILE_DEFINITIONS) +check_get_property_value("def1") + +# Get property + relative directory path +get_property(actual + SOURCE "${src_prefix}/src3.cpp" + DIRECTORY SubDir2 + PROPERTY COMPILE_DEFINITIONS) +check_get_property_value("def3") + +# Get property + absolute directory path +get_property(actual + SOURCE "${src_prefix}/src4.cpp" + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/SubDir2" + PROPERTY COMPILE_DEFINITIONS) +check_get_property_value("def4") + + +# Get property + target directory +unset(actual) +get_source_file_property(actual + "${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src10.cpp" + TARGET_DIRECTORY set_prop_lib_1 + COMPILE_DEFINITIONS) +check_get_property_value("def10") + +# Get property + relative directory path +get_source_file_property(actual + "${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src11.cpp" + DIRECTORY SubDir2 + COMPILE_DEFINITIONS) +check_get_property_value("def11") + +# Get property + absolute directory path +get_source_file_property(actual + "${CMAKE_CURRENT_BINARY_DIR}/SubDir2/src12.cpp" + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/SubDir2" + COMPILE_DEFINITIONS) +check_get_property_value("def12") diff --git a/Tests/Properties/SubDir2/CMakeLists.txt b/Tests/Properties/SubDir2/CMakeLists.txt index 377dc83..9b2c79e 100644 --- a/Tests/Properties/SubDir2/CMakeLists.txt +++ b/Tests/Properties/SubDir2/CMakeLists.txt @@ -3,3 +3,28 @@ set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/../subdirtest.cxx" PROPERTIES COMPILE_DEFINITIONS SUBDIR_TEST) add_executable(subdirtest "${CMAKE_CURRENT_SOURCE_DIR}/../subdirtest.cxx") + +# For set_property +add_library(set_prop_lib_1 SHARED) +foreach(i RANGE 1 6) + generate_file_for_set_property_test(${i} set_prop_lib_1) +endforeach() + +# For set_source_files_properties +foreach(i RANGE 10 12) + generate_file_for_set_property_test(${i} set_prop_lib_1) +endforeach() + +# For set_source_files_properties + multiple files + absolute directory path +add_library(set_prop_lib_2 SHARED) +foreach(i RANGE 20 21) + generate_file_for_set_property_test(${i} set_prop_lib_1) +endforeach() + +# For set_source_files_properties + multiple files + multiple target directories +add_library(set_prop_lib_3 SHARED) +generate_file_for_set_property_test(22 set_prop_lib_2) +generate_file_for_set_property_test(23 set_prop_lib_3) + +# For set_source_files_properties + multiple files in multiple directories +generate_file_for_set_property_test(31 set_prop_lib_3) |