summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-05-15 13:57:48 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-05-15 13:58:03 (GMT)
commiteb93b50be9995965d50253eaa22456603e6fdaac (patch)
tree9f64f844d0dde5d474fd68c96141f8dfac7cf395 /Tests
parente2f61e875f7edd26fd09b13d2f571176ad5da7cc (diff)
parent3d4b70ea6474c8f29d6b5c057126582dcaad7ea7 (diff)
downloadCMake-eb93b50be9995965d50253eaa22456603e6fdaac.zip
CMake-eb93b50be9995965d50253eaa22456603e6fdaac.tar.gz
CMake-eb93b50be9995965d50253eaa22456603e6fdaac.tar.bz2
Merge topic 'source_file_scopes'
3d4b70ea64 set_source_files_properties: Allow specification of directory scope Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4661
Diffstat (limited to 'Tests')
-rw-r--r--Tests/Properties/CMakeLists.txt139
-rw-r--r--Tests/Properties/SubDir2/CMakeLists.txt25
-rw-r--r--Tests/RunCMake/get_property/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/get_property/source_properties_failures-result.txt1
-rw-r--r--Tests/RunCMake/get_property/source_properties_failures-stderr.txt66
-rw-r--r--Tests/RunCMake/get_property/source_properties_failures.cmake14
-rw-r--r--Tests/RunCMake/set_property/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/set_property/SOURCE_FILE-result.txt1
-rw-r--r--Tests/RunCMake/set_property/SOURCE_FILE-stderr.txt22
-rw-r--r--Tests/RunCMake/set_property/SOURCE_FILE.cmake4
10 files changed, 274 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)
diff --git a/Tests/RunCMake/get_property/RunCMakeTest.cmake b/Tests/RunCMake/get_property/RunCMakeTest.cmake
index 6e36473..c4ee53d 100644
--- a/Tests/RunCMake/get_property/RunCMakeTest.cmake
+++ b/Tests/RunCMake/get_property/RunCMakeTest.cmake
@@ -5,6 +5,7 @@ run_cmake(directory_properties)
run_cmake(global_properties)
run_cmake(install_properties)
run_cmake(source_properties)
+run_cmake(source_properties_failures)
run_cmake(target_properties)
run_cmake(test_properties)
run_cmake(DebugConfigurations)
diff --git a/Tests/RunCMake/get_property/source_properties_failures-result.txt b/Tests/RunCMake/get_property/source_properties_failures-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/get_property/source_properties_failures-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/get_property/source_properties_failures-stderr.txt b/Tests/RunCMake/get_property/source_properties_failures-stderr.txt
new file mode 100644
index 0000000..a500e2e
--- /dev/null
+++ b/Tests/RunCMake/get_property/source_properties_failures-stderr.txt
@@ -0,0 +1,66 @@
+^CMake Error at source_properties_failures.cmake:1 \(set_source_files_properties\):
+ set_source_files_properties called with incorrect number of arguments no
+ value provided to the DIRECTORY option
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:2 \(set_source_files_properties\):
+ set_source_files_properties given non-existent DIRECTORY non_existing_dir
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:3 \(set_source_files_properties\):
+ set_source_files_properties called with incorrect number of arguments no
+ value provided to the TARGET_DIRECTORY option
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:4 \(set_source_files_properties\):
+ set_source_files_properties given non-existent target for DIRECTORY_TARGET
+ non_existing_target
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:6 \(get_property\):
+ get_property called with incorrect number of arguments no value provided to
+ the DIRECTORY option
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:7 \(get_property\):
+ get_property given non-existent DIRECTORY non_existing_dir
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:8 \(get_property\):
+ get_property called with incorrect number of arguments no value provided to
+ the TARGET_DIRECTORY option
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:9 \(get_property\):
+ get_property given non-existent target for DIRECTORY_TARGET
+ non_existing_dir
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:11 \(get_source_file_property\):
+ get_source_file_property given non-existent DIRECTORY PROPERTY
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:12 \(get_source_file_property\):
+ get_source_file_property called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:13 \(get_source_file_property\):
+ get_source_file_property given non-existent target for DIRECTORY_TARGET
+ PROPERTY
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at source_properties_failures.cmake:14 \(get_source_file_property\):
+ get_source_file_property called with incorrect number of arguments
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/source_properties_failures.cmake b/Tests/RunCMake/get_property/source_properties_failures.cmake
new file mode 100644
index 0000000..f4b87f9
--- /dev/null
+++ b/Tests/RunCMake/get_property/source_properties_failures.cmake
@@ -0,0 +1,14 @@
+set_source_files_properties(a.txt DIRECTORY PROPERTIES COMPILE_DEFINITIONS "def")
+set_source_files_properties(a.txt DIRECTORY non_existing_dir PROPERTIES COMPILE_DEFINITIONS "def")
+set_source_files_properties(a.txt TARGET_DIRECTORY PROPERTIES COMPILE_DEFINITIONS "def")
+set_source_files_properties(a.txt TARGET_DIRECTORY non_existing_target PROPERTIES COMPILE_DEFINITIONS "def")
+
+get_property(in_var SOURCE a.txt DIRECTORY PROPERTY COMPILE_DEFINITIONS)
+get_property(in_var SOURCE a.txt DIRECTORY non_existing_dir PROPERTY COMPILE_DEFINITIONS)
+get_property(in_var SOURCE a.txt TARGET_DIRECTORY PROPERTY COMPILE_DEFINITIONS)
+get_property(in_var SOURCE a.txt TARGET_DIRECTORY non_existing_dir PROPERTY COMPILE_DEFINITIONS)
+
+get_source_file_property(in_var a.txt DIRECTORY PROPERTY COMPILE_DEFINITIONS)
+get_source_file_property(in_var a.txt DIRECTORY non_existing_dir PROPERTY COMPILE_DEFINITIONS)
+get_source_file_property(in_var a.txt TARGET_DIRECTORY PROPERTY COMPILE_DEFINITIONS)
+get_source_file_property(in_var a.txt TARGET_DIRECTORY non_existing_dir PROPERTY COMPILE_DEFINITIONS)
diff --git a/Tests/RunCMake/set_property/RunCMakeTest.cmake b/Tests/RunCMake/set_property/RunCMakeTest.cmake
index 8d4614c..692c6b9 100644
--- a/Tests/RunCMake/set_property/RunCMakeTest.cmake
+++ b/Tests/RunCMake/set_property/RunCMakeTest.cmake
@@ -9,6 +9,7 @@ run_cmake(LINK_OPTIONS)
run_cmake(LINK_DIRECTORIES)
run_cmake(LINK_LIBRARIES)
run_cmake(SOURCES)
+run_cmake(SOURCE_FILE)
run_cmake(TYPE)
run_cmake(USER_PROP)
run_cmake(USER_PROP_INHERITED)
diff --git a/Tests/RunCMake/set_property/SOURCE_FILE-result.txt b/Tests/RunCMake/set_property/SOURCE_FILE-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/set_property/SOURCE_FILE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/set_property/SOURCE_FILE-stderr.txt b/Tests/RunCMake/set_property/SOURCE_FILE-stderr.txt
new file mode 100644
index 0000000..2e0b238
--- /dev/null
+++ b/Tests/RunCMake/set_property/SOURCE_FILE-stderr.txt
@@ -0,0 +1,22 @@
+^CMake Error at SOURCE_FILE.cmake:1 \(set_property\):
+ set_property called with incorrect number of arguments no value provided to
+ the DIRECTORY option
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at SOURCE_FILE.cmake:2 \(set_property\):
+ set_property given non-existent DIRECTORY non_existing_dir
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at SOURCE_FILE.cmake:3 \(set_property\):
+ set_property called with incorrect number of arguments no value provided to
+ the TARGET_DIRECTORY option
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Error at SOURCE_FILE.cmake:4 \(set_property\):
+ set_property given non-existent target for DIRECTORY_TARGET
+ non_existing_target
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/set_property/SOURCE_FILE.cmake b/Tests/RunCMake/set_property/SOURCE_FILE.cmake
new file mode 100644
index 0000000..b1d78bd
--- /dev/null
+++ b/Tests/RunCMake/set_property/SOURCE_FILE.cmake
@@ -0,0 +1,4 @@
+set_property(SOURCE a.txt DIRECTORY PROPERTY COMPILE_DEFINITIONS "def")
+set_property(SOURCE a.txt DIRECTORY non_existing_dir PROPERTY COMPILE_DEFINITIONS "def")
+set_property(SOURCE a.txt TARGET_DIRECTORY PROPERTY COMPILE_DEFINITIONS "def")
+set_property(SOURCE a.txt TARGET_DIRECTORY non_existing_target PROPERTY COMPILE_DEFINITIONS "def")