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.
pull/5405/merge
Daniel Mensinger 5 years ago committed by Jussi Pakkanen
parent 948741355f
commit a98db022aa
  1. 9
      mesonbuild/cmake/interpreter.py
  2. 10
      test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt
  3. 3
      test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am
  4. 6
      test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp

@ -279,7 +279,7 @@ class ConverterTarget:
std_regex = re.compile(r'([-]{1,2}std=|/std:v?|[-]{1,2}std:)(.*)')
def postprocess(self, output_target_map: OutputTargetMap, root_src_dir: str, subdir: str, install_prefix: str, trace: CMakeTraceParser) -> None:
# Detect setting the C and C++ standard
# Detect setting the C and C++ standard and do additional compiler args manipulation
for i in ['c', 'cpp']:
if i not in self.compile_opts:
continue
@ -287,6 +287,7 @@ class ConverterTarget:
temp = []
for j in self.compile_opts[i]:
m = ConverterTarget.std_regex.match(j)
ctgt = output_target_map.generated(j)
if m:
std = m.group(2)
supported = self._all_lang_stds(i)
@ -301,6 +302,12 @@ class ConverterTarget:
self.override_options += ['{}_std={}'.format(i, std)]
elif j in ['-fPIC', '-fpic', '-fPIE', '-fpie']:
self.pie = True
elif isinstance(ctgt, ConverterCustomTarget):
# Sometimes projects pass generated source files as compiler
# flags. Add these as generated sources to ensure that the
# corresponding custom target is run.2
self.generated += [j]
temp += [j]
elif j in blacklist_compiler_flags:
pass
else:

@ -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)

@ -0,0 +1,3 @@
#pragma once
#define CPY_INC_WAS_INCLUDED 1

@ -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");

Loading…
Cancel
Save