summaryrefslogtreecommitdiffstats
path: root/test cases/cmake/15 object library advanced
diff options
context:
space:
mode:
Diffstat (limited to 'test cases/cmake/15 object library advanced')
-rw-r--r--test cases/cmake/15 object library advanced/main.cpp11
-rw-r--r--test cases/cmake/15 object library advanced/meson.build17
-rw-r--r--test cases/cmake/15 object library advanced/subprojects/cmObjLib/CMakeLists.txt18
-rw-r--r--test cases/cmake/15 object library advanced/subprojects/cmObjLib/genC.cpp31
-rw-r--r--test cases/cmake/15 object library advanced/subprojects/cmObjLib/libA.cpp9
-rw-r--r--test cases/cmake/15 object library advanced/subprojects/cmObjLib/libA.hpp16
-rw-r--r--test cases/cmake/15 object library advanced/subprojects/cmObjLib/libB.cpp6
-rw-r--r--test cases/cmake/15 object library advanced/subprojects/cmObjLib/libB.hpp16
8 files changed, 124 insertions, 0 deletions
diff --git a/test cases/cmake/15 object library advanced/main.cpp b/test cases/cmake/15 object library advanced/main.cpp
new file mode 100644
index 0000000..4cc01a8
--- /dev/null
+++ b/test cases/cmake/15 object library advanced/main.cpp
@@ -0,0 +1,11 @@
+#include <iostream>
+#include "libA.hpp"
+#include "libB.hpp"
+
+using namespace std;
+
+int main(void) {
+ cout << getLibStr() << endl;
+ cout << getZlibVers() << endl;
+ return EXIT_SUCCESS;
+}
diff --git a/test cases/cmake/15 object library advanced/meson.build b/test cases/cmake/15 object library advanced/meson.build
new file mode 100644
index 0000000..4009a0d
--- /dev/null
+++ b/test cases/cmake/15 object library advanced/meson.build
@@ -0,0 +1,17 @@
+project('cmake_object_lib_test', 'cpp', default_options: ['cpp_std=c++11'])
+
+if meson.is_cross_build()
+ error('MESON_SKIP_TEST this test does not cross compile correctly.')
+endif
+
+cm = import('cmake')
+
+sub_pro = cm.subproject('cmObjLib')
+sub_sha = sub_pro.dependency('lib_sha')
+sub_sta = sub_pro.dependency('lib_sta')
+
+exe_sha = executable('shared', ['main.cpp'], dependencies: [sub_sha])
+exe_sta = executable('static', ['main.cpp'], dependencies: [sub_sta])
+
+test('test1', exe_sha)
+test('test1', exe_sta)
diff --git a/test cases/cmake/15 object library advanced/subprojects/cmObjLib/CMakeLists.txt b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/CMakeLists.txt
new file mode 100644
index 0000000..47f1ad3
--- /dev/null
+++ b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/CMakeLists.txt
@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 3.7)
+project(cmObject CXX)
+
+add_executable(genC genC.cpp)
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libC.cpp" "${CMAKE_CURRENT_BINARY_DIR}/libC.hpp"
+ COMMAND genC
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+)
+
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+
+add_library(lib_obj OBJECT libA.cpp libB.cpp "${CMAKE_CURRENT_BINARY_DIR}/libC.cpp" "${CMAKE_CURRENT_BINARY_DIR}/libC.hpp")
+add_library(lib_sha SHARED $<TARGET_OBJECTS:lib_obj>)
+add_library(lib_sta STATIC $<TARGET_OBJECTS:lib_obj>)
+
+target_compile_definitions(lib_obj PRIVATE "-DBUILD_AS_OBJ=1")
diff --git a/test cases/cmake/15 object library advanced/subprojects/cmObjLib/genC.cpp b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/genC.cpp
new file mode 100644
index 0000000..a9e4b5e
--- /dev/null
+++ b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/genC.cpp
@@ -0,0 +1,31 @@
+#include <iostream>
+#include <fstream>
+
+using namespace std;
+
+int main() {
+ ofstream hpp("libC.hpp");
+ ofstream cpp("libC.cpp");
+ if (!hpp.is_open() || !cpp.is_open()) {
+ cerr << "Failed to open 'libC.hpp' or 'libC.cpp' for writing" << endl;
+ return 1;
+ }
+
+ hpp << R"cpp(
+#pragma once
+
+#include <string>
+
+std::string getGenStr();
+)cpp";
+
+ cpp << R"cpp(
+#include "libC.hpp"
+
+std::string getGenStr(void) {
+ return "GEN STR";
+}
+)cpp";
+
+ return 0;
+} \ No newline at end of file
diff --git a/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libA.cpp b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libA.cpp
new file mode 100644
index 0000000..fd5aa48
--- /dev/null
+++ b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libA.cpp
@@ -0,0 +1,9 @@
+#include "libA.hpp"
+
+#if not BUILD_AS_OBJ
+#error "BUILD_AS_OBJ was not defined"
+#endif
+
+std::string getLibStr(void) {
+ return "Hello World";
+}
diff --git a/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libA.hpp b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libA.hpp
new file mode 100644
index 0000000..84b7bc7
--- /dev/null
+++ b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libA.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <string>
+
+#if defined _WIN32 || defined __CYGWIN__
+ #define DLL_PUBLIC __declspec(dllexport)
+#else
+ #if defined __GNUC__
+ #define DLL_PUBLIC __attribute__ ((visibility("default")))
+ #else
+ #pragma message ("Compiler does not support symbol visibility.")
+ #define DLL_PUBLIC
+ #endif
+#endif
+
+std::string DLL_PUBLIC getLibStr();
diff --git a/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libB.cpp b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libB.cpp
new file mode 100644
index 0000000..4b832ec
--- /dev/null
+++ b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libB.cpp
@@ -0,0 +1,6 @@
+#include "libB.hpp"
+#include "libC.hpp"
+
+std::string getZlibVers(void) {
+ return getGenStr();
+}
diff --git a/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libB.hpp b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libB.hpp
new file mode 100644
index 0000000..52ccc16
--- /dev/null
+++ b/test cases/cmake/15 object library advanced/subprojects/cmObjLib/libB.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <string>
+
+#if defined _WIN32 || defined __CYGWIN__
+ #define DLL_PUBLIC __declspec(dllexport)
+#else
+ #if defined __GNUC__
+ #define DLL_PUBLIC __attribute__ ((visibility("default")))
+ #else
+ #pragma message ("Compiler does not support symbol visibility.")
+ #define DLL_PUBLIC
+ #endif
+#endif
+
+std::string DLL_PUBLIC getZlibVers();