cmake: Ignore files that violate subproject isolation (fixes #6640)

pull/6665/head
Daniel Mensinger 4 years ago committed by Jussi Pakkanen
parent 76ae865864
commit 55d3fe4f4a
  1. 14
      mesonbuild/cmake/interpreter.py
  2. 3
      test cases/failing build/4 cmake subproject isolation/incDir/fileA.hpp
  3. 10
      test cases/failing build/4 cmake subproject isolation/main.cpp
  4. 17
      test cases/failing build/4 cmake subproject isolation/meson.build
  5. 10
      test cases/failing build/4 cmake subproject isolation/subprojects/cmMod/CMakeLists.txt
  6. 12
      test cases/failing build/4 cmake subproject isolation/subprojects/cmMod/cmMod.cpp
  7. 14
      test cases/failing build/4 cmake subproject isolation/subprojects/cmMod/cmMod.hpp

@ -399,7 +399,19 @@ class ConverterTarget:
if not os.path.isabs(x):
x = os.path.normpath(os.path.join(self.src_dir, x))
if not os.path.exists(x) and not any([x.endswith(y) for y in obj_suffixes]) and not is_generated:
mlog.warning('CMake: path', mlog.bold(x), 'does not exist. Ignoring. This can lead to build errors')
mlog.warning('CMake: path', mlog.bold(x), 'does not exist.')
mlog.warning(' --> Ignoring. This can lead to build errors.')
return None
if (
os.path.isabs(x)
and os.path.commonpath([x, self.env.get_source_dir()]) == self.env.get_source_dir()
and not (
os.path.commonpath([x, root_src_dir]) == root_src_dir or
os.path.commonpath([x, self.env.get_build_dir()]) == self.env.get_build_dir()
)
):
mlog.warning('CMake: path', mlog.bold(x), 'is inside the root project but', mlog.bold('not'), 'inside the subproject.')
mlog.warning(' --> Ignoring. This can lead to build errors.')
return None
if os.path.isabs(x) and os.path.commonpath([x, self.env.get_build_dir()]) == self.env.get_build_dir():
if is_header:

@ -0,0 +1,3 @@
#pragma once
#define SOME_DEFINE " World"

@ -0,0 +1,10 @@
#include <iostream>
#include <cmMod.hpp>
using namespace std;
int main(void) {
cmModClass obj("Hello");
cout << obj.getStr() << endl;
return 0;
}

@ -0,0 +1,17 @@
project('subproject isolation', ['c', 'cpp'])
if not find_program('cmake', required: false).found()
error('MESON_SKIP_TEST CMake is not installed')
endif
incdir = meson.source_root() / 'incDir'
cm = import('cmake')
# This should generate a warning and the include dir should be skipped.
sub_pro = cm.subproject('cmMod', cmake_options : [ '-DMESON_INC_DIR=' + incdir ])
sub_dep = sub_pro.dependency('cmModLib++')
# Since the include dir is skipped, the compilation of this project should fail.
exe1 = executable('main', ['main.cpp'], dependencies: [sub_dep])
test('test1', exe1)

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.5)
project(cmMod)
set (CMAKE_CXX_STANDARD 14)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${MESON_INC_DIR})
add_library(cmModLib++ SHARED cmMod.cpp)
include(GenerateExportHeader)
generate_export_header(cmModLib++)

@ -0,0 +1,12 @@
#include "cmMod.hpp"
#include "fileA.hpp"
using namespace std;
cmModClass::cmModClass(string foo) {
str = foo + SOME_DEFINE;
}
string cmModClass::getStr() const {
return str;
}

@ -0,0 +1,14 @@
#pragma once
#include "cmmodlib++_export.h"
#include <string>
class CMMODLIB___EXPORT cmModClass {
private:
std::string str;
public:
cmModClass(std::string foo);
std::string getStr() const;
};
Loading…
Cancel
Save