From a98db022aa4cc0798fba4bb2f723e5b0cc3b2570 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sat, 8 Aug 2020 15:37:51 +0200 Subject: cmake: Detect custom command targets in compiler args This is required to make `-include /path/to/custom/target.hpp` work. This setup is used by wxWidgets and this PR is required to use wxWidgets as a CMake subproject. --- .../cmake/8 custom command/subprojects/cmMod/CMakeLists.txt | 10 ++++++++++ .../cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am | 3 +++ .../cmake/8 custom command/subprojects/cmMod/macro_name.cpp | 6 ++++++ 3 files changed, 19 insertions(+) create mode 100644 test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am (limited to 'test cases/cmake') diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt index 1498c3607..199c2e9a6 100644 --- a/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt +++ b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt @@ -134,6 +134,16 @@ add_custom_target(args_test_cmd ) add_custom_target(macro_name_cmd COMMAND macro_name) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + message(STATUS "Running the -include test case on macro_name") + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyInc.hpp" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyInc.hpp.am" "${CMAKE_CURRENT_BINARY_DIR}/cpyInc.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyInc.hpp.am" + ) + target_compile_options(macro_name PUBLIC -DTEST_CMD_INCLUDE -include "${CMAKE_CURRENT_BINARY_DIR}/cpyInc.hpp") +endif() + # Only executable targets are replaced in the command # all other target names are kept as is add_custom_target(clang-format COMMAND clang-format -i cmMod.cpp) diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am b/test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am new file mode 100644 index 000000000..07c8ff790 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_INC_WAS_INCLUDED 1 diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp index 790557b3a..964062ffe 100644 --- a/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp +++ b/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp @@ -5,6 +5,12 @@ using namespace std; +#ifdef TEST_CMD_INCLUDE +#if CPY_INC_WAS_INCLUDED != 1 +#error "cpyInc.hpp was not included" +#endif +#endif + int main() { this_thread::sleep_for(chrono::seconds(1)); ofstream out1("macro_name.txt"); -- cgit v1.3