diff options
Diffstat (limited to 'meson/test cases/cmake/2 advanced')
8 files changed, 141 insertions, 0 deletions
diff --git a/meson/test cases/cmake/2 advanced/main.cpp b/meson/test cases/cmake/2 advanced/main.cpp new file mode 100644 index 000000000..d823e2964 --- /dev/null +++ b/meson/test cases/cmake/2 advanced/main.cpp @@ -0,0 +1,15 @@ +#include <iostream> +#include <cmMod.hpp> +#include "config.h" + +#if CONFIG_OPT != 42 +#error "Invalid value of CONFIG_OPT" +#endif + +using namespace std; + +int main(void) { + cmModClass obj("Hello"); + cout << obj.getStr() << endl; + return 0; +} diff --git a/meson/test cases/cmake/2 advanced/meson.build b/meson/test cases/cmake/2 advanced/meson.build new file mode 100644 index 000000000..b301bfe42 --- /dev/null +++ b/meson/test cases/cmake/2 advanced/meson.build @@ -0,0 +1,27 @@ +project('cmakeSubTest_advanced', ['c', 'cpp']) + +dep_test = dependency('ZLIB', method: 'cmake', required: false) +if not dep_test.found() + error('MESON_SKIP_TEST: zlib is not installed') +endif + +cm = import('cmake') + +# Test the "normal" subproject call +sub_pro = cm.subproject('cmMod') +sub_dep = sub_pro.dependency('cmModLib') +sub_sta = sub_pro.dependency('cmModLibStatic') + +# Build some files +exe1 = executable('main1', ['main.cpp'], dependencies: [sub_dep]) +exe2 = executable('main2', ['main.cpp'], dependencies: [sub_sta]) +test('test1', exe1) +test('test2', exe2) + +# Test if we can also extract executables +assert(sub_pro.target_type('testEXE') == 'executable', 'The type must be executable for obvious reasons') +test('test3', sub_pro.target('testEXE')) + +# Test that we can add a new target with the same name as the CMake subproject +exe4 = executable('testEXE', ['main.cpp'], dependencies: [sub_sta]) +test('test4', exe4) diff --git a/meson/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt b/meson/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 000000000..6258ca0b4 --- /dev/null +++ b/meson/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) +set(CMAKE_CXX_STANDARD 14) + +find_package(ZLIB REQUIRED) + +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib) + +set(CONFIG_OPT 42) +configure_file("config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY) + +add_library(cmModLib SHARED lib/cmMod.cpp) +add_library(cmModLibStatic STATIC lib/cmMod.cpp) +include(GenerateExportHeader) +generate_export_header(cmModLib) + +set_target_properties(cmModLib PROPERTIES VERSION 1.0.1) + +add_executable(testEXE main.cpp) + +target_link_libraries(cmModLib ZLIB::ZLIB) +target_link_libraries(cmModLibStatic ;ZLIB::ZLIB;) +target_link_libraries(testEXE cmModLib) + +if(APPLE) + find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation") + if(NOT COREFOUNDATION_FRAMEWORK) + message(FATAL_ERROR "CoreFoundation framework not found") + endif() + + target_link_libraries(cmModLibStatic "${COREFOUNDATION_FRAMEWORK}") + target_compile_definitions(cmModLibStatic PUBLIC USE_FRAMEWORK) +endif() + +target_compile_definitions(cmModLibStatic PUBLIC CMMODLIB_STATIC_DEFINE) + +install(TARGETS testEXE LIBRARY DESTINATION lib RUNTIME DESTINATION bin) diff --git a/meson/test cases/cmake/2 advanced/subprojects/cmMod/config.h.in b/meson/test cases/cmake/2 advanced/subprojects/cmMod/config.h.in new file mode 100644 index 000000000..f538ac985 --- /dev/null +++ b/meson/test cases/cmake/2 advanced/subprojects/cmMod/config.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define CONFIG_OPT @CONFIG_OPT@ diff --git a/meson/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.cpp b/meson/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.cpp new file mode 100644 index 000000000..eb414382d --- /dev/null +++ b/meson/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.cpp @@ -0,0 +1,26 @@ +#include "cmMod.hpp" +#include <zlib.h> +#include "config.h" + +#if CONFIG_OPT != 42 +#error "Invalid value of CONFIG_OPT" +#endif + +#ifdef USE_FRAMEWORK +#include <CoreFoundation/CoreFoundation.h> +#endif + +using namespace std; + +cmModClass::cmModClass(string foo) { + str = foo + " World " + zlibVersion(); + +#ifdef USE_FRAMEWORK + CFStringRef ref = CFStringCreateWithCString(NULL, str.c_str(), kCFStringEncodingUTF8); + CFRelease(ref); +#endif +} + +string cmModClass::getStr() const { + return str; +} diff --git a/meson/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp b/meson/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp new file mode 100644 index 000000000..52f576bf3 --- /dev/null +++ b/meson/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include <string> +#include "cmmodlib_export.h" + +class CMMODLIB_EXPORT cmModClass { + private: + std::string str; + public: + cmModClass(std::string foo); + + std::string getStr() const; +}; diff --git a/meson/test cases/cmake/2 advanced/subprojects/cmMod/main.cpp b/meson/test cases/cmake/2 advanced/subprojects/cmMod/main.cpp new file mode 100644 index 000000000..77fab68ab --- /dev/null +++ b/meson/test cases/cmake/2 advanced/subprojects/cmMod/main.cpp @@ -0,0 +1,11 @@ +#include <iostream> +#include <zlib.h> +#include "lib/cmMod.hpp" + +using namespace std; + +int main(void) { + cmModClass obj("Hello (LIB TEST)"); + cout << obj.getStr() << " ZLIB: " << zlibVersion() << endl; + return 0; +} diff --git a/meson/test cases/cmake/2 advanced/test.json b/meson/test cases/cmake/2 advanced/test.json new file mode 100644 index 000000000..71ea812c7 --- /dev/null +++ b/meson/test cases/cmake/2 advanced/test.json @@ -0,0 +1,8 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/testEXE"} + ], + "tools": { + "cmake": ">=3.11" + } +} |