diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-04-24 22:42:09 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-09-22 15:50:26 -0400 |
commit | 49e7e3b9ccba7f9b0a135188f892b37d4e52cafc (patch) | |
tree | c2d7cce36113bc1fae778b3a55823672ee28e99f /test cases/cmake | |
parent | c0da998afa7466d58c12d8a54baf09d09ae3225e (diff) | |
download | meson-49e7e3b9ccba7f9b0a135188f892b37d4e52cafc.zip meson-49e7e3b9ccba7f9b0a135188f892b37d4e52cafc.tar.gz meson-49e7e3b9ccba7f9b0a135188f892b37d4e52cafc.tar.bz2 |
Allow to fallback to cmake subproject
The method can be overridden by setting the `method` key in the wrap
file and always defaults to 'meson'. cmake.subproject() is still needed
in case specific cmake options need to be passed.
This also makes it easier to extend to other methods in the future e.g.
cargo.
Diffstat (limited to 'test cases/cmake')
14 files changed, 115 insertions, 0 deletions
diff --git a/test cases/cmake/26 dependency fallback/main.cpp b/test cases/cmake/26 dependency fallback/main.cpp new file mode 100644 index 0000000..9507961 --- /dev/null +++ b/test cases/cmake/26 dependency fallback/main.cpp @@ -0,0 +1,10 @@ +#include <iostream> +#include <cmMod.hpp> + +using namespace std; + +int main(void) { + cmModClass obj("Hello"); + cout << obj.getStr() << endl; + return 0; +} diff --git a/test cases/cmake/26 dependency fallback/meson.build b/test cases/cmake/26 dependency fallback/meson.build new file mode 100644 index 0000000..b36aaac --- /dev/null +++ b/test cases/cmake/26 dependency fallback/meson.build @@ -0,0 +1,30 @@ +project('cmakeSubTest', ['c', 'cpp']) + +# Fallback to a CMake subproject +sub_dep = dependency('cmModLib++') +exe1 = executable('main', ['main.cpp'], dependencies: [sub_dep]) +test('test1', exe1) + +# Subproject contains both meson.build and CMakeLists.txt. It should default +# to meson but wrap force cmake. +subproject('force_cmake') + +testcase expect_error('Wrap method \'notfound\' is not supported, must be one of: meson, cmake') + subproject('broken_method') +endtestcase + +# With method=meson we can't use cmake.subproject() +cmake = import('cmake') +testcase expect_error('Wrap method is \'meson\' but we are trying to configure it with cmake') + cmake.subproject('meson_method') +endtestcase + +# cmake.subproject() force cmake method even if meson.build exists. +testcase expect_error('Subproject exists but has no CMakeLists.txt file.') + cmake.subproject('meson_subp') +endtestcase + +# Without specifying the method it defaults to meson even if CMakeLists.txt exists. +testcase expect_error('Subproject exists but has no meson.build file.') + subproject('cmake_subp') +endtestcase diff --git a/test cases/cmake/26 dependency fallback/subprojects/broken_method.wrap b/test cases/cmake/26 dependency fallback/subprojects/broken_method.wrap new file mode 100644 index 0000000..ce0690a --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/broken_method.wrap @@ -0,0 +1,2 @@ +[wrap-file] +method=notfound diff --git a/test cases/cmake/26 dependency fallback/subprojects/cmMod.wrap b/test cases/cmake/26 dependency fallback/subprojects/cmMod.wrap new file mode 100644 index 0000000..9e6d855 --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/cmMod.wrap @@ -0,0 +1,5 @@ +[wrap-file] +method = cmake + +[provide] +cmModLib++ = cmModLib___dep diff --git a/test cases/cmake/26 dependency fallback/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/26 dependency fallback/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..d08e55c --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) +set(CMAKE_CXX_STANDARD 14) + +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) + +# Test PCH support +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0") + target_precompile_headers(cmModLib++ PRIVATE "cpp_pch.hpp") +endif() + +include(GenerateExportHeader) +generate_export_header(cmModLib++) diff --git a/test cases/cmake/26 dependency fallback/subprojects/cmMod/cmMod.cpp b/test cases/cmake/26 dependency fallback/subprojects/cmMod/cmMod.cpp new file mode 100644 index 0000000..f4cbea0 --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/cmMod/cmMod.cpp @@ -0,0 +1,15 @@ +#include "cmMod.hpp" + +using namespace std; + +#if MESON_MAGIC_FLAG != 21 +#error "Invalid MESON_MAGIC_FLAG (private)" +#endif + +cmModClass::cmModClass(string foo) { + str = foo + " World"; +} + +string cmModClass::getStr() const { + return str; +} diff --git a/test cases/cmake/26 dependency fallback/subprojects/cmMod/cmMod.hpp b/test cases/cmake/26 dependency fallback/subprojects/cmMod/cmMod.hpp new file mode 100644 index 0000000..4445e1f --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/cmMod/cmMod.hpp @@ -0,0 +1,18 @@ +#pragma once + +#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; + +public: + cmModClass(std::string foo); + + std::string getStr() const; +}; diff --git a/test cases/cmake/26 dependency fallback/subprojects/cmMod/cpp_pch.hpp b/test cases/cmake/26 dependency fallback/subprojects/cmMod/cpp_pch.hpp new file mode 100644 index 0000000..aa7ceb3 --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/cmMod/cpp_pch.hpp @@ -0,0 +1,2 @@ +#include <vector> +#include <string> diff --git a/test cases/cmake/26 dependency fallback/subprojects/cmake_subp/CMakeLists.txt b/test cases/cmake/26 dependency fallback/subprojects/cmake_subp/CMakeLists.txt new file mode 100644 index 0000000..6443fca --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/cmake_subp/CMakeLists.txt @@ -0,0 +1,2 @@ +cmake_minimum_required(VERSION 3.5) +project(cmModDummy) diff --git a/test cases/cmake/26 dependency fallback/subprojects/force_cmake.wrap b/test cases/cmake/26 dependency fallback/subprojects/force_cmake.wrap new file mode 100644 index 0000000..b24754e --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/force_cmake.wrap @@ -0,0 +1,2 @@ +[wrap-file] +method=cmake diff --git a/test cases/cmake/26 dependency fallback/subprojects/force_cmake/CMakeLists.txt b/test cases/cmake/26 dependency fallback/subprojects/force_cmake/CMakeLists.txt new file mode 100644 index 0000000..497beb9 --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/force_cmake/CMakeLists.txt @@ -0,0 +1,2 @@ +cmake_minimum_required(VERSION 3.5) +project(cmModBoth) diff --git a/test cases/cmake/26 dependency fallback/subprojects/force_cmake/meson.build b/test cases/cmake/26 dependency fallback/subprojects/force_cmake/meson.build new file mode 100644 index 0000000..9264974 --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/force_cmake/meson.build @@ -0,0 +1,4 @@ +project('both methods') + +# Ensure the meson method is not used. +notfound() diff --git a/test cases/cmake/26 dependency fallback/subprojects/meson_method.wrap b/test cases/cmake/26 dependency fallback/subprojects/meson_method.wrap new file mode 100644 index 0000000..e52701e --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/meson_method.wrap @@ -0,0 +1,2 @@ +[wrap-file] +method=meson diff --git a/test cases/cmake/26 dependency fallback/subprojects/meson_subp/meson.build b/test cases/cmake/26 dependency fallback/subprojects/meson_subp/meson.build new file mode 100644 index 0000000..e4746ce --- /dev/null +++ b/test cases/cmake/26 dependency fallback/subprojects/meson_subp/meson.build @@ -0,0 +1 @@ +project('dummy') |