summaryrefslogtreecommitdiffstats
path: root/test cases/cmake/2 advanced
diff options
context:
space:
mode:
Diffstat (limited to 'test cases/cmake/2 advanced')
-rw-r--r--test cases/cmake/2 advanced/main.cpp15
-rw-r--r--test cases/cmake/2 advanced/meson.build27
-rw-r--r--test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt38
-rw-r--r--test cases/cmake/2 advanced/subprojects/cmMod/config.h.in3
-rw-r--r--test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.cpp26
-rw-r--r--test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp13
-rw-r--r--test cases/cmake/2 advanced/subprojects/cmMod/main.cpp11
-rw-r--r--test cases/cmake/2 advanced/test.json5
8 files changed, 138 insertions, 0 deletions
diff --git a/test cases/cmake/2 advanced/main.cpp b/test cases/cmake/2 advanced/main.cpp
new file mode 100644
index 0000000..d823e29
--- /dev/null
+++ b/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/test cases/cmake/2 advanced/meson.build b/test cases/cmake/2 advanced/meson.build
new file mode 100644
index 0000000..b301bfe
--- /dev/null
+++ b/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/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt
new file mode 100644
index 0000000..0750117
--- /dev/null
+++ b/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 "${CMAKE_CURRENT_BINARY_DIR}/config.h")
+
+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/test cases/cmake/2 advanced/subprojects/cmMod/config.h.in b/test cases/cmake/2 advanced/subprojects/cmMod/config.h.in
new file mode 100644
index 0000000..f538ac9
--- /dev/null
+++ b/test cases/cmake/2 advanced/subprojects/cmMod/config.h.in
@@ -0,0 +1,3 @@
+#pragma once
+
+#define CONFIG_OPT @CONFIG_OPT@
diff --git a/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.cpp b/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.cpp
new file mode 100644
index 0000000..eb41438
--- /dev/null
+++ b/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/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp b/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp
new file mode 100644
index 0000000..52f576b
--- /dev/null
+++ b/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/test cases/cmake/2 advanced/subprojects/cmMod/main.cpp b/test cases/cmake/2 advanced/subprojects/cmMod/main.cpp
new file mode 100644
index 0000000..77fab68
--- /dev/null
+++ b/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/test cases/cmake/2 advanced/test.json b/test cases/cmake/2 advanced/test.json
new file mode 100644
index 0000000..29888ea
--- /dev/null
+++ b/test cases/cmake/2 advanced/test.json
@@ -0,0 +1,5 @@
+{
+ "installed": [
+ {"type": "exe", "file": "usr/bin/testEXE"}
+ ]
+}