From 7c4f46b65c6d9d8bf71c0eca3c75e5f8b5f73617 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Fri, 19 Apr 2019 10:14:03 +0200 Subject: [PATCH] cmake: Fixed test cases for windows --- test cases/cmake/1 basic/meson.build | 2 +- .../1 basic/subprojects/cmMod/CMakeLists.txt | 4 ++++ .../cmake/1 basic/subprojects/cmMod/cmMod.hpp | 3 ++- test cases/cmake/2 advanced/meson.build | 7 +++++- .../subprojects/cmMod/CMakeLists.txt | 3 +++ .../subprojects/cmMod/lib/cmMod.hpp | 3 ++- test cases/cmake/3 advanced no dep/main.cpp | 15 ++++++++++++ .../cmake/3 advanced no dep/meson.build | 17 ++++++++++++++ .../subprojects/cmMod/CMakeLists.txt | 19 +++++++++++++++ .../subprojects/cmMod/config.h.in | 3 +++ .../subprojects/cmMod/lib/cmMod.cpp | 16 +++++++++++++ .../subprojects/cmMod/lib/cmMod.hpp | 13 +++++++++++ .../subprojects/cmMod/main.cpp | 10 ++++++++ .../cmake/{3 code gen => 4 code gen}/main.cpp | 0 .../{3 code gen => 4 code gen}/meson.build | 4 ++-- .../subprojects/cmCodeGen/CMakeLists.txt | 0 .../subprojects/cmCodeGen/main.cpp | 0 .../cmake/{3 code gen => 4 code gen}/test.hpp | 0 .../main.cpp | 0 test cases/cmake/5 object library/meson.build | 23 +++++++++++++++++++ .../subprojects/cmObjLib/CMakeLists.txt | 0 .../subprojects/cmObjLib/libA.cpp | 0 .../subprojects/cmObjLib/libA.hpp | 0 .../subprojects/cmObjLib/libB.cpp | 0 .../subprojects/cmObjLib/libB.hpp | 0 .../cmake/6 object library no dep/main.cpp | 9 ++++++++ .../meson.build | 11 +++++---- .../subprojects/cmObjLib/CMakeLists.txt | 5 ++++ .../subprojects/cmObjLib/libA.cpp | 5 ++++ .../subprojects/cmObjLib/libA.hpp | 5 ++++ .../subprojects/cmObjLib/libB.cpp | 5 ++++ .../subprojects/cmObjLib/libB.hpp | 5 ++++ .../meson.build | 2 +- .../subprojects/cmOpts/CMakeLists.txt | 0 34 files changed, 177 insertions(+), 12 deletions(-) create mode 100644 test cases/cmake/3 advanced no dep/main.cpp create mode 100644 test cases/cmake/3 advanced no dep/meson.build create mode 100644 test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt create mode 100644 test cases/cmake/3 advanced no dep/subprojects/cmMod/config.h.in create mode 100644 test cases/cmake/3 advanced no dep/subprojects/cmMod/lib/cmMod.cpp create mode 100644 test cases/cmake/3 advanced no dep/subprojects/cmMod/lib/cmMod.hpp create mode 100644 test cases/cmake/3 advanced no dep/subprojects/cmMod/main.cpp rename test cases/cmake/{3 code gen => 4 code gen}/main.cpp (100%) rename test cases/cmake/{3 code gen => 4 code gen}/meson.build (84%) rename test cases/cmake/{3 code gen => 4 code gen}/subprojects/cmCodeGen/CMakeLists.txt (100%) rename test cases/cmake/{3 code gen => 4 code gen}/subprojects/cmCodeGen/main.cpp (100%) rename test cases/cmake/{3 code gen => 4 code gen}/test.hpp (100%) rename test cases/cmake/{4 object library => 5 object library}/main.cpp (100%) create mode 100644 test cases/cmake/5 object library/meson.build rename test cases/cmake/{4 object library => 5 object library}/subprojects/cmObjLib/CMakeLists.txt (100%) rename test cases/cmake/{4 object library => 5 object library}/subprojects/cmObjLib/libA.cpp (100%) rename test cases/cmake/{4 object library => 5 object library}/subprojects/cmObjLib/libA.hpp (100%) rename test cases/cmake/{4 object library => 5 object library}/subprojects/cmObjLib/libB.cpp (100%) rename test cases/cmake/{4 object library => 5 object library}/subprojects/cmObjLib/libB.hpp (100%) create mode 100644 test cases/cmake/6 object library no dep/main.cpp rename test cases/cmake/{4 object library => 6 object library no dep}/meson.build (62%) create mode 100644 test cases/cmake/6 object library no dep/subprojects/cmObjLib/CMakeLists.txt create mode 100644 test cases/cmake/6 object library no dep/subprojects/cmObjLib/libA.cpp create mode 100644 test cases/cmake/6 object library no dep/subprojects/cmObjLib/libA.hpp create mode 100644 test cases/cmake/6 object library no dep/subprojects/cmObjLib/libB.cpp create mode 100644 test cases/cmake/6 object library no dep/subprojects/cmObjLib/libB.hpp rename test cases/cmake/{5 cmake options => 7 cmake options}/meson.build (68%) rename test cases/cmake/{5 cmake options => 7 cmake options}/subprojects/cmOpts/CMakeLists.txt (100%) diff --git a/test cases/cmake/1 basic/meson.build b/test cases/cmake/1 basic/meson.build index de54cced4..eaa1e7ab3 100644 --- a/test cases/cmake/1 basic/meson.build +++ b/test cases/cmake/1 basic/meson.build @@ -1,4 +1,4 @@ -project('cmakeSubTest', ['cpp']) +project('cmakeSubTest', ['c', 'cpp']) sub_pro = subproject('cmMod', method: 'cmake') sub_dep = sub_pro.get_variable('cmModLib_dep') diff --git a/test cases/cmake/1 basic/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/1 basic/subprojects/cmMod/CMakeLists.txt index f27f63627..7a9538b50 100644 --- a/test cases/cmake/1 basic/subprojects/cmMod/CMakeLists.txt +++ b/test cases/cmake/1 basic/subprojects/cmMod/CMakeLists.txt @@ -3,4 +3,8 @@ cmake_minimum_required(VERSION 3.5) project(cmMod) set (CMAKE_CXX_STANDARD 14) +add_definitions("-DDO_NOTHING_JUST_A_FLAG=1") + add_library(cmModLib SHARED cmMod.cpp) +include(GenerateExportHeader) +generate_export_header(cmModLib) diff --git a/test cases/cmake/1 basic/subprojects/cmMod/cmMod.hpp b/test cases/cmake/1 basic/subprojects/cmMod/cmMod.hpp index 29938dc36..52f576bf3 100644 --- a/test cases/cmake/1 basic/subprojects/cmMod/cmMod.hpp +++ b/test cases/cmake/1 basic/subprojects/cmMod/cmMod.hpp @@ -1,8 +1,9 @@ #pragma once #include +#include "cmmodlib_export.h" -class cmModClass { +class CMMODLIB_EXPORT cmModClass { private: std::string str; public: diff --git a/test cases/cmake/2 advanced/meson.build b/test cases/cmake/2 advanced/meson.build index b3acc9785..5f949f459 100644 --- a/test cases/cmake/2 advanced/meson.build +++ b/test cases/cmake/2 advanced/meson.build @@ -1,4 +1,9 @@ -project('cmakeSubTest_advanced', ['cpp']) +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 # Test the "normal" subproject call sub_pro = subproject('cmMod') diff --git a/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt index 3f33e4dcc..14908a366 100644 --- a/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt +++ b/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt @@ -11,6 +11,9 @@ set(CONFIG_OPT 42) configure_file("config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY) add_library(cmModLib SHARED lib/cmMod.cpp) +include(GenerateExportHeader) +generate_export_header(cmModLib) + add_executable(testEXE main.cpp) target_link_libraries(cmModLib ZLIB::ZLIB) diff --git a/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp b/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp index 29938dc36..52f576bf3 100644 --- a/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp +++ b/test cases/cmake/2 advanced/subprojects/cmMod/lib/cmMod.hpp @@ -1,8 +1,9 @@ #pragma once #include +#include "cmmodlib_export.h" -class cmModClass { +class CMMODLIB_EXPORT cmModClass { private: std::string str; public: diff --git a/test cases/cmake/3 advanced no dep/main.cpp b/test cases/cmake/3 advanced no dep/main.cpp new file mode 100644 index 000000000..6cc4c0ce3 --- /dev/null +++ b/test cases/cmake/3 advanced no dep/main.cpp @@ -0,0 +1,15 @@ +#include +#include +#include "config.h" + +#if CONFIG_OPT != 42 +#error "Invalid value of CONFIG_OPT" +#endif + +using namespace std; + +int main() { + cmModClass obj("Hello"); + cout << obj.getStr() << endl; + return 0; +} diff --git a/test cases/cmake/3 advanced no dep/meson.build b/test cases/cmake/3 advanced no dep/meson.build new file mode 100644 index 000000000..b4469f351 --- /dev/null +++ b/test cases/cmake/3 advanced no dep/meson.build @@ -0,0 +1,17 @@ +project('cmakeSubTest_advanced', ['c', 'cpp']) + +# Test the "normal" subproject call +sub_pro = subproject('cmMod') +sub_dep = sub_pro.get_variable('cmModLib_dep') + +# Test the dependency shortcut +shortcut_dep = dependency('ttabadbneiobevn', fallback: ['cmMod', 'cmModLib_dep']) + +# Build some files +exe1 = executable('main1', ['main.cpp'], dependencies: [sub_dep]) +exe2 = executable('main2', ['main.cpp'], dependencies: [shortcut_dep]) +test('test1', exe1) +test('test2', exe2) + +# Test if we can also extract executables +test('test3', sub_pro.get_variable('testEXE')) diff --git a/test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 000000000..57f0a644b --- /dev/null +++ b/test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) +set(CMAKE_CXX_STANDARD 14) + +include_directories(${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) +include(GenerateExportHeader) +generate_export_header(cmModLib) + +add_executable(testEXE main.cpp) + +target_link_libraries(testEXE cmModLib) + +install(TARGETS cmModLib testEXE LIBRARY DESTINATION lib RUNTIME DESTINATION bin) diff --git a/test cases/cmake/3 advanced no dep/subprojects/cmMod/config.h.in b/test cases/cmake/3 advanced no dep/subprojects/cmMod/config.h.in new file mode 100644 index 000000000..f538ac985 --- /dev/null +++ b/test cases/cmake/3 advanced no dep/subprojects/cmMod/config.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define CONFIG_OPT @CONFIG_OPT@ diff --git a/test cases/cmake/3 advanced no dep/subprojects/cmMod/lib/cmMod.cpp b/test cases/cmake/3 advanced no dep/subprojects/cmMod/lib/cmMod.cpp new file mode 100644 index 000000000..741e8dff0 --- /dev/null +++ b/test cases/cmake/3 advanced no dep/subprojects/cmMod/lib/cmMod.cpp @@ -0,0 +1,16 @@ +#include "cmMod.hpp" +#include "config.h" + +#if CONFIG_OPT != 42 +#error "Invalid value of CONFIG_OPT" +#endif + +using namespace std; + +cmModClass::cmModClass(string foo) { + str = foo + " World"; +} + +string cmModClass::getStr() const { + return str; +} diff --git a/test cases/cmake/3 advanced no dep/subprojects/cmMod/lib/cmMod.hpp b/test cases/cmake/3 advanced no dep/subprojects/cmMod/lib/cmMod.hpp new file mode 100644 index 000000000..52f576bf3 --- /dev/null +++ b/test cases/cmake/3 advanced no dep/subprojects/cmMod/lib/cmMod.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include +#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/3 advanced no dep/subprojects/cmMod/main.cpp b/test cases/cmake/3 advanced no dep/subprojects/cmMod/main.cpp new file mode 100644 index 000000000..cd2104217 --- /dev/null +++ b/test cases/cmake/3 advanced no dep/subprojects/cmMod/main.cpp @@ -0,0 +1,10 @@ +#include +#include "lib/cmMod.hpp" + +using namespace std; + +int main() { + cmModClass obj("Hello (LIB TEST)"); + cout << obj.getStr() << endl; + return 0; +} diff --git a/test cases/cmake/3 code gen/main.cpp b/test cases/cmake/4 code gen/main.cpp similarity index 100% rename from test cases/cmake/3 code gen/main.cpp rename to test cases/cmake/4 code gen/main.cpp diff --git a/test cases/cmake/3 code gen/meson.build b/test cases/cmake/4 code gen/meson.build similarity index 84% rename from test cases/cmake/3 code gen/meson.build rename to test cases/cmake/4 code gen/meson.build index daa93cedd..a592dfbd8 100644 --- a/test cases/cmake/3 code gen/meson.build +++ b/test cases/cmake/4 code gen/meson.build @@ -1,4 +1,4 @@ -project('cmake_code_gen', ['cpp']) +project('cmake_code_gen', ['c', 'cpp']) # Subproject with the "code generator" sub_pro = subproject('cmCodeGen') @@ -15,4 +15,4 @@ generated = custom_target( # Build the exe exe1 = executable('main1', ['main.cpp', generated]) -test('test1', exe1) \ No newline at end of file +test('test1', exe1) diff --git a/test cases/cmake/3 code gen/subprojects/cmCodeGen/CMakeLists.txt b/test cases/cmake/4 code gen/subprojects/cmCodeGen/CMakeLists.txt similarity index 100% rename from test cases/cmake/3 code gen/subprojects/cmCodeGen/CMakeLists.txt rename to test cases/cmake/4 code gen/subprojects/cmCodeGen/CMakeLists.txt diff --git a/test cases/cmake/3 code gen/subprojects/cmCodeGen/main.cpp b/test cases/cmake/4 code gen/subprojects/cmCodeGen/main.cpp similarity index 100% rename from test cases/cmake/3 code gen/subprojects/cmCodeGen/main.cpp rename to test cases/cmake/4 code gen/subprojects/cmCodeGen/main.cpp diff --git a/test cases/cmake/3 code gen/test.hpp b/test cases/cmake/4 code gen/test.hpp similarity index 100% rename from test cases/cmake/3 code gen/test.hpp rename to test cases/cmake/4 code gen/test.hpp diff --git a/test cases/cmake/4 object library/main.cpp b/test cases/cmake/5 object library/main.cpp similarity index 100% rename from test cases/cmake/4 object library/main.cpp rename to test cases/cmake/5 object library/main.cpp diff --git a/test cases/cmake/5 object library/meson.build b/test cases/cmake/5 object library/meson.build new file mode 100644 index 000000000..76e16bec2 --- /dev/null +++ b/test cases/cmake/5 object library/meson.build @@ -0,0 +1,23 @@ +project('cmake_object_lib_test', ['c', 'cpp']) + +dep_test = dependency('ZLIB', method: 'cmake', required: false) +if not dep_test.found() + error('MESON_SKIP_TEST: zlib is not installed') +endif + +if build_machine.system() == 'windows' + error('MESON_SKIP_TEST: Windows is not supported because of symbol export problems') +endif + +sub_pro = subproject('cmObjLib') +sub_sha = sub_pro.get_variable('lib_sha_dep') +sub_sta = sub_pro.get_variable('lib_sta_dep') + +# Required for the static library +zlib_dep = dependency('zlib') + +exe_sha = executable('shared', ['main.cpp'], dependencies: [sub_sha]) +exe_sta = executable('static', ['main.cpp'], dependencies: [sub_sta, zlib_dep]) + +test('test1', exe_sha) +test('test1', exe_sta) diff --git a/test cases/cmake/4 object library/subprojects/cmObjLib/CMakeLists.txt b/test cases/cmake/5 object library/subprojects/cmObjLib/CMakeLists.txt similarity index 100% rename from test cases/cmake/4 object library/subprojects/cmObjLib/CMakeLists.txt rename to test cases/cmake/5 object library/subprojects/cmObjLib/CMakeLists.txt diff --git a/test cases/cmake/4 object library/subprojects/cmObjLib/libA.cpp b/test cases/cmake/5 object library/subprojects/cmObjLib/libA.cpp similarity index 100% rename from test cases/cmake/4 object library/subprojects/cmObjLib/libA.cpp rename to test cases/cmake/5 object library/subprojects/cmObjLib/libA.cpp diff --git a/test cases/cmake/4 object library/subprojects/cmObjLib/libA.hpp b/test cases/cmake/5 object library/subprojects/cmObjLib/libA.hpp similarity index 100% rename from test cases/cmake/4 object library/subprojects/cmObjLib/libA.hpp rename to test cases/cmake/5 object library/subprojects/cmObjLib/libA.hpp diff --git a/test cases/cmake/4 object library/subprojects/cmObjLib/libB.cpp b/test cases/cmake/5 object library/subprojects/cmObjLib/libB.cpp similarity index 100% rename from test cases/cmake/4 object library/subprojects/cmObjLib/libB.cpp rename to test cases/cmake/5 object library/subprojects/cmObjLib/libB.cpp diff --git a/test cases/cmake/4 object library/subprojects/cmObjLib/libB.hpp b/test cases/cmake/5 object library/subprojects/cmObjLib/libB.hpp similarity index 100% rename from test cases/cmake/4 object library/subprojects/cmObjLib/libB.hpp rename to test cases/cmake/5 object library/subprojects/cmObjLib/libB.hpp diff --git a/test cases/cmake/6 object library no dep/main.cpp b/test cases/cmake/6 object library no dep/main.cpp new file mode 100644 index 000000000..f3836087b --- /dev/null +++ b/test cases/cmake/6 object library no dep/main.cpp @@ -0,0 +1,9 @@ +#include +#include "libA.hpp" +#include "libB.hpp" + +using namespace std; + +int main() { + cout << getLibStr() << " -- " << getZlibVers() << endl; +} diff --git a/test cases/cmake/4 object library/meson.build b/test cases/cmake/6 object library no dep/meson.build similarity index 62% rename from test cases/cmake/4 object library/meson.build rename to test cases/cmake/6 object library no dep/meson.build index 05cd7f719..8e1eaf973 100644 --- a/test cases/cmake/4 object library/meson.build +++ b/test cases/cmake/6 object library no dep/meson.build @@ -1,14 +1,15 @@ -project('cmake_object_lib_test', ['cpp']) +project('cmake_object_lib_test', ['c', 'cpp']) + +if build_machine.system() == 'windows' + error('MESON_SKIP_TEST: Windows is not supported because of symbol export problems') +endif sub_pro = subproject('cmObjLib') sub_sha = sub_pro.get_variable('lib_sha_dep') sub_sta = sub_pro.get_variable('lib_sta_dep') -# Required for the static library -zlib_dep = dependency('zlib') - exe_sha = executable('shared', ['main.cpp'], dependencies: [sub_sha]) -exe_sta = executable('static', ['main.cpp'], dependencies: [sub_sta, zlib_dep]) +exe_sta = executable('static', ['main.cpp'], dependencies: [sub_sta]) test('test1', exe_sha) test('test1', exe_sta) diff --git a/test cases/cmake/6 object library no dep/subprojects/cmObjLib/CMakeLists.txt b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/CMakeLists.txt new file mode 100644 index 000000000..08c6a1848 --- /dev/null +++ b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.7) + +add_library(lib_obj OBJECT libA.cpp libB.cpp) +add_library(lib_sha SHARED $) +add_library(lib_sta STATIC $) diff --git a/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libA.cpp b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libA.cpp new file mode 100644 index 000000000..3736b2c2d --- /dev/null +++ b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libA.cpp @@ -0,0 +1,5 @@ +#include "libA.hpp" + +std::string getLibStr() { + return "Hello World"; +} diff --git a/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libA.hpp b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libA.hpp new file mode 100644 index 000000000..58c941321 --- /dev/null +++ b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libA.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include + +std::string getLibStr(); diff --git a/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libB.cpp b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libB.cpp new file mode 100644 index 000000000..187d10f39 --- /dev/null +++ b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libB.cpp @@ -0,0 +1,5 @@ +#include "libB.hpp" + +std::string getZlibVers() { + return "STUB"; +} diff --git a/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libB.hpp b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libB.hpp new file mode 100644 index 000000000..71db6b7a3 --- /dev/null +++ b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/libB.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include + +std::string getZlibVers(); diff --git a/test cases/cmake/5 cmake options/meson.build b/test cases/cmake/7 cmake options/meson.build similarity index 68% rename from test cases/cmake/5 cmake options/meson.build rename to test cases/cmake/7 cmake options/meson.build index 3b58515a0..55813fbc2 100644 --- a/test cases/cmake/5 cmake options/meson.build +++ b/test cases/cmake/7 cmake options/meson.build @@ -1,3 +1,3 @@ -project('cmake_set_opt', ['c']) +project('cmake_set_opt', ['c', 'cpp']) subproject('cmOpts', method: 'cmake', cmake_options: '-DSOME_CMAKE_VAR=something') diff --git a/test cases/cmake/5 cmake options/subprojects/cmOpts/CMakeLists.txt b/test cases/cmake/7 cmake options/subprojects/cmOpts/CMakeLists.txt similarity index 100% rename from test cases/cmake/5 cmake options/subprojects/cmOpts/CMakeLists.txt rename to test cases/cmake/7 cmake options/subprojects/cmOpts/CMakeLists.txt