Pass EXCLUDE_FROM_ALL from directory to targets

When a target is created it now inherits the EXCLUDE_FROM_ALL property
from its directory. This change makes it possible to include a target
in "all", even if its directory has been marked as EXCLUDE_FROM_ALL.
This commit is contained in:
Zack Galbreath
2019-01-15 17:26:02 -06:00
parent bd3685b6cf
commit dc6888573d
14 changed files with 92 additions and 29 deletions

View File

@@ -1,4 +1,20 @@
add_library(bar STATIC bar.cpp)
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 .)

View File

@@ -0,0 +1,44 @@
# 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)
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")
endif()

View File

@@ -33,6 +33,7 @@ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(ExcludeFromAll)
set(RunCMake-check-file ExcludeFromAll/check.cmake)
run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build .)
unset(RunCMake_TEST_BINARY_DIR)