cmake: fix definitions with interface libraries (fixes #7299)

0.54
Daniel Mensinger 5 years ago committed by Nirbheek Chauhan
parent e20f02bfc3
commit f542677fd4
  1. 13
      mesonbuild/cmake/interpreter.py
  2. 2
      test cases/cmake/1 basic/subprojects/cmMod/CMakeLists.txt
  3. 4
      test cases/cmake/1 basic/subprojects/cmMod/cmMod.cpp
  4. 4
      test cases/cmake/1 basic/subprojects/cmMod/cmMod.hpp
  5. 6
      test cases/cmake/10 header only/main.cpp
  6. 1
      test cases/cmake/10 header only/subprojects/cmMod/CMakeLists.txt
  7. 5
      test cases/cmake/10 header only/subprojects/cmMod/include/cmMod.hpp

@ -315,13 +315,6 @@ class ConverterTarget:
tgt = trace.targets.get(self.cmake_name)
if tgt:
self.depends_raw = trace.targets[self.cmake_name].depends
if self.type.upper() == 'INTERFACE_LIBRARY':
props = tgt.properties
self.includes += props.get('INTERFACE_INCLUDE_DIRECTORIES', [])
self.public_compile_opts += props.get('INTERFACE_COMPILE_DEFINITIONS', [])
self.public_compile_opts += props.get('INTERFACE_COMPILE_OPTIONS', [])
self.link_flags += props.get('INTERFACE_LINK_OPTIONS', [])
# TODO refactor this copy paste from CMakeDependency for future releases
reg_is_lib = re.compile(r'^(-l[a-zA-Z0-9_]+|-l?pthread)$')
@ -340,6 +333,12 @@ class ConverterTarget:
libraries = []
mlog.debug(tgt)
if 'INTERFACE_INCLUDE_DIRECTORIES' in tgt.properties:
self.includes += [x for x in tgt.properties['INTERFACE_INCLUDE_DIRECTORIES'] if x]
if 'INTERFACE_LINK_OPTIONS' in tgt.properties:
self.link_flags += [x for x in tgt.properties['INTERFACE_LINK_OPTIONS'] if x]
if 'INTERFACE_COMPILE_DEFINITIONS' in tgt.properties:
self.public_compile_opts += ['-D' + re.sub('^-D', '', x) for x in tgt.properties['INTERFACE_COMPILE_DEFINITIONS'] if x]

@ -8,5 +8,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_definitions("-DDO_NOTHING_JUST_A_FLAG=1")
add_library(cmModLib++ SHARED cmMod.cpp)
target_compile_definitions(cmModLib++ PRIVATE MESON_MAGIC_FLAG=21)
target_compile_definitions(cmModLib++ INTERFACE MESON_MAGIC_FLAG=42)
include(GenerateExportHeader)
generate_export_header(cmModLib++)

@ -2,6 +2,10 @@
using namespace std;
#if MESON_MAGIC_FLAG != 21
#error "Invalid MESON_MAGIC_FLAG (private)"
#endif
cmModClass::cmModClass(string foo) {
str = foo + " World";
}

@ -3,6 +3,10 @@
#include "cmmodlib++_export.h"
#include <string>
#if MESON_MAGIC_FLAG != 42 && MESON_MAGIC_FLAG != 21
#error "Invalid MESON_MAGIC_FLAG"
#endif
class CMMODLIB___EXPORT cmModClass {
private:
std::string str;

@ -3,8 +3,14 @@
using namespace std;
#define EXPECTED "Hello World compDef 42"
int main(void) {
cmModClass obj("Hello");
cout << obj.getStr() << endl;
if (obj.getStr() != EXPECTED) {
cerr << "Expected: '" << EXPECTED << "'" << endl;
return 1;
}
return 0;
}

@ -9,3 +9,4 @@ add_library(cmModLib INTERFACE)
set_target_properties(cmModLib PROPERTIES INTERFACE_COMPILE_OPTIONS "-DCMAKE_FLAG_MUST_BE_PRESENT")
target_include_directories(cmModLib INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_compile_definitions(cmModLib INTERFACE -DCMAKE_COMPILER_DEFINE_STR="compDef")
target_compile_definitions(cmModLib INTERFACE MESON_MAGIC_FLAG=42)

@ -6,6 +6,9 @@
#error "The flag CMAKE_FLAG_MUST_BE_PRESENT was not set"
#endif
#define xstr(s) str(s)
#define str(s) #s
class cmModClass {
private:
std::string str;
@ -13,6 +16,8 @@ class cmModClass {
cmModClass(std::string foo) {
str = foo + " World ";
str += CMAKE_COMPILER_DEFINE_STR;
str += ' ';
str += xstr(MESON_MAGIC_FLAG);
}
inline std::string getStr() const { return str; }

Loading…
Cancel
Save