summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/add_subdirectory
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-09-24 16:39:33 (GMT)
committerBrad King <brad.king@kitware.com>2019-09-26 18:57:40 (GMT)
commit21442d72a44c2bd732f2ff19ed89ce488854d25d (patch)
tree656a1a2875dbfca3857175a9ab67560e4f7c61c1 /Tests/RunCMake/add_subdirectory
parent0cfbd85e7b0d61affda6450b1cc081860b5543a6 (diff)
downloadCMake-21442d72a44c2bd732f2ff19ed89ce488854d25d.zip
CMake-21442d72a44c2bd732f2ff19ed89ce488854d25d.tar.gz
CMake-21442d72a44c2bd732f2ff19ed89ce488854d25d.tar.bz2
Tests: Revise RunCMake.add_subdirectory ExcludeFromAll to avoid globbing
Also simplify the clean step.
Diffstat (limited to 'Tests/RunCMake/add_subdirectory')
-rw-r--r--Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake7
-rw-r--r--Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt12
-rw-r--r--Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake69
-rw-r--r--Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake16
4 files changed, 43 insertions, 61 deletions
diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake
index f686005..cc31428 100644
--- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake
+++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake
@@ -4,3 +4,10 @@ add_subdirectory(ExcludeFromAll EXCLUDE_FROM_ALL)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE foo)
+
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+set(main_exe \"$<TARGET_FILE:main>\")
+set(foo_lib \"$<TARGET_FILE:foo>\")
+set(bar_lib \"$<TARGET_FILE:bar>\")
+set(baz_lib \"$<TARGET_FILE:baz>\")
+")
diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt
index 9e6462b..99add23 100644
--- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt
+++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt
@@ -5,16 +5,4 @@ add_library(foo STATIC foo.cpp)
add_library(baz STATIC foo.cpp)
set_target_properties(baz PROPERTIES EXCLUDE_FROM_ALL OFF)
-file(GENERATE
- OUTPUT "${CMAKE_BINARY_DIR}/main.txt"
- CONTENT "$<TARGET_FILE_NAME:main>")
-
-file(GENERATE
- OUTPUT "${CMAKE_BINARY_DIR}/bar.txt"
- CONTENT "$<TARGET_FILE_NAME:bar>")
-
-file(GENERATE
- OUTPUT "${CMAKE_BINARY_DIR}/baz.txt"
- CONTENT "$<TARGET_FILE_NAME:baz>")
-
target_include_directories(foo PUBLIC .)
diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake
index 14ec482..2a0179e 100644
--- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake
+++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/check.cmake
@@ -1,44 +1,31 @@
-# Use globbing to check if exes / libs were built because determining
-# exactly where these files will live inside a CMake -P script is
-# pretty challenging.
-
-file(READ "${RunCMake_TEST_BINARY_DIR}/main.txt" main_exe)
-file(READ "${RunCMake_TEST_BINARY_DIR}/bar.txt" bar_lib)
-file(READ "${RunCMake_TEST_BINARY_DIR}/baz.txt" baz_lib)
-
-set(found_main FALSE)
-file(GLOB_RECURSE files
- LIST_DIRECTORIES FALSE
- RELATIVE "${RunCMake_TEST_BINARY_DIR}"
- "${RunCMake_TEST_BINARY_DIR}/*")
-foreach (file IN LISTS files)
- if (file MATCHES "${main_exe}")
- set(found_main TRUE)
+if(EXISTS ${RunCMake_TEST_BINARY_DIR}/check-debug.cmake)
+ include(${RunCMake_TEST_BINARY_DIR}/check-debug.cmake)
+ if(RunCMake_TEST_FAILED)
+ return()
endif()
-endforeach()
-if (NOT found_main)
- set(RunCMake_TEST_FAILED "'main' missing from ${RunCMake_TEST_BINARY_DIR}")
-endif()
-set(found_bar FALSE)
-set(found_baz FALSE)
-file(GLOB_RECURSE files
- LIST_DIRECTORIES FALSE
- RELATIVE "${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll"
- "${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll/*")
-foreach (file IN LISTS files)
- if (file MATCHES "${bar_lib}")
- set(found_bar TRUE)
- endif()
- if (file MATCHES "${baz_lib}")
- set(found_baz TRUE)
- endif()
-endforeach()
-if (found_bar)
- set(RunCMake_TEST_FAILED
- "'bar' was not excluded from ${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll")
-endif()
-if (NOT found_baz)
- set(RunCMake_TEST_FAILED
- "'baz' missing from ${RunCMake_TEST_BINARY_DIR}/ExcludeFromAll")
+ foreach(file
+ "${foo_lib}"
+ "${baz_lib}"
+ "${main_exe}"
+ )
+ if(NOT EXISTS "${file}")
+ set(RunCMake_TEST_FAILED
+ "Artifact should exist but is missing:\n ${file}")
+ return()
+ endif()
+ endforeach()
+ foreach(file
+ "${bar_lib}"
+ )
+ if(EXISTS "${file}")
+ set(RunCMake_TEST_FAILED
+ "Artifact should be missing but exists:\n ${file}")
+ return()
+ endif()
+ endforeach()
+else()
+ set(RunCMake_TEST_FAILED "
+ '${RunCMake_TEST_BINARY_DIR}/check-debug.cmake' missing
+")
endif()
diff --git a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake b/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake
index 781e483..e9ba92f 100644
--- a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake
+++ b/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake
@@ -27,14 +27,14 @@ run_cmake_install(CMP0082-OLD -DCMP0082_VALUE=OLD)
run_cmake_install(CMP0082-NEW -DCMP0082_VALUE=NEW)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExcludeFromAll-build)
-set(RunCMake_TEST_NO_CLEAN 1)
-
-file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
-file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
-
+if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+endif()
run_cmake(ExcludeFromAll)
+set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake-check-file ExcludeFromAll/check.cmake)
-run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build .)
-
-unset(RunCMake_TEST_BINARY_DIR)
+run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build . --config Debug)
+unset(RunCMake-check-file)
unset(RunCMake_TEST_NO_CLEAN)
+unset(RunCMake_TEST_OPTIONS)
+unset(RunCMake_TEST_BINARY_DIR)