diff options
author | Craig Scott <craig.scott@crascit.com> | 2018-06-19 12:23:44 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-06-19 12:24:08 (GMT) |
commit | 6e7b424240dfae88a22327c86454150f2200b7c5 (patch) | |
tree | e86aee11c5a2432605cda2bc1456410517820684 /Tests/CMakeCommands | |
parent | fa744586cce3159b7a18b18f25f6fb51927c0f89 (diff) | |
parent | 316815e1f4beb66b679f27f96800facef572889e (diff) | |
download | CMake-6e7b424240dfae88a22327c86454150f2200b7c5.zip CMake-6e7b424240dfae88a22327c86454150f2200b7c5.tar.gz CMake-6e7b424240dfae88a22327c86454150f2200b7c5.tar.bz2 |
Merge topic 'subdir_target_sources'
316815e1f4 target_sources: Interpret relative paths as relative to the calling directory
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2128
Diffstat (limited to 'Tests/CMakeCommands')
8 files changed, 135 insertions, 0 deletions
diff --git a/Tests/CMakeCommands/target_sources/CMakeLists.txt b/Tests/CMakeCommands/target_sources/CMakeLists.txt new file mode 100644 index 0000000..ab14855 --- /dev/null +++ b/Tests/CMakeCommands/target_sources/CMakeLists.txt @@ -0,0 +1,36 @@ + +cmake_minimum_required(VERSION 3.12) +cmake_policy(SET CMP0076 NEW) + +project(target_sources) + +add_library(target_sources_lib) +target_compile_definitions(target_sources_lib PRIVATE "-DIS_LIB") +add_subdirectory(subdir) + +set(subdir_fullpath "${CMAKE_CURRENT_LIST_DIR}/subdir") + +get_property(target_sources_lib_property TARGET target_sources_lib PROPERTY SOURCES) +if (NOT "$<1:${subdir_fullpath}/subdir_empty_1.cpp>" IN_LIST target_sources_lib_property) + message(SEND_ERROR "target_sources_lib: Generator expression to absolute sub directory file not found") +endif() +if (NOT "$<1:${subdir_fullpath}/../empty_1.cpp>" IN_LIST target_sources_lib_property) + message(SEND_ERROR "target_sources_lib: Generator expression to absolute main directory file not found") +endif() +if (NOT "${subdir_fullpath}/subdir_empty_2.cpp" IN_LIST target_sources_lib_property) + message(SEND_ERROR "target_sources_lib: Relative sub directory file not converted to absolute") +endif() +if (NOT "$<1:empty_2.cpp>" IN_LIST target_sources_lib_property) + message(SEND_ERROR "target_sources_lib: Generator expression to relative main directory file not found") +endif() +if (NOT "${subdir_fullpath}/../empty_3.cpp" IN_LIST target_sources_lib_property) + message(SEND_ERROR "target_sources_lib: Relative main directory file not converted to absolute") +endif() + +add_executable(target_sources main.cpp) +target_link_libraries(target_sources target_sources_lib) + +get_property(target_sources_property TARGET target_sources PROPERTY SOURCES) +if (NOT "main.cpp" IN_LIST target_sources_property) + message(SEND_ERROR "target_sources: Relative main directory file converted to absolute") +endif() diff --git a/Tests/CMakeCommands/target_sources/empty_1.cpp b/Tests/CMakeCommands/target_sources/empty_1.cpp new file mode 100644 index 0000000..01e5b07 --- /dev/null +++ b/Tests/CMakeCommands/target_sources/empty_1.cpp @@ -0,0 +1,21 @@ +#ifdef IS_LIB + +# ifdef _WIN32 +__declspec(dllexport) +# endif + int internal_empty_1() +{ + return 0; +} + +#else + +# ifdef _WIN32 +__declspec(dllexport) +# endif + int empty_1() +{ + return 0; +} + +#endif diff --git a/Tests/CMakeCommands/target_sources/empty_2.cpp b/Tests/CMakeCommands/target_sources/empty_2.cpp new file mode 100644 index 0000000..48ae8bb --- /dev/null +++ b/Tests/CMakeCommands/target_sources/empty_2.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif + int empty_2() +{ + return 0; +} diff --git a/Tests/CMakeCommands/target_sources/empty_3.cpp b/Tests/CMakeCommands/target_sources/empty_3.cpp new file mode 100644 index 0000000..bd3a6d1 --- /dev/null +++ b/Tests/CMakeCommands/target_sources/empty_3.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif + int empty_3() +{ + return 0; +} diff --git a/Tests/CMakeCommands/target_sources/main.cpp b/Tests/CMakeCommands/target_sources/main.cpp new file mode 100644 index 0000000..622771c --- /dev/null +++ b/Tests/CMakeCommands/target_sources/main.cpp @@ -0,0 +1,16 @@ +#include <iostream> + +int empty_1(); +int subdir_empty_1(); +int subdir_empty_2(); + +int main() +{ + int e1 = empty_1(); + int se1 = subdir_empty_1(); + int se2 = subdir_empty_2(); + + std::cout << e1 << " " << se1 << " " << se2 << std::endl; + + return 0; +} diff --git a/Tests/CMakeCommands/target_sources/subdir/CMakeLists.txt b/Tests/CMakeCommands/target_sources/subdir/CMakeLists.txt new file mode 100644 index 0000000..f749f1d --- /dev/null +++ b/Tests/CMakeCommands/target_sources/subdir/CMakeLists.txt @@ -0,0 +1,6 @@ + +target_sources(target_sources_lib PUBLIC $<1:${CMAKE_CURRENT_LIST_DIR}/subdir_empty_1.cpp> + $<1:${CMAKE_CURRENT_LIST_DIR}/../empty_1.cpp> + subdir_empty_2.cpp + PRIVATE $<1:empty_2.cpp> + ../empty_3.cpp) diff --git a/Tests/CMakeCommands/target_sources/subdir/subdir_empty_1.cpp b/Tests/CMakeCommands/target_sources/subdir/subdir_empty_1.cpp new file mode 100644 index 0000000..3c61321 --- /dev/null +++ b/Tests/CMakeCommands/target_sources/subdir/subdir_empty_1.cpp @@ -0,0 +1,21 @@ +#ifdef IS_LIB + +# ifdef _WIN32 +__declspec(dllexport) +# endif + int internal_subdir_empty_1() +{ + return 0; +} + +#else + +# ifdef _WIN32 +__declspec(dllexport) +# endif + int subdir_empty_1() +{ + return 0; +} + +#endif diff --git a/Tests/CMakeCommands/target_sources/subdir/subdir_empty_2.cpp b/Tests/CMakeCommands/target_sources/subdir/subdir_empty_2.cpp new file mode 100644 index 0000000..47fa736 --- /dev/null +++ b/Tests/CMakeCommands/target_sources/subdir/subdir_empty_2.cpp @@ -0,0 +1,21 @@ +#ifdef IS_LIB + +# ifdef _WIN32 +__declspec(dllexport) +# endif + int internal_subdir_empty_2() +{ + return 0; +} + +#else + +# ifdef _WIN32 +__declspec(dllexport) +# endif + int subdir_empty_2() +{ + return 0; +} + +#endif |