aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2020-08-08 15:37:51 +0200
committerNirbheek Chauhan <nirbheek@centricular.com>2020-08-15 11:35:37 +0530
commit433ea2037b210751f984f12eef2d926dfded6897 (patch)
treeceed35e75b564e2579051b6af59d48868c02c6bc
parent571b76ab519a0ec7b6fdce31b9b6249c3fa53792 (diff)
downloadmeson-433ea2037b210751f984f12eef2d926dfded6897.zip
meson-433ea2037b210751f984f12eef2d926dfded6897.tar.gz
meson-433ea2037b210751f984f12eef2d926dfded6897.tar.bz2
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.
-rw-r--r--mesonbuild/cmake/interpreter.py9
-rw-r--r--test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt10
-rw-r--r--test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am3
-rw-r--r--test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp6
4 files changed, 27 insertions, 1 deletions
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
index 9749c4c..c2affd0 100644
--- a/mesonbuild/cmake/interpreter.py
+++ b/mesonbuild/cmake/interpreter.py
@@ -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:
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 1498c36..199c2e9 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 0000000..07c8ff7
--- /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 790557b..964062f 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");