aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2019-11-20 22:16:17 +0100
committerDaniel Mensinger <daniel@mensinger-ka.de>2019-11-28 11:07:20 +0100
commitb2b9c102b5610112231a321fca4479c09a6ba234 (patch)
tree3414bb710f8abdd3aafde019890d96d3936ec0b3
parent8efbcb1e80d58fa39501a883968229270c4e4bec (diff)
downloadmeson-b2b9c102b5610112231a321fca4479c09a6ba234.zip
meson-b2b9c102b5610112231a321fca4479c09a6ba234.tar.gz
meson-b2b9c102b5610112231a321fca4479c09a6ba234.tar.bz2
cmake: Some minor fixup
-rwxr-xr-xmesonbuild/cmake/data/run_ctgt.py2
-rw-r--r--mesonbuild/cmake/interpreter.py38
-rw-r--r--test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt4
-rw-r--r--test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp3
-rw-r--r--test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp14
5 files changed, 47 insertions, 14 deletions
diff --git a/mesonbuild/cmake/data/run_ctgt.py b/mesonbuild/cmake/data/run_ctgt.py
index 3786c5d..954f8ce 100755
--- a/mesonbuild/cmake/data/run_ctgt.py
+++ b/mesonbuild/cmake/data/run_ctgt.py
@@ -14,7 +14,7 @@ parser = argparse.ArgumentParser(description='Wrapper for add_custom_command')
parser.add_argument('-d', '--directory', type=str, metavar='D', required=True, help='Working directory to cwd to')
parser.add_argument('-o', '--outputs', nargs='+', metavar='O', required=True, help='Expected output files')
parser.add_argument('-O', '--original-outputs', nargs='*', metavar='O', default=[], help='Output files expected by CMake')
-parser.add_argument('commands', nargs=argparse.REMAINDER, help='A "{}" seperated list of commands'.format(SEPERATOR))
+parser.add_argument('commands', nargs=argparse.REMAINDER, help='A "{}" seperated list of commands'.format(SEPARATOR))
# Parse
args = parser.parse_args()
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
index 5fd8ce0..548acb1 100644
--- a/mesonbuild/cmake/interpreter.py
+++ b/mesonbuild/cmake/interpreter.py
@@ -170,6 +170,10 @@ class ConverterTarget:
# Project default override options (c_std, cpp_std, etc.)
self.override_options = []
+ # Convert the target name to a valid meson target name
+ self.name = self.name.replace('-', '_')
+ self.name = generated_target_name_prefix + self.name
+
for i in target.files:
# Determine the meson language
lang = ConverterTarget.lang_cmake_to_meson.get(i.language.lower(), 'c')
@@ -199,10 +203,6 @@ class ConverterTarget:
std_regex = re.compile(r'([-]{1,2}std=|/std:v?|[-]{1,2}std:)(.*)')
def postprocess(self, output_target_map: dict, root_src_dir: str, subdir: str, install_prefix: str, trace: CMakeTraceParser) -> None:
- # Convert the target name to a valid meson target name
- self.name = self.name.replace('-', '_')
- self.name = generated_target_name_prefix + self.name
-
# Detect setting the C and C++ standard
for i in ['c', 'cpp']:
if i not in self.compile_opts:
@@ -339,6 +339,7 @@ class ConverterTarget:
self.link_libraries = [x for x in self.link_libraries if x.lower() not in blacklist_link_libs]
self.link_flags = [x for x in self.link_flags if check_flag(x)]
+ # Handle explicit CMake add_dependency() calls
for i in self.depends_raw:
tgt = output_target_map.get(_target_key(i))
if tgt:
@@ -382,6 +383,7 @@ class ConverterTarget:
mlog.log(' -- generated: ', mlog.bold(str(self.generated)))
mlog.log(' -- pie: ', mlog.bold('true' if self.pie else 'false'))
mlog.log(' -- override_opts: ', mlog.bold(str(self.override_options)))
+ mlog.log(' -- depends: ', mlog.bold(str(self.depends)))
mlog.log(' -- options:')
for key, val in self.compile_opts.items():
mlog.log(' -', key, '=', mlog.bold(str(val)))
@@ -412,6 +414,7 @@ class ConverterCustomTarget:
if not self.name:
self.name = 'custom_tgt_{}'.format(ConverterCustomTarget.tgt_counter)
ConverterCustomTarget.tgt_counter += 1
+ self.cmake_name = str(self.name)
self.original_outputs = list(target.outputs)
self.outputs = [os.path.basename(x) for x in self.original_outputs]
self.conflict_map = {}
@@ -421,8 +424,12 @@ class ConverterCustomTarget:
self.inputs = []
self.depends = []
+ # Convert the target name to a valid meson target name
+ self.name = self.name.replace('-', '_')
+ self.name = generated_target_name_prefix + self.name
+
def __repr__(self) -> str:
- return '<{}: {}>'.format(self.__class__.__name__, self.outputs)
+ return '<{}: {} {}>'.format(self.__class__.__name__, self.name, self.outputs)
def postprocess(self, output_target_map: dict, root_src_dir: str, subdir: str, build_dir: str, all_outputs: List[str]) -> None:
# Default the working directory to the CMake build dir. This
@@ -480,8 +487,15 @@ class ConverterCustomTarget:
commands += [cmd]
self.command = commands
+ # If the custom target does not declare any output, create a dummy
+ # one that can be used as dependency.
+ if not self.outputs:
+ self.outputs = [self.name + '.h']
+
# Check dependencies and input files
for i in self.depends_raw:
+ if not i:
+ continue
tgt_key = _target_key(i)
gen_key = _generated_file_key(i)
@@ -725,16 +739,21 @@ class CMakeInterpreter:
# generate the output_target_map
output_target_map = {}
output_target_map.update({x.full_name: x for x in self.targets})
- output_target_map.update({_target_key(x.name): x for x in self.targets})
+ output_target_map.update({_target_key(x.cmake_name): x for x in self.targets})
for i in self.targets:
for j in i.artifacts:
output_target_map[os.path.basename(j)] = i
for i in self.custom_targets:
- output_target_map[_target_key(i.name)] = i
+ output_target_map[_target_key(i.cmake_name)] = i
for j in i.original_outputs:
output_target_map[_generated_file_key(j)] = i
object_libs = []
+ # Sometimes an empty string can be inserted (no full name, etc.)
+ # Delete the entry in this case
+ if '' in output_target_map:
+ del output_target_map['']
+
# First pass: Basic target cleanup
custom_target_outputs = [] # type: List[str]
for i in self.custom_targets:
@@ -973,11 +992,6 @@ class CMakeInterpreter:
tgt_var = tgt.name # type: str
- # If the custom target does not declare any output, create a dummy
- # one that can be used as dependency.
- if not tgt.outputs:
- tgt.outputs = [tgt.name + '.h']
-
def resolve_source(x: Any) -> Any:
if isinstance(x, ConverterTarget):
if x.name not in processed:
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 ec56105..3c3297e 100644
--- a/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt
+++ b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.5)
project(cmMod)
set (CMAKE_CXX_STANDARD 14)
+set (CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_definitions("-DDO_NOTHING_JUST_A_FLAG=1")
@@ -48,9 +49,12 @@ generate_export_header(cmModLib)
set(ARGS_TEST arg1)
set(ARGS_TEST ${ARGS_TEST} arg2)
+add_executable(macro_name macro_name.cpp)
add_executable(args_test args_test.cpp)
add_custom_target(args_test_cmd
COMMAND args_test ARGS ${ARGS_TEST}
)
+add_custom_target(macro_name_cmd COMMAND macro_name)
add_dependencies(cmModLib args_test_cmd)
+add_dependencies(args_test_cmd macro_name_cmd)
diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp
index 243e597..abb8a42 100644
--- a/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp
+++ b/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp
@@ -9,8 +9,9 @@ int main(int argc, const char *argv[]) {
return 1;
}
+ ifstream in1("macro_name.txt");
ofstream out1("cmModLib.hpp");
- out1 << "#define FOO = \"plop\"";
+ out1 << "#define " << in1.rdbuf() << " = \"plop\"";
return 0;
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
new file mode 100644
index 0000000..790557b
--- /dev/null
+++ b/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp
@@ -0,0 +1,14 @@
+#include <iostream>
+#include <fstream>
+#include <chrono>
+#include <thread>
+
+using namespace std;
+
+int main() {
+ this_thread::sleep_for(chrono::seconds(1));
+ ofstream out1("macro_name.txt");
+ out1 << "FOO";
+
+ return 0;
+}