diff options
Diffstat (limited to 'test cases/cmake')
170 files changed, 2424 insertions, 0 deletions
diff --git a/test cases/cmake/1 basic/main.cpp b/test cases/cmake/1 basic/main.cpp new file mode 100644 index 0000000..9507961 --- /dev/null +++ b/test cases/cmake/1 basic/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/1 basic/meson.build b/test cases/cmake/1 basic/meson.build new file mode 100644 index 0000000..2464739 --- /dev/null +++ b/test cases/cmake/1 basic/meson.build @@ -0,0 +1,14 @@ +project('cmakeSubTest', ['c', 'cpp']) + +cm = import('cmake') + +sub_pro = cm.subproject('cmMod') +sub_dep = sub_pro.dependency('cmModLib++', include_type: 'system') + +assert(sub_pro.found(), 'found() method reports not found, but should be found') +assert(sub_pro.target_list() == ['cmModLib++'], 'There should be exactly one target') +assert(sub_pro.target_type('cmModLib++') == 'shared_library', 'Target type should be shared_library') +assert(sub_dep.include_type() == 'system', 'the include_type kwarg of dependency() works') + +exe1 = executable('main', ['main.cpp'], dependencies: [sub_dep]) +test('test1', exe1) diff --git a/test cases/cmake/1 basic/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/1 basic/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..2197667 --- /dev/null +++ b/test cases/cmake/1 basic/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/1 basic/subprojects/cmMod/cmMod.cpp b/test cases/cmake/1 basic/subprojects/cmMod/cmMod.cpp new file mode 100644 index 0000000..f4cbea0 --- /dev/null +++ b/test cases/cmake/1 basic/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/1 basic/subprojects/cmMod/cmMod.hpp b/test cases/cmake/1 basic/subprojects/cmMod/cmMod.hpp new file mode 100644 index 0000000..4445e1f --- /dev/null +++ b/test cases/cmake/1 basic/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/1 basic/subprojects/cmMod/cpp_pch.hpp b/test cases/cmake/1 basic/subprojects/cmMod/cpp_pch.hpp new file mode 100644 index 0000000..aa7ceb3 --- /dev/null +++ b/test cases/cmake/1 basic/subprojects/cmMod/cpp_pch.hpp @@ -0,0 +1,2 @@ +#include <vector> +#include <string> diff --git a/test cases/cmake/10 header only/main.cpp b/test cases/cmake/10 header only/main.cpp new file mode 100644 index 0000000..1417881 --- /dev/null +++ b/test cases/cmake/10 header only/main.cpp @@ -0,0 +1,16 @@ +#include <iostream> +#include <cmMod.hpp> + +using namespace std; + +#define EXPECTED "Hello World compDef 42" + +int main(void) { + cmModClass obj("Hello"); + cout << obj.getStr() << endl; + if (obj.getStr() != EXPECTED) { + cerr << "Expected: '" << EXPECTED << "'" << endl; + return 1; + } + return 0; +} diff --git a/test cases/cmake/10 header only/meson.build b/test cases/cmake/10 header only/meson.build new file mode 100644 index 0000000..ca08a3f --- /dev/null +++ b/test cases/cmake/10 header only/meson.build @@ -0,0 +1,12 @@ +project('cmakeSubTest', ['c', 'cpp']) + +cm = import('cmake') + +sub_pro = cm.subproject('cmMod') +sub_dep = sub_pro.dependency('cmModLib') + +assert(sub_pro.target_list() == ['cmModLib'], 'There should be exactly one target') +assert(sub_pro.target_type('cmModLib') == 'header_only', 'Target type should be header_only') + +exe1 = executable('main', ['main.cpp'], dependencies: [sub_dep]) +test('test1', exe1) diff --git a/test cases/cmake/10 header only/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/10 header only/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..e01b6e2 --- /dev/null +++ b/test cases/cmake/10 header only/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) +set (CMAKE_CXX_STANDARD 14) + +add_definitions("-DDO_NOTHING_JUST_A_FLAG=1") + +add_library(cmModLib INTERFACE) +set_target_properties(cmModLib PROPERTIES INTERFACE_COMPILE_OPTIONS "-DCMAKE_FLAG_MUST_BE_PRESENT") +target_include_directories(cmModLib INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_compile_definitions(cmModLib INTERFACE -DCMAKE_COMPILER_DEFINE_STR="compDef") +target_compile_definitions(cmModLib INTERFACE MESON_MAGIC_FLAG=42) diff --git a/test cases/cmake/10 header only/subprojects/cmMod/include/cmMod.hpp b/test cases/cmake/10 header only/subprojects/cmMod/include/cmMod.hpp new file mode 100644 index 0000000..fe01040 --- /dev/null +++ b/test cases/cmake/10 header only/subprojects/cmMod/include/cmMod.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <string> + +#ifndef CMAKE_FLAG_MUST_BE_PRESENT +#error "The flag CMAKE_FLAG_MUST_BE_PRESENT was not set" +#endif + +#define xstr(s) str(s) +#define str(s) #s + +class cmModClass { + private: + std::string str; + public: + cmModClass(std::string foo) { + str = foo + " World "; + str += CMAKE_COMPILER_DEFINE_STR; + str += ' '; + str += xstr(MESON_MAGIC_FLAG); + } + + inline std::string getStr() const { return str; } +}; diff --git a/test cases/cmake/11 cmake_module_path/cmake/FindSomethingLikePython.cmake b/test cases/cmake/11 cmake_module_path/cmake/FindSomethingLikePython.cmake new file mode 100644 index 0000000..0c663f4 --- /dev/null +++ b/test cases/cmake/11 cmake_module_path/cmake/FindSomethingLikePython.cmake @@ -0,0 +1,9 @@ +cmake_policy(VERSION 3.7) + +find_package(Python COMPONENTS Interpreter) +if(Python_FOUND OR PYTHONINTERP_FOUND) + set(SomethingLikePython_FOUND ON) + set(SomethingLikePython_EXECUTABLE ${Python_EXECUTABLE}) +else() + set(SomethingLikePython_FOUND OFF) +endif() diff --git a/test cases/cmake/11 cmake_module_path/meson.build b/test cases/cmake/11 cmake_module_path/meson.build new file mode 100644 index 0000000..e201936 --- /dev/null +++ b/test cases/cmake/11 cmake_module_path/meson.build @@ -0,0 +1,25 @@ +# We use Python3 as it's the only thing guaranteed to be available on any platform Meson can run on (unlike Zlib in linuxlike/13 cmake dependency). + +project('user CMake find_package module using cmake_module_path', ['c', 'cpp'], + meson_version: '>= 0.55.0') + +if not find_program('cmake', required: false).found() + error('MESON_SKIP_TEST cmake binary not available.') +endif + +# NOTE: can't request Python3 via dependency('Python3', method: 'cmake') +# Meson intercepts and wants "method: auto" + +# Try to find a dependency with a custom CMake module + +dependency('SomethingLikePython', required : true, method : 'cmake', cmake_module_path : 'cmake', modules: 'Python::Interpreter') + +dependency('SomethingLikePython', method : 'cmake', cmake_module_path : ['doesNotExist', 'cmake'], modules: 'Python::Interpreter') + +# Test a custom target with Python::Interpreter in COMMAND +cm = import('cmake') +op = cm.subproject_options() +op.add_cmake_defines({'CMAKE_MODULE_PATH': meson.source_root() / 'cmake'}) +sp = cm.subproject('cmMod', options: op) +main = sp.target('main') +test('main', main) diff --git a/test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..88ba9bc --- /dev/null +++ b/test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) + +message(STATUS "CMAKE_MODULE_PATH: '${CMAKE_MODULE_PATH}'") + +find_package(SomethingLikePython REQUIRED) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main.c" + COMMAND Python::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/gen.py" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) + +add_executable(main "${CMAKE_CURRENT_BINARY_DIR}/main.c") diff --git a/test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py b/test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py new file mode 100644 index 0000000..5c71646 --- /dev/null +++ b/test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py @@ -0,0 +1,9 @@ +with open('main.c', 'w') as fp: + print(''' +#include <stdio.h> + +int main(void) { + printf(\"Hello World\"); + return 0; +} +''', file=fp) diff --git a/test cases/cmake/12 generator expressions/main.cpp b/test cases/cmake/12 generator expressions/main.cpp new file mode 100644 index 0000000..9507961 --- /dev/null +++ b/test cases/cmake/12 generator expressions/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/12 generator expressions/meson.build b/test cases/cmake/12 generator expressions/meson.build new file mode 100644 index 0000000..ca08a3f --- /dev/null +++ b/test cases/cmake/12 generator expressions/meson.build @@ -0,0 +1,12 @@ +project('cmakeSubTest', ['c', 'cpp']) + +cm = import('cmake') + +sub_pro = cm.subproject('cmMod') +sub_dep = sub_pro.dependency('cmModLib') + +assert(sub_pro.target_list() == ['cmModLib'], 'There should be exactly one target') +assert(sub_pro.target_type('cmModLib') == 'header_only', 'Target type should be header_only') + +exe1 = executable('main', ['main.cpp'], dependencies: [sub_dep]) +test('test1', exe1) diff --git a/test cases/cmake/12 generator expressions/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/12 generator expressions/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..27b3721 --- /dev/null +++ b/test cases/cmake/12 generator expressions/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) +set (CMAKE_CXX_STANDARD 14) + +include(GNUInstallDirs) + +add_library(cmModLib INTERFACE) + +target_compile_options(cmModLib + INTERFACE $<$<AND:$<CONFIG:Release>,$<CONFIG:Debug>>:-DCMAKE_FLAG_ERROR_A> # Check discard = false + INTERFACE "-DCMAKE_FLAG_REQUIRED_A" + INTERFACE $<$<AND:1,$<STREQUAL:asd,$<LOWER_CASE:AsD>>,$<NOT:$<EQUAL:4,2>>>:-DCMAKE_FLAG_REQUIRED_B> + INTERFACE $<$<VERSION_LESS:1.2.3,2.1.0>:-DCMAKE_FLAG_REQUIRED_C> + INTERFACE $<IF:$<NOT:$<BOOL:OFF>>,-DCMAKE_TRUE_FLAG,-DCMAKE_FALSE_FLAG> + INTERFACE $<IF:$<TARGET_EXISTS:cmModLib>,-DCMAKE_TGT_EXISTS,-DCMAKE_TGT_NEXISTS> + INTERFACE $<IF:$<TARGET_PROPERTY:IMPORTED_NO_SONAME>,-DCMAKE_PROP1_OK,-DCMAKE_PROP1_ERROR> + INTERFACE $<IF:$<TARGET_PROPERTY:cmModLib,IMPORT_SUFFIX>,-DCMAKE_PROP2_ERROR,-DCMAKE_PROP2_OK> +) + +target_include_directories(cmModLib INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> +) + +set_target_properties(cmModLib + PROPERTIES + IMPORTED_NO_SONAME 1 + IMPORT_SUFFIX 0 +) + +target_compile_definitions(cmModLib INTERFACE -DCMAKE_COMPILER_DEFINE_STR="compDef") diff --git a/test cases/cmake/12 generator expressions/subprojects/cmMod/include/cmMod.hpp b/test cases/cmake/12 generator expressions/subprojects/cmMod/include/cmMod.hpp new file mode 100644 index 0000000..416e5bb --- /dev/null +++ b/test cases/cmake/12 generator expressions/subprojects/cmMod/include/cmMod.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include <string> + +#ifndef CMAKE_FLAG_REQUIRED_A +#error "The flag CMAKE_FLAG_REQUIRED_A was not set" +#endif + +#ifndef CMAKE_FLAG_REQUIRED_B +#error "The flag CMAKE_FLAG_REQUIRED_B was not set" +#endif + +#ifndef CMAKE_FLAG_REQUIRED_C +#error "The flag CMAKE_FLAG_REQUIRED_C was not set" +#endif + +#ifdef CMAKE_FLAG_ERROR_A +#error "The flag CMAKE_FLAG_ERROR_A was set" +#endif + +#ifndef CMAKE_TRUE_FLAG +#error "The flag CMAKE_TRUE_FLAG was not set" +#endif + +#ifdef CMAKE_FALSE_FLAG +#error "The flag CMAKE_FALSE_FLAG was set" +#endif + +#ifndef CMAKE_TGT_EXISTS +#error "The flag CMAKE_TGT_EXISTS was not set" +#endif + +#ifdef CMAKE_TGT_NEXISTS +#error "The flag CMAKE_TGT_NEXISTS was set" +#endif + +#ifndef CMAKE_PROP1_OK +#error "The flag CMAKE_PROP1_OK was not set" +#endif + +#ifdef CMAKE_PROP1_ERROR +#error "The flag CMAKE_PROP1_ERROR was set" +#endif + +#ifndef CMAKE_PROP2_OK +#error "The flag CMAKE_PROP2_OK was not set" +#endif + +#ifdef CMAKE_PROP2_ERROR +#error "The flag CMAKE_PROP2_ERROR was set" +#endif + +class cmModClass { + private: + std::string str; + public: + cmModClass(std::string foo) { + str = foo + " World "; + str += CMAKE_COMPILER_DEFINE_STR; + } + + inline std::string getStr() const { return str; } +}; diff --git a/test cases/cmake/12 generator expressions/test.json b/test cases/cmake/12 generator expressions/test.json new file mode 100644 index 0000000..faf1ff8 --- /dev/null +++ b/test cases/cmake/12 generator expressions/test.json @@ -0,0 +1,5 @@ +{ + "tools": { + "cmake": ">=3.19" + } +} diff --git a/test cases/cmake/13 system includes/main.cpp b/test cases/cmake/13 system includes/main.cpp new file mode 100644 index 0000000..9507961 --- /dev/null +++ b/test cases/cmake/13 system includes/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/13 system includes/meson.build b/test cases/cmake/13 system includes/meson.build new file mode 100644 index 0000000..1265d46 --- /dev/null +++ b/test cases/cmake/13 system includes/meson.build @@ -0,0 +1,18 @@ +project( + 'meson_cmake_system_include_bug', ['c', 'cpp'], + default_options: [ + 'warning_level=3', + 'werror=true', + ], +) + +if meson.get_compiler('cpp').get_argument_syntax() == 'msvc' + error('MESON_SKIP_TEST: Skip with msvc due to missing -system support') +endif + +cm = import('cmake') +sub_pro = cm.subproject('cmMod') +sub_dep = sub_pro.dependency('cmModLib') + +exe1 = executable('main1', ['main.cpp'], dependencies: [sub_dep]) +test('test1', exe1) diff --git a/test cases/cmake/13 system includes/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/13 system includes/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..a6b0ba4 --- /dev/null +++ b/test cases/cmake/13 system includes/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,15 @@ +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) +include(GenerateExportHeader) +generate_export_header(cmModLib) + +target_compile_options(cmModLib PRIVATE "-Wall" "-Werror") +target_include_directories(cmModLib SYSTEM PRIVATE "sysInc") diff --git a/test cases/cmake/13 system includes/subprojects/cmMod/cmMod.cpp b/test cases/cmake/13 system includes/subprojects/cmMod/cmMod.cpp new file mode 100644 index 0000000..1eaf0cf --- /dev/null +++ b/test cases/cmake/13 system includes/subprojects/cmMod/cmMod.cpp @@ -0,0 +1,12 @@ +#include "cmMod.hpp" +#include "triggerWarn.hpp" + +using namespace std; + +cmModClass::cmModClass(string foo) { + str = foo + " World " + to_string(bar(World)); +} + +string cmModClass::getStr() const { + return str; +} diff --git a/test cases/cmake/13 system includes/subprojects/cmMod/cmMod.hpp b/test cases/cmake/13 system includes/subprojects/cmMod/cmMod.hpp new file mode 100644 index 0000000..52f576b --- /dev/null +++ b/test cases/cmake/13 system includes/subprojects/cmMod/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/13 system includes/subprojects/cmMod/sysInc/triggerWarn.hpp b/test cases/cmake/13 system includes/subprojects/cmMod/sysInc/triggerWarn.hpp new file mode 100644 index 0000000..3b00f2d --- /dev/null +++ b/test cases/cmake/13 system includes/subprojects/cmMod/sysInc/triggerWarn.hpp @@ -0,0 +1,14 @@ +#pragma once + +enum Foo { + Hello, + World +}; + +inline int bar( Foo foo ) { + switch(foo) { + case Hello: return 0; + // Warn because of missung case for World + } + return 1; +} diff --git a/test cases/cmake/14 fortran threads/meson.build b/test cases/cmake/14 fortran threads/meson.build new file mode 100644 index 0000000..2d2f892 --- /dev/null +++ b/test cases/cmake/14 fortran threads/meson.build @@ -0,0 +1,12 @@ +project('FortranThreads') + +if not add_languages('fortran', required: false) + error('MESON_SKIP_TEST: Fortran language not available.') +endif + +# want to be sure that CMake can find dependencies where even if the +# project isn't C, the C language is required to find the library. +threads = dependency('threads', method: 'cmake', required: false) +if not threads.found() + error('MESON_SKIP_TEST: CMake backend not working for Fortran / threads') +endif 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(); diff --git a/test cases/cmake/16 threads/main.cpp b/test cases/cmake/16 threads/main.cpp new file mode 100644 index 0000000..67ee110 --- /dev/null +++ b/test cases/cmake/16 threads/main.cpp @@ -0,0 +1,9 @@ +#include "cmMod.hpp" + +#include <cstdlib> + +int main() { + CmMod cc; + cc.asyncIncrement(); + return cc.getNum() == 1 ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test cases/cmake/16 threads/meson.build b/test cases/cmake/16 threads/meson.build new file mode 100644 index 0000000..5efd73e --- /dev/null +++ b/test cases/cmake/16 threads/meson.build @@ -0,0 +1,12 @@ +project('cmMod', ['c', 'cpp']) + +cm = import('cmake') +cmOpts = ['-DUSE_PTHREAD=@0@'.format(get_option('use_pthread'))] +cmMod = cm.subproject('cmMod', cmake_options: cmOpts) +cmModDep1 = cmMod.dependency('cmModLib') +cmModDep2 = cmMod.dependency('cmModLib_shared') + +exe1 = executable('exe1', ['main.cpp'], dependencies: [cmModDep1]) +exe2 = executable('exe2', ['main.cpp'], dependencies: [cmModDep2]) +test('exe1_OK', exe1) +test('exe2_OK', exe2) diff --git a/test cases/cmake/16 threads/meson_options.txt b/test cases/cmake/16 threads/meson_options.txt new file mode 100644 index 0000000..1fd9068 --- /dev/null +++ b/test cases/cmake/16 threads/meson_options.txt @@ -0,0 +1 @@ +option('use_pthread', type: 'combo', choices: ['ON', 'OFF', 'NOT_SET'], value: 'ON') diff --git a/test cases/cmake/16 threads/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/16 threads/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..4d61b0c --- /dev/null +++ b/test cases/cmake/16 threads/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod C CXX) +set (CMAKE_CXX_STANDARD 14) + +if(NOT USE_PTHREAD STREQUAL NOT_SET) + set(THREADS_PREFER_PTHREAD_FLAG ${USE_PTHREAD}) +endif() +find_package(Threads) + +add_library(cmModLib STATIC cmMod.cpp) +target_link_libraries(cmModLib PRIVATE Threads::Threads) + +add_library(cmModLib_shared SHARED cmMod.cpp) +target_link_libraries(cmModLib_shared PUBLIC Threads::Threads) diff --git a/test cases/cmake/16 threads/subprojects/cmMod/cmMod.cpp b/test cases/cmake/16 threads/subprojects/cmMod/cmMod.cpp new file mode 100644 index 0000000..f971eeb --- /dev/null +++ b/test cases/cmake/16 threads/subprojects/cmMod/cmMod.cpp @@ -0,0 +1,15 @@ +#include "cmMod.hpp" + +#include <chrono> +#include <thread> + +using namespace std::chrono_literals; + +void CmMod::asyncIncrement() { + std::thread t1([this]() { + std::this_thread::sleep_for(100ms); + num += 1; + }); + + t1.join(); +} diff --git a/test cases/cmake/16 threads/subprojects/cmMod/cmMod.hpp b/test cases/cmake/16 threads/subprojects/cmMod/cmMod.hpp new file mode 100644 index 0000000..81c5ec8 --- /dev/null +++ b/test cases/cmake/16 threads/subprojects/cmMod/cmMod.hpp @@ -0,0 +1,21 @@ +#pragma once + +#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 + +class DLL_PUBLIC CmMod { +private: + int num = 0; + +public: + inline int getNum() const { return num; } + void asyncIncrement(); +}; diff --git a/test cases/cmake/16 threads/subprojects/cmMod/main.cpp b/test cases/cmake/16 threads/subprojects/cmMod/main.cpp new file mode 100644 index 0000000..67ee110 --- /dev/null +++ b/test cases/cmake/16 threads/subprojects/cmMod/main.cpp @@ -0,0 +1,9 @@ +#include "cmMod.hpp" + +#include <cstdlib> + +int main() { + CmMod cc; + cc.asyncIncrement(); + return cc.getNum() == 1 ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test cases/cmake/16 threads/test.json b/test cases/cmake/16 threads/test.json new file mode 100644 index 0000000..db788b1 --- /dev/null +++ b/test cases/cmake/16 threads/test.json @@ -0,0 +1,11 @@ +{ + "matrix": { + "options": { + "use_pthread": [ + { "val": "ON" }, + { "val": "OFF" }, + { "val": "NOT_SET" } + ] + } + } +} diff --git a/test cases/cmake/17 include path order/main.cpp b/test cases/cmake/17 include path order/main.cpp new file mode 100644 index 0000000..9507961 --- /dev/null +++ b/test cases/cmake/17 include path order/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/17 include path order/meson.build b/test cases/cmake/17 include path order/meson.build new file mode 100644 index 0000000..cf3ec96 --- /dev/null +++ b/test cases/cmake/17 include path order/meson.build @@ -0,0 +1,9 @@ +project('include_path_order', ['c', 'cpp']) + +cm = import('cmake') + +sub_pro = cm.subproject('cmMod') +sub_dep = sub_pro.dependency('cmModLib++') + +exe1 = executable('main', ['main.cpp'], dependencies: [sub_dep]) +test('test1', exe1) diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/17 include path order/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..9a252df --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) +set (CMAKE_CXX_STANDARD 14) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + + # The one and only correct include dir + ${CMAKE_CURRENT_SOURCE_DIR}/incG + + # All of these are traps + ${CMAKE_CURRENT_SOURCE_DIR}/incL + ${CMAKE_CURRENT_SOURCE_DIR}/incM + ${CMAKE_CURRENT_SOURCE_DIR}/incO + ${CMAKE_CURRENT_SOURCE_DIR}/incF + ${CMAKE_CURRENT_SOURCE_DIR}/incI + ${CMAKE_CURRENT_SOURCE_DIR}/incE + ${CMAKE_CURRENT_SOURCE_DIR}/incD + ${CMAKE_CURRENT_SOURCE_DIR}/incH + ${CMAKE_CURRENT_SOURCE_DIR}/incN + ${CMAKE_CURRENT_SOURCE_DIR}/incA + ${CMAKE_CURRENT_SOURCE_DIR}/incB + ${CMAKE_CURRENT_SOURCE_DIR}/incJ + ${CMAKE_CURRENT_SOURCE_DIR}/incP + ${CMAKE_CURRENT_SOURCE_DIR}/incC + ${CMAKE_CURRENT_SOURCE_DIR}/incK +) + +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/17 include path order/subprojects/cmMod/cmMod.cpp b/test cases/cmake/17 include path order/subprojects/cmMod/cmMod.cpp new file mode 100644 index 0000000..d3141d5 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/cmMod.cpp @@ -0,0 +1,11 @@ +#include "cmMod.hpp" + +using namespace std; + +cmModClass::cmModClass(string foo) { + str = foo + " World"; +} + +string cmModClass::getStr() const { + return str; +} diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incA/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incA/cmMod.hpp new file mode 100644 index 0000000..6228a31 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incA/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (A) +#pragma once + +#error "cmMod.hpp in incA must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incB/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incB/cmMod.hpp new file mode 100644 index 0000000..60bf14c --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incB/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (B) +#pragma once + +#error "cmMod.hpp in incB must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incC/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incC/cmMod.hpp new file mode 100644 index 0000000..3229e07 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incC/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (C) +#pragma once + +#error "cmMod.hpp in incC must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incD/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incD/cmMod.hpp new file mode 100644 index 0000000..b958093 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incD/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (D) +#pragma once + +#error "cmMod.hpp in incD must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incE/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incE/cmMod.hpp new file mode 100644 index 0000000..aea5b6d --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incE/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (E) +#pragma once + +#error "cmMod.hpp in incE must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incF/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incF/cmMod.hpp new file mode 100644 index 0000000..1e1e2cb --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incF/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (F) +#pragma once + +#error "cmMod.hpp in incF must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incG/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incG/cmMod.hpp new file mode 100644 index 0000000..0e6dc04 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incG/cmMod.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "cmmodlib++_export.h" +#include <string> + +class CMMODLIB___EXPORT cmModClass { +private: + std::string str; + +public: + cmModClass(std::string foo); + + std::string getStr() const; +}; diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incH/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incH/cmMod.hpp new file mode 100644 index 0000000..263e701 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incH/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (H) +#pragma once + +#error "cmMod.hpp in incH must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incI/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incI/cmMod.hpp new file mode 100644 index 0000000..a44a89a --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incI/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (I) +#pragma once + +#error "cmMod.hpp in incI must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incJ/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incJ/cmMod.hpp new file mode 100644 index 0000000..118a809 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incJ/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (J) +#pragma once + +#error "cmMod.hpp in incJ must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incL/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incL/cmMod.hpp new file mode 100644 index 0000000..8294104 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incL/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (L) +#pragma once + +#error "cmMod.hpp in incL must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incM/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incM/cmMod.hpp new file mode 100644 index 0000000..031c5e9 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incM/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (M) +#pragma once + +#error "cmMod.hpp in incM must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incN/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incN/cmMod.hpp new file mode 100644 index 0000000..9dba6da --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incN/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (N) +#pragma once + +#error "cmMod.hpp in incN must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incO/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incO/cmMod.hpp new file mode 100644 index 0000000..233add9 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incO/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (O) +#pragma once + +#error "cmMod.hpp in incO must not be included" diff --git a/test cases/cmake/17 include path order/subprojects/cmMod/incP/cmMod.hpp b/test cases/cmake/17 include path order/subprojects/cmMod/incP/cmMod.hpp new file mode 100644 index 0000000..9578745 --- /dev/null +++ b/test cases/cmake/17 include path order/subprojects/cmMod/incP/cmMod.hpp @@ -0,0 +1,4 @@ +// cmMod.hpp (P) +#pragma once + +#error "cmMod.hpp in incP must not be included" diff --git a/test cases/cmake/18 skip include files/main.cpp b/test cases/cmake/18 skip include files/main.cpp new file mode 100644 index 0000000..9507961 --- /dev/null +++ b/test cases/cmake/18 skip include files/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/18 skip include files/meson.build b/test cases/cmake/18 skip include files/meson.build new file mode 100644 index 0000000..b9a300c --- /dev/null +++ b/test cases/cmake/18 skip include files/meson.build @@ -0,0 +1,9 @@ +project('cmakeSubTest', ['c', 'cpp']) + +cm = import('cmake') + +sub_pro = cm.subproject('cmMod') +sub_dep = sub_pro.dependency('cmModLib++') + +exe1 = executable('main', ['main.cpp'], dependencies: [sub_dep]) +test('test1', exe1) diff --git a/test cases/cmake/18 skip include files/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/18 skip include files/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..4db01b3 --- /dev/null +++ b/test cases/cmake/18 skip include files/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,15 @@ +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") + +set(SRCS + ${CMAKE_CURRENT_LIST_DIR}/cmMod.hpp + ${CMAKE_CURRENT_LIST_DIR}/cmMod.cpp +) + +add_subdirectory(fakeInc) diff --git a/test cases/cmake/18 skip include files/subprojects/cmMod/cmMod.cpp b/test cases/cmake/18 skip include files/subprojects/cmMod/cmMod.cpp new file mode 100644 index 0000000..7551b75 --- /dev/null +++ b/test cases/cmake/18 skip include files/subprojects/cmMod/cmMod.cpp @@ -0,0 +1,10 @@ +#include "cmMod.hpp" + +using namespace std; + +#define MESON_INCLUDE_IMPL +#include "fakeInc/cmModInc1.cpp" +#include "fakeInc/cmModInc2.cpp" +#include "fakeInc/cmModInc3.cpp" +#include "fakeInc/cmModInc4.cpp" +#undef MESON_INCLUDE_IMPL diff --git a/test cases/cmake/18 skip include files/subprojects/cmMod/cmMod.hpp b/test cases/cmake/18 skip include files/subprojects/cmMod/cmMod.hpp new file mode 100644 index 0000000..f7b780f --- /dev/null +++ b/test cases/cmake/18 skip include files/subprojects/cmMod/cmMod.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "cmmodlib++_export.h" +#include <string> + +class CMMODLIB___EXPORT cmModClass { +private: + std::string str; + + std::string getStr1() const; + std::string getStr2() const; +public: + cmModClass(std::string foo); + + std::string getStr() const; +}; diff --git a/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/CMakeLists.txt b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/CMakeLists.txt new file mode 100644 index 0000000..39cd080 --- /dev/null +++ b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/CMakeLists.txt @@ -0,0 +1,30 @@ +list(APPEND SRCS + cmModInc1.cpp + cmModInc2.cpp + cmModInc3.cpp + cmModInc4.cpp +) + +set(SRC_A + cmModInc1.cpp + ${CMAKE_CURRENT_LIST_DIR}/cmModInc2.cpp +) + +set_property( + SOURCE ${SRC_A} + PROPERTY + HEADER_FILE_ONLY ON +) + +set_source_files_properties( + cmModInc3.cpp + ${CMAKE_CURRENT_LIST_DIR}/cmModInc4.cpp + PROPERTIES + LABELS "CMake;Lists;are;fun" + HEADER_FILE_ONLY ON +) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +add_library(cmModLib++ SHARED ${SRCS}) +include(GenerateExportHeader) +generate_export_header(cmModLib++) diff --git a/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc1.cpp b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc1.cpp new file mode 100644 index 0000000..b637755 --- /dev/null +++ b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc1.cpp @@ -0,0 +1,7 @@ +#ifndef MESON_INCLUDE_IMPL +#error "MESON_INCLUDE_IMPL is not defined" +#endif // !MESON_INCLUDE_IMPL + +cmModClass::cmModClass(string foo) { + str = foo + " World"; +} diff --git a/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc2.cpp b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc2.cpp new file mode 100644 index 0000000..8a53567 --- /dev/null +++ b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc2.cpp @@ -0,0 +1,7 @@ +#ifndef MESON_INCLUDE_IMPL +#error "MESON_INCLUDE_IMPL is not defined" +#endif // !MESON_INCLUDE_IMPL + +string cmModClass::getStr() const { + return getStr2(); +} diff --git a/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc3.cpp b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc3.cpp new file mode 100644 index 0000000..2c8ad12 --- /dev/null +++ b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc3.cpp @@ -0,0 +1,7 @@ +#ifndef MESON_INCLUDE_IMPL +#error "MESON_INCLUDE_IMPL is not defined" +#endif // !MESON_INCLUDE_IMPL + +string cmModClass::getStr1() const { + return getStr2(); +} diff --git a/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc4.cpp b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc4.cpp new file mode 100644 index 0000000..78a0673 --- /dev/null +++ b/test cases/cmake/18 skip include files/subprojects/cmMod/fakeInc/cmModInc4.cpp @@ -0,0 +1,7 @@ +#ifndef MESON_INCLUDE_IMPL +#error "MESON_INCLUDE_IMPL is not defined" +#endif // !MESON_INCLUDE_IMPL + +string cmModClass::getStr2() const { + return str; +} diff --git a/test cases/cmake/19 advanced options/main.cpp b/test cases/cmake/19 advanced options/main.cpp new file mode 100644 index 0000000..6a071cc --- /dev/null +++ b/test cases/cmake/19 advanced options/main.cpp @@ -0,0 +1,18 @@ +#include <iostream> +#include <cmMod.hpp> +#include <cmTest.hpp> + +using namespace std; + +int main(void) { + cmModClass obj("Hello"); + cout << obj.getStr() << endl; + + int v1 = obj.getInt(); + int v2 = getTestInt(); + if (v1 != ((1 + v2) * 2)) { + cerr << "Number test failed" << endl; + return 1; + } + return 0; +} diff --git a/test cases/cmake/19 advanced options/meson.build b/test cases/cmake/19 advanced options/meson.build new file mode 100644 index 0000000..6332ca4 --- /dev/null +++ b/test cases/cmake/19 advanced options/meson.build @@ -0,0 +1,29 @@ +project('cmake_set_opt', ['c', 'cpp']) + +comp = meson.get_compiler('cpp') +if comp.get_argument_syntax() == 'msvc' + error('MESON_SKIP_TEST: MSVC is not supported because it does not support C++11') +endif + +cm = import('cmake') +opts = cm.subproject_options() + +opts.add_cmake_defines({'SOME_CMAKE_VAR': 'something', 'SOME_OTHER_VAR': true}) + +opts.set_override_option('cpp_std', 'c++11') # Global is C++11 +opts.set_override_option('cpp_std', 'c++14', target: 'cmModLib++') # Override it with C++14 for cmModLib++ + +opts.append_compile_args('cpp', '-DMESON_GLOBAL_FLAG=1') +opts.append_compile_args('cpp', ['-DMESON_SPECIAL_FLAG1=1', ['-DMESON_SPECIAL_FLAG2=1']], target: 'cmModLib++') +opts.append_compile_args('cpp', '-DMESON_MAGIC_INT=42', target: 'cmModLib++') +opts.append_compile_args('cpp', [[[['-DMESON_MAGIC_INT=20']]]], target: 'cmTestLib') + +opts.set_install(false) +opts.set_install(true, target: 'testEXE') + +sp = cm.subproject('cmOpts', options: opts) +dep1 = sp.dependency('cmModLib++') +dep2 = sp.dependency('cmTestLib') + +exe1 = executable('main', ['main.cpp'], dependencies: [dep1, dep2]) +test('test1', exe1) diff --git a/test cases/cmake/19 advanced options/subprojects/cmOpts/CMakeLists.txt b/test cases/cmake/19 advanced options/subprojects/cmOpts/CMakeLists.txt new file mode 100644 index 0000000..584841e --- /dev/null +++ b/test cases/cmake/19 advanced options/subprojects/cmOpts/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.7) + +project(CmOpts) + +set(CMAKE_CXX_STANDARD 98) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(NOT "${SOME_CMAKE_VAR}" STREQUAL "something") + message(FATAL_ERROR "Setting the CMake var failed") +endif() + +add_library(cmModLib++ STATIC cmMod.cpp) +add_library(cmTestLib STATIC cmTest.cpp) +add_executable(testEXE main.cpp) + +target_link_libraries(testEXE cmModLib++) + +install(TARGETS cmTestLib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) diff --git a/test cases/cmake/19 advanced options/subprojects/cmOpts/cmMod.cpp b/test cases/cmake/19 advanced options/subprojects/cmOpts/cmMod.cpp new file mode 100644 index 0000000..7651b60 --- /dev/null +++ b/test cases/cmake/19 advanced options/subprojects/cmOpts/cmMod.cpp @@ -0,0 +1,31 @@ +#include "cmMod.hpp" + +using namespace std; + +#if __cplusplus < 201402L +#error "At least C++14 is required" +#endif + +#ifndef MESON_GLOBAL_FLAG +#error "MESON_GLOBAL_FLAG was not set" +#endif + +#ifndef MESON_SPECIAL_FLAG1 +#error "MESON_SPECIAL_FLAG1 was not set" +#endif + +#ifndef MESON_SPECIAL_FLAG2 +#error "MESON_SPECIAL_FLAG2 was not set" +#endif + +cmModClass::cmModClass(string foo) { + str = foo + " World"; +} + +string cmModClass::getStr() const { + return str; +} + +int cmModClass::getInt() const { + return MESON_MAGIC_INT; +} diff --git a/test cases/cmake/19 advanced options/subprojects/cmOpts/cmMod.hpp b/test cases/cmake/19 advanced options/subprojects/cmOpts/cmMod.hpp new file mode 100644 index 0000000..0748936 --- /dev/null +++ b/test cases/cmake/19 advanced options/subprojects/cmOpts/cmMod.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include <string> + +class cmModClass { +private: + std::string str; + +public: + cmModClass(std::string foo); + + std::string getStr() const; + int getInt() const; +}; diff --git a/test cases/cmake/19 advanced options/subprojects/cmOpts/cmTest.cpp b/test cases/cmake/19 advanced options/subprojects/cmOpts/cmTest.cpp new file mode 100644 index 0000000..a00cdcd --- /dev/null +++ b/test cases/cmake/19 advanced options/subprojects/cmOpts/cmTest.cpp @@ -0,0 +1,25 @@ +#include "cmTest.hpp" + +#if __cplusplus < 201103L +#error "At least C++11 is required" +#endif + +#if __cplusplus >= 201402L +#error "At most C++11 is required" +#endif + +#ifndef MESON_GLOBAL_FLAG +#error "MESON_GLOBAL_FLAG was not set" +#endif + +#ifdef MESON_SPECIAL_FLAG1 +#error "MESON_SPECIAL_FLAG1 *was* set" +#endif + +#ifdef MESON_SPECIAL_FLAG2 +#error "MESON_SPECIAL_FLAG2 *was* set" +#endif + +int getTestInt() { + return MESON_MAGIC_INT; +} diff --git a/test cases/cmake/19 advanced options/subprojects/cmOpts/cmTest.hpp b/test cases/cmake/19 advanced options/subprojects/cmOpts/cmTest.hpp new file mode 100644 index 0000000..5a3bf7b --- /dev/null +++ b/test cases/cmake/19 advanced options/subprojects/cmOpts/cmTest.hpp @@ -0,0 +1,3 @@ +#pragma once + +int getTestInt(); diff --git a/test cases/cmake/19 advanced options/subprojects/cmOpts/main.cpp b/test cases/cmake/19 advanced options/subprojects/cmOpts/main.cpp new file mode 100644 index 0000000..497d1ce --- /dev/null +++ b/test cases/cmake/19 advanced options/subprojects/cmOpts/main.cpp @@ -0,0 +1,10 @@ +#include <iostream> +#include "cmMod.hpp" + +using namespace std; + +int main(void) { + cmModClass obj("Hello (LIB TEST)"); + cout << obj.getStr() << endl; + return 0; +} diff --git a/test cases/cmake/19 advanced options/test.json b/test cases/cmake/19 advanced options/test.json new file mode 100644 index 0000000..29888ea --- /dev/null +++ b/test cases/cmake/19 advanced options/test.json @@ -0,0 +1,5 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/testEXE"} + ] +} 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"} + ] +} diff --git a/test cases/cmake/20 cmake file/foolib.cmake.in b/test cases/cmake/20 cmake file/foolib.cmake.in new file mode 100644 index 0000000..16e992b --- /dev/null +++ b/test cases/cmake/20 cmake file/foolib.cmake.in @@ -0,0 +1 @@ +@foo@ diff --git a/test cases/cmake/20 cmake file/meson.build b/test cases/cmake/20 cmake file/meson.build new file mode 100644 index 0000000..5c45d66 --- /dev/null +++ b/test cases/cmake/20 cmake file/meson.build @@ -0,0 +1,12 @@ +project( + 'cmake config file', +) + +cmake = import('cmake') + +cmake.configure_package_config_file( + name : 'foolib', + input : 'foolib.cmake.in', + install_dir : get_option('libdir') / 'cmake', + configuration : {'foo': '"bar"'}, +) diff --git a/test cases/cmake/20 cmake file/test.json b/test cases/cmake/20 cmake file/test.json new file mode 100644 index 0000000..a8c4ba3 --- /dev/null +++ b/test cases/cmake/20 cmake file/test.json @@ -0,0 +1,5 @@ +{ + "installed": [ + {"file": "usr/lib/cmake/foolibConfig.cmake", "type": "file"} + ] +} diff --git a/test cases/cmake/21 shared module/meson.build b/test cases/cmake/21 shared module/meson.build new file mode 100644 index 0000000..c6ff957 --- /dev/null +++ b/test cases/cmake/21 shared module/meson.build @@ -0,0 +1,13 @@ +project('cmakeSharedModule', ['c', 'cpp']) + +cm = import('cmake') + +sub_pro = cm.subproject('cmMod') +sub_dep = sub_pro.dependency('myMod') + +dl = meson.get_compiler('c').find_library('dl', required: false) + +l = shared_library('runtime', 'runtime.c') +e = executable('prog', ['prog.c'], link_with: l, dependencies: [sub_dep, dl]) +m = sub_pro.target('myMod') +test('test1', e, args : m) diff --git a/test cases/cmake/21 shared module/prog.c b/test cases/cmake/21 shared module/prog.c new file mode 100644 index 0000000..228a976 --- /dev/null +++ b/test cases/cmake/21 shared module/prog.c @@ -0,0 +1,108 @@ + +#include <stdio.h> +#include "module.h" + +#if SPECIAL_MAGIC_DEFINE != 42 +#error "SPECIAL_MAGIC_DEFINE is not defined" +#endif + +int func_from_language_runtime(void); +typedef int (*fptr) (void); + +#ifdef _WIN32 + +#include <windows.h> + +static wchar_t* +win32_get_last_error (void) +{ + wchar_t *msg = NULL; + + FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER + | FORMAT_MESSAGE_IGNORE_INSERTS + | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, GetLastError (), 0, + (LPWSTR) &msg, 0, NULL); + return msg; +} + +int main(int argc, char **argv) +{ + HINSTANCE handle; + fptr importedfunc; + int expected, actual; + int ret = 1; + if(argc==0) {}; + + handle = LoadLibraryA (argv[1]); + if (!handle) { + wchar_t *msg = win32_get_last_error (); + printf ("Could not open %s: %S\n", argv[1], msg); + goto nohandle; + } + + importedfunc = (fptr) GetProcAddress (handle, "func"); + if (importedfunc == NULL) { + wchar_t *msg = win32_get_last_error (); + printf ("Could not find 'func': %S\n", msg); + goto out; + } + + actual = importedfunc (); + expected = func_from_language_runtime (); + if (actual != expected) { + printf ("Got %i instead of %i\n", actual, expected); + goto out; + } + + ret = 0; +out: + FreeLibrary (handle); +nohandle: + return ret; +} + +#else + +#include<dlfcn.h> +#include<assert.h> + +int main(int argc, char **argv) { + void *dl; + fptr importedfunc; + int expected, actual; + char *error; + int ret = 1; + if(argc==0) {}; + + dlerror(); + dl = dlopen(argv[1], RTLD_LAZY); + error = dlerror(); + if(error) { + printf("Could not open %s: %s\n", argv[1], error); + goto nodl; + } + + importedfunc = (fptr) dlsym(dl, "func"); + if (importedfunc == NULL) { + printf ("Could not find 'func'\n"); + goto out; + } + + assert(importedfunc != func_from_language_runtime); + + actual = (*importedfunc)(); + expected = func_from_language_runtime (); + if (actual != expected) { + printf ("Got %i instead of %i\n", actual, expected); + goto out; + } + + ret = 0; +out: + dlclose(dl); +nodl: + return ret; +} + +#endif diff --git a/test cases/cmake/21 shared module/runtime.c b/test cases/cmake/21 shared module/runtime.c new file mode 100644 index 0000000..03bde86 --- /dev/null +++ b/test cases/cmake/21 shared module/runtime.c @@ -0,0 +1,19 @@ +#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 + +/* + * This file pretends to be a language runtime that supports extension + * modules. + */ + +int DLL_PUBLIC func_from_language_runtime(void) { + return 86; +} diff --git a/test cases/cmake/21 shared module/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/21 shared module/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..d2fcfe3 --- /dev/null +++ b/test cases/cmake/21 shared module/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmModule) + +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/module") + +add_library(myMod MODULE "${CMAKE_CURRENT_SOURCE_DIR}/module/module.c") diff --git a/test cases/cmake/21 shared module/subprojects/cmMod/module/module.c b/test cases/cmake/21 shared module/subprojects/cmMod/module/module.c new file mode 100644 index 0000000..5dd26d7 --- /dev/null +++ b/test cases/cmake/21 shared module/subprojects/cmMod/module/module.c @@ -0,0 +1,96 @@ +#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 + +#if defined(_WIN32) || defined(__CYGWIN__) + +#include <stdio.h> + +typedef int (*fptr) (void); + +#ifdef __CYGWIN__ + +#include <dlfcn.h> + +fptr find_any_f (const char *name) { + return (fptr) dlsym(RTLD_DEFAULT, name); +} +#else /* _WIN32 */ + +#include <windows.h> +#include <tlhelp32.h> + +static wchar_t* +win32_get_last_error (void) +{ + wchar_t *msg = NULL; + + FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER + | FORMAT_MESSAGE_IGNORE_INSERTS + | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, GetLastError (), 0, + (LPWSTR) &msg, 0, NULL); + return msg; +} + +/* Unlike Linux and OS X, when a library is loaded, all the symbols aren't + * loaded into a single namespace. You must fetch the symbol by iterating over + * all loaded modules. Code for finding the function from any of the loaded + * modules is taken from gmodule.c in glib */ +fptr find_any_f (const char *name) { + fptr f; + HANDLE snapshot; + MODULEENTRY32 me32; + + snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, 0); + if (snapshot == (HANDLE) -1) { + wchar_t *msg = win32_get_last_error(); + printf("Could not get snapshot: %S\n", msg); + return 0; + } + + me32.dwSize = sizeof (me32); + + f = NULL; + if (Module32First (snapshot, &me32)) { + do { + if ((f = (fptr) GetProcAddress (me32.hModule, name)) != NULL) + break; + } while (Module32Next (snapshot, &me32)); + } + + CloseHandle (snapshot); + return f; +} +#endif + +int DLL_PUBLIC func(void) { + fptr f; + + f = find_any_f ("func_from_language_runtime"); + if (f != NULL) + return f(); + printf ("Could not find function\n"); + return 1; +} + +#else +/* + * Shared modules often have references to symbols that are not defined + * at link time, but which will be provided from deps of the executable that + * dlopens it. We need to make sure that this works, i.e. that we do + * not pass -Wl,--no-undefined when linking modules. + */ +int func_from_language_runtime(void); + +int DLL_PUBLIC func(void) { + return func_from_language_runtime(); +} +#endif diff --git a/test cases/cmake/21 shared module/subprojects/cmMod/module/module.h b/test cases/cmake/21 shared module/subprojects/cmMod/module/module.h new file mode 100644 index 0000000..e1d9c13 --- /dev/null +++ b/test cases/cmake/21 shared module/subprojects/cmMod/module/module.h @@ -0,0 +1,3 @@ +#pragma once + +#define SPECIAL_MAGIC_DEFINE 42 diff --git a/test cases/cmake/22 cmake module/cmake_project/CMakeLists.txt b/test cases/cmake/22 cmake module/cmake_project/CMakeLists.txt new file mode 100644 index 0000000..cd91584 --- /dev/null +++ b/test cases/cmake/22 cmake module/cmake_project/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8) +project(cmakeMeson C) + +find_package(cmakeModule REQUIRED)
\ No newline at end of file diff --git a/test cases/cmake/22 cmake module/meson.build b/test cases/cmake/22 cmake module/meson.build new file mode 100644 index 0000000..68f9993 --- /dev/null +++ b/test cases/cmake/22 cmake module/meson.build @@ -0,0 +1,31 @@ +project('cmakeModule', 'c', version: '1.0.0') + +if build_machine.system() == 'cygwin' + error('MESON_SKIP_TEST CMake is broken on Cygwin.') +endif + +cmake_bin = find_program('cmake', required: false) +if not cmake_bin.found() + error('MESON_SKIP_TEST CMake not installed.') +endif + +cc = meson.get_compiler('c') +if cc.get_id() == 'clang-cl' and meson.backend() == 'ninja' and build_machine.system() == 'windows' + error('MESON_SKIP_TEST CMake installation nor operational for vs2017 clangclx64ninja') +endif + +cmake = import('cmake') + +cmake.write_basic_package_version_file(version: '0.0.1', + name: 'cmakeModule', +) + +conf = configuration_data() +conf.set('MYVAR', 'my variable value') +conf.set_quoted('MYQUOTEDVAR', 'my quoted variable value') + +cmake.configure_package_config_file( + input: 'projectConfig.cmake.in', + name: 'cmakeModule', + configuration: conf, +) diff --git a/test cases/cmake/22 cmake module/projectConfig.cmake.in b/test cases/cmake/22 cmake module/projectConfig.cmake.in new file mode 100644 index 0000000..fa3dfca --- /dev/null +++ b/test cases/cmake/22 cmake module/projectConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +set(MYVAR "@MYVAR@") +set(MYQUOTEDVAR @MYQUOTEDVAR@) diff --git a/test cases/cmake/22 cmake module/test.json b/test cases/cmake/22 cmake module/test.json new file mode 100644 index 0000000..2a5625a --- /dev/null +++ b/test cases/cmake/22 cmake module/test.json @@ -0,0 +1,6 @@ +{ + "installed": [ + {"type": "file", "file": "usr/lib/cmake/cmakeModule/cmakeModuleConfig.cmake"}, + {"type": "file", "file": "usr/lib/cmake/cmakeModule/cmakeModuleConfigVersion.cmake"} + ] +} diff --git a/test cases/cmake/23 cmake toolchain/CMakeToolchain.cmake b/test cases/cmake/23 cmake toolchain/CMakeToolchain.cmake new file mode 100644 index 0000000..ab5fbac --- /dev/null +++ b/test cases/cmake/23 cmake toolchain/CMakeToolchain.cmake @@ -0,0 +1 @@ +set(MESON_TEST_VAR2 VAR2) diff --git a/test cases/cmake/23 cmake toolchain/meson.build b/test cases/cmake/23 cmake toolchain/meson.build new file mode 100644 index 0000000..8399597 --- /dev/null +++ b/test cases/cmake/23 cmake toolchain/meson.build @@ -0,0 +1,13 @@ +project('cmake toolchain test', ['c']) + +if meson.is_cross_build() + error('MESON_SKIP_TEST: skip this on cross builds') +endif + +cm = import('cmake') + +sub_pro = cm.subproject('cmMod') + +add_languages('cpp') + +sub_pro = cm.subproject('cmModFortran') diff --git a/test cases/cmake/23 cmake toolchain/nativefile.ini.in b/test cases/cmake/23 cmake toolchain/nativefile.ini.in new file mode 100644 index 0000000..1f4037d --- /dev/null +++ b/test cases/cmake/23 cmake toolchain/nativefile.ini.in @@ -0,0 +1,9 @@ +[properties] + +cmake_toolchain_file = '@MESON_TEST_ROOT@/CMakeToolchain.cmake' +cmake_skip_compiler_test = 'always' + +[cmake] + +MESON_TEST_VAR1 = 'VAR1 space' +MESON_TEST_VAR2 = 'VAR2 error' diff --git a/test cases/cmake/23 cmake toolchain/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/23 cmake toolchain/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..a00affa --- /dev/null +++ b/test cases/cmake/23 cmake toolchain/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod NONE) + +if(NOT "${MESON_TEST_VAR1}" STREQUAL "VAR1 space") + message(FATAL_ERROR "MESON_TEST_VAR1 -- '${MESON_TEST_VAR1}' != 'VAR1 space'") +endif() + +if(NOT "${MESON_TEST_VAR2}" STREQUAL "VAR2") + message(FATAL_ERROR "MESON_TEST_VAR2 -- '${MESON_TEST_VAR2}' != 'VAR2'") +endif() + +if(NOT DEFINED CMAKE_C_COMPILER_VERSION) + message(FATAL_ERROR "CMAKE_C_COMPILER_VERSION was not defined") +endif() diff --git a/test cases/cmake/23 cmake toolchain/subprojects/cmModFortran/CMakeLists.txt b/test cases/cmake/23 cmake toolchain/subprojects/cmModFortran/CMakeLists.txt new file mode 100644 index 0000000..ecf1737 --- /dev/null +++ b/test cases/cmake/23 cmake toolchain/subprojects/cmModFortran/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod NONE) + +if(NOT "${MESON_TEST_VAR1}" STREQUAL "VAR1 space") + message(FATAL_ERROR "MESON_TEST_VAR1 -- '${MESON_TEST_VAR1}' != 'VAR1 space'") +endif() + +if(NOT "${MESON_TEST_VAR2}" STREQUAL "VAR2") + message(FATAL_ERROR "MESON_TEST_VAR2 -- '${MESON_TEST_VAR2}' != 'VAR2'") +endif() + +if(NOT DEFINED CMAKE_C_COMPILER_VERSION) + message(FATAL_ERROR "CMAKE_C_COMPILER_VERSION was not defined") +endif() + +if(NOT DEFINED CMAKE_CXX_COMPILER_VERSION) + message(FATAL_ERROR "CMAKE_CXX_COMPILER_VERSION was not defined") +endif() diff --git a/test cases/cmake/24 mixing languages/main.c b/test cases/cmake/24 mixing languages/main.c new file mode 100644 index 0000000..028a78e --- /dev/null +++ b/test cases/cmake/24 mixing languages/main.c @@ -0,0 +1,5 @@ +#include <cmTest.h> + +int main(void) { + return doStuff(); +} diff --git a/test cases/cmake/24 mixing languages/meson.build b/test cases/cmake/24 mixing languages/meson.build new file mode 100644 index 0000000..4ab1d85 --- /dev/null +++ b/test cases/cmake/24 mixing languages/meson.build @@ -0,0 +1,13 @@ +project('CMake mix', ['c', 'cpp']) + +if not add_languages('objc', required : false) + error('MESON_SKIP_TEST: No ObjC compiler') +endif + +cm = import('cmake') + +sub_pro = cm.subproject('cmTest') +sub_dep = sub_pro.dependency('cmTest', include_type: 'system') + +exe1 = executable('exe1', ['main.c'], dependencies: [sub_dep]) +test('test1', exe1) diff --git a/test cases/cmake/24 mixing languages/subprojects/cmTest/CMakeLists.txt b/test cases/cmake/24 mixing languages/subprojects/cmTest/CMakeLists.txt new file mode 100644 index 0000000..80a256f --- /dev/null +++ b/test cases/cmake/24 mixing languages/subprojects/cmTest/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmTest) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +add_library(cmTest STATIC cmTest.c cmTest.m) +target_compile_definitions(cmTest PUBLIC SOME_MAGIC_DEFINE=42) diff --git a/test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.c b/test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.c new file mode 100644 index 0000000..066d676 --- /dev/null +++ b/test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.c @@ -0,0 +1,13 @@ +#include "cmTest.h" +#include <stdio.h> + +#if SOME_MAGIC_DEFINE != 42 +#error "SOME_MAGIC_DEFINE != 42" +#endif + +int foo(int x); + +int doStuff(void) { + printf("Hello World\n"); + return foo(42); +} diff --git a/test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.h b/test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.h new file mode 100644 index 0000000..a6a5c24 --- /dev/null +++ b/test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.h @@ -0,0 +1,3 @@ +#pragma once + +int doStuff(void); diff --git a/test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.m b/test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.m new file mode 100644 index 0000000..16ec805 --- /dev/null +++ b/test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.m @@ -0,0 +1,7 @@ +#if SOME_MAGIC_DEFINE != 42 +#error "SOME_MAGIC_DEFINE != 42" +#endif + +int foo(int x) { + return 42 - x; +} diff --git a/test cases/cmake/25 assembler/main.c b/test cases/cmake/25 assembler/main.c new file mode 100644 index 0000000..5aef967 --- /dev/null +++ b/test cases/cmake/25 assembler/main.c @@ -0,0 +1,18 @@ +#include <stdint.h> +#include <stdio.h> + +int32_t cmTestFunc(void); + +int main(void) +{ + if (cmTestFunc() > 4200) + { + printf("Test success.\n"); + return 0; + } + else + { + printf("Test failure.\n"); + return 1; + } +} diff --git a/test cases/cmake/25 assembler/meson.build b/test cases/cmake/25 assembler/meson.build new file mode 100644 index 0000000..7180356 --- /dev/null +++ b/test cases/cmake/25 assembler/meson.build @@ -0,0 +1,9 @@ +project('assembler test', ['c', 'cpp']) + +cm = import('cmake') + +sub_pro = cm.subproject('cmTest') +sub_dep = sub_pro.dependency('cmTest') + +exe1 = executable('exe1', ['main.c'], dependencies: [sub_dep]) +test('test1', exe1) diff --git a/test cases/cmake/25 assembler/subprojects/cmTest/CMakeLists.txt b/test cases/cmake/25 assembler/subprojects/cmTest/CMakeLists.txt new file mode 100644 index 0000000..bb8834d --- /dev/null +++ b/test cases/cmake/25 assembler/subprojects/cmTest/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmTest) + +#Detect processor +if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "amd64") + SET(TEST_PROCESSOR "x86_64") +elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64") + SET(TEST_PROCESSOR "x86_64") +elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i386") + SET(TEST_PROCESSOR "x86") +elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i686") + SET(TEST_PROCESSOR "x86") +elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm") + SET(TEST_PROCESSOR "arm") +elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64") + SET(TEST_PROCESSOR "arm") +else () + message(FATAL_ERROR "MESON_SKIP_TEST: Unsupported Assembler Platform") +endif () + +#Detect ABI +if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + SET(TEST_ABI "sysv") +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD") + SET(TEST_ABI "sysv") +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "NetBSD") + SET(TEST_ABI "sysv") +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD") + SET(TEST_ABI "sysv") +else () + message(FATAL_ERROR "MESON_SKIP_TEST: Unsupported Assembler Platform") +endif () + +SET(TEST_PLATFORM "${TEST_PROCESSOR}-${TEST_ABI}") + +if ( ("${TEST_PLATFORM}" MATCHES "x86_64-sysv") + OR ("${TEST_PLATFORM}" MATCHES "x86-sysv") + OR ("${TEST_PLATFORM}" MATCHES "arm-sysv")) + SET(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) + enable_language(ASM) + SET(TEST_SOURCE "cmTestAsm.s") +endif () + +add_library(cmTest STATIC cmTest.c ${TEST_SOURCE}) diff --git a/test cases/cmake/25 assembler/subprojects/cmTest/cmTest.c b/test cases/cmake/25 assembler/subprojects/cmTest/cmTest.c new file mode 100644 index 0000000..e32415c --- /dev/null +++ b/test cases/cmake/25 assembler/subprojects/cmTest/cmTest.c @@ -0,0 +1,8 @@ +#include <stdint.h> + +extern const int32_t cmTestArea; + +int32_t cmTestFunc(void) +{ + return cmTestArea; +} diff --git a/test cases/cmake/25 assembler/subprojects/cmTest/cmTestAsm.s b/test cases/cmake/25 assembler/subprojects/cmTest/cmTestAsm.s new file mode 100644 index 0000000..8aa83a6 --- /dev/null +++ b/test cases/cmake/25 assembler/subprojects/cmTest/cmTestAsm.s @@ -0,0 +1,4 @@ +.text +.globl cmTestArea +cmTestArea: + .long 4242 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 0000000..d823e29 --- /dev/null +++ b/test cases/cmake/3 advanced no dep/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/3 advanced no dep/meson.build b/test cases/cmake/3 advanced no dep/meson.build new file mode 100644 index 0000000..f8f1836 --- /dev/null +++ b/test cases/cmake/3 advanced no dep/meson.build @@ -0,0 +1,19 @@ +project('cmakeSubTest_advanced', ['c', 'cpp']) + +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('meson-testEXE') == 'executable', 'The type must be executable for obvious reasons') +test('test3', sub_pro.target('meson-testEXE')) +test('test4', sub_pro.target('benchmark')) 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 0000000..d738d45 --- /dev/null +++ b/test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) +set(CMAKE_CXX_STANDARD 14) + +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(meson-testEXE main.cpp) +add_executable(benchmark main.cpp) + +target_link_libraries(meson-testEXE cmModLib) +target_link_libraries(benchmark cmModLib) + +target_compile_definitions(cmModLibStatic PUBLIC CMMODLIB_STATIC_DEFINE) + +install(TARGETS meson-testEXE benchmark 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 0000000..f538ac9 --- /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 0000000..741e8df --- /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 0000000..52f576b --- /dev/null +++ b/test cases/cmake/3 advanced no dep/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/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 0000000..d3e67ca --- /dev/null +++ b/test cases/cmake/3 advanced no dep/subprojects/cmMod/main.cpp @@ -0,0 +1,10 @@ +#include <iostream> +#include "lib/cmMod.hpp" + +using namespace std; + +int main(void) { + cmModClass obj("Hello (LIB TEST)"); + cout << obj.getStr() << endl; + return 0; +} diff --git a/test cases/cmake/3 advanced no dep/test.json b/test cases/cmake/3 advanced no dep/test.json new file mode 100644 index 0000000..e75e54a --- /dev/null +++ b/test cases/cmake/3 advanced no dep/test.json @@ -0,0 +1,8 @@ +{ + "installed": [ + {"type": "pdb", "file": "usr/bin/cm_meson_testEXE"}, + {"type": "exe", "file": "usr/bin/cm_meson_testEXE"}, + {"type": "pdb", "file": "usr/bin/cm_benchmark"}, + {"type": "exe", "file": "usr/bin/cm_benchmark"} + ] +} diff --git a/test cases/cmake/4 code gen/main.cpp b/test cases/cmake/4 code gen/main.cpp new file mode 100644 index 0000000..a41204b --- /dev/null +++ b/test cases/cmake/4 code gen/main.cpp @@ -0,0 +1,8 @@ +#include <iostream> +#include "test.hpp" + +using namespace std; + +int main(void) { + cout << getStr() << endl; +} diff --git a/test cases/cmake/4 code gen/meson.build b/test cases/cmake/4 code gen/meson.build new file mode 100644 index 0000000..80c801f --- /dev/null +++ b/test cases/cmake/4 code gen/meson.build @@ -0,0 +1,24 @@ +project('cmake_code_gen', ['c', 'cpp']) + +if meson.is_cross_build() + error('MESON_SKIP_TEST this test does not cross compile correctly.') +endif + +cm = import('cmake') + +# Subproject with the "code generator" +sub_pro = cm.subproject('cmCodeGen') +sub_exe = sub_pro.target('genA') + +# Generate the source +generated = custom_target( + 'cmake-generated', + input: [], + output: ['test.cpp'], + command: [sub_exe, '@OUTPUT@'] +) + +# Build the exe +exe1 = executable('main1', ['main.cpp', generated]) + +test('test1', exe1) diff --git a/test cases/cmake/4 code gen/subprojects/cmCodeGen/CMakeLists.txt b/test cases/cmake/4 code gen/subprojects/cmCodeGen/CMakeLists.txt new file mode 100644 index 0000000..ff50e54 --- /dev/null +++ b/test cases/cmake/4 code gen/subprojects/cmCodeGen/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.7) + +project(CMCodeGen) +set(CMAKE_CXX_STANDARD 14) + +add_executable(genA main.cpp) diff --git a/test cases/cmake/4 code gen/subprojects/cmCodeGen/main.cpp b/test cases/cmake/4 code gen/subprojects/cmCodeGen/main.cpp new file mode 100644 index 0000000..5b7fed2 --- /dev/null +++ b/test cases/cmake/4 code gen/subprojects/cmCodeGen/main.cpp @@ -0,0 +1,21 @@ +#include <iostream> +#include <fstream> + +using namespace std; + +int main(int argc, const char *argv[]) { + if(argc < 2) { + cerr << argv[0] << " requires an output file!" << endl; + return 1; + } + ofstream out(argv[1]); + out << R"( +#include "test.hpp" + +std::string getStr() { + return "Hello World"; +} +)"; + + return 0; +} diff --git a/test cases/cmake/4 code gen/test.hpp b/test cases/cmake/4 code gen/test.hpp new file mode 100644 index 0000000..8e25a0a --- /dev/null +++ b/test cases/cmake/4 code gen/test.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include <string> + +std::string getStr(); diff --git a/test cases/cmake/5 object library/main.cpp b/test cases/cmake/5 object library/main.cpp new file mode 100644 index 0000000..9933ab4 --- /dev/null +++ b/test cases/cmake/5 object library/main.cpp @@ -0,0 +1,11 @@ +#include <stdlib.h> +#include <iostream> +#include "libA.hpp" +#include "libB.hpp" + +using namespace std; + +int main(void) { + cout << getLibStr() << " -- " << getZlibVers() << endl; + return EXIT_SUCCESS; +} 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 0000000..f38a2dd --- /dev/null +++ b/test cases/cmake/5 object library/meson.build @@ -0,0 +1,21 @@ +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 + +cm = import('cmake') + +sub_pro = cm.subproject('cmObjLib') +sub_sha = sub_pro.dependency('lib_sha') +sub_sta = sub_pro.dependency('lib_sta') + +# 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/5 object library/subprojects/cmObjLib/CMakeLists.txt b/test cases/cmake/5 object library/subprojects/cmObjLib/CMakeLists.txt new file mode 100644 index 0000000..062496e --- /dev/null +++ b/test cases/cmake/5 object library/subprojects/cmObjLib/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.7) +project(cmObject CXX) + +find_package(ZLIB REQUIRED) + +add_library(lib_obj OBJECT libA.cpp libB.cpp) +add_library(lib_sha SHARED $<TARGET_OBJECTS:lib_obj>) +add_library(lib_sta STATIC $<TARGET_OBJECTS:lib_obj>) + +target_link_libraries(lib_sha ZLIB::ZLIB) +target_link_libraries(lib_sta ZLIB::ZLIB) diff --git a/test cases/cmake/5 object library/subprojects/cmObjLib/libA.cpp b/test cases/cmake/5 object library/subprojects/cmObjLib/libA.cpp new file mode 100644 index 0000000..1d579cf --- /dev/null +++ b/test cases/cmake/5 object library/subprojects/cmObjLib/libA.cpp @@ -0,0 +1,5 @@ +#include "libA.hpp" + +std::string getLibStr(void) { + return "Hello World"; +} diff --git a/test cases/cmake/5 object library/subprojects/cmObjLib/libA.hpp b/test cases/cmake/5 object library/subprojects/cmObjLib/libA.hpp new file mode 100644 index 0000000..84b7bc7 --- /dev/null +++ b/test cases/cmake/5 object library/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/5 object library/subprojects/cmObjLib/libB.cpp b/test cases/cmake/5 object library/subprojects/cmObjLib/libB.cpp new file mode 100644 index 0000000..22fe7c2 --- /dev/null +++ b/test cases/cmake/5 object library/subprojects/cmObjLib/libB.cpp @@ -0,0 +1,6 @@ +#include "libB.hpp" +#include <zlib.h> + +std::string getZlibVers(void) { + return zlibVersion(); +} diff --git a/test cases/cmake/5 object library/subprojects/cmObjLib/libB.hpp b/test cases/cmake/5 object library/subprojects/cmObjLib/libB.hpp new file mode 100644 index 0000000..52ccc16 --- /dev/null +++ b/test cases/cmake/5 object library/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(); 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 0000000..9933ab4 --- /dev/null +++ b/test cases/cmake/6 object library no dep/main.cpp @@ -0,0 +1,11 @@ +#include <stdlib.h> +#include <iostream> +#include "libA.hpp" +#include "libB.hpp" + +using namespace std; + +int main(void) { + cout << getLibStr() << " -- " << getZlibVers() << endl; + return EXIT_SUCCESS; +} diff --git a/test cases/cmake/6 object library no dep/meson.build b/test cases/cmake/6 object library no dep/meson.build new file mode 100644 index 0000000..65b8700 --- /dev/null +++ b/test cases/cmake/6 object library no dep/meson.build @@ -0,0 +1,13 @@ +project('cmake_object_lib_test', 'cpp') + +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/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 0000000..9e136af --- /dev/null +++ b/test cases/cmake/6 object library no dep/subprojects/cmObjLib/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.7) +project(cmObject CXX) + +add_library(lib_obj OBJECT libA.cpp libB.cpp) +add_library(lib_sha SHARED $<TARGET_OBJECTS:lib_obj>) +add_library(lib_sta STATIC $<TARGET_OBJECTS:lib_obj>) 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 0000000..1d579cf --- /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(void) { + 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 0000000..84b7bc7 --- /dev/null +++ b/test cases/cmake/6 object library no dep/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/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 0000000..aa44816 --- /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(void) { + 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 0000000..52ccc16 --- /dev/null +++ b/test cases/cmake/6 object library no dep/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(); diff --git a/test cases/cmake/7 cmake options/meson.build b/test cases/cmake/7 cmake options/meson.build new file mode 100644 index 0000000..8bb6d1d --- /dev/null +++ b/test cases/cmake/7 cmake options/meson.build @@ -0,0 +1,3 @@ +project('cmake_set_opt', ['c', 'cpp']) + +import('cmake').subproject('cmOpts', cmake_options: '-DSOME_CMAKE_VAR=something') diff --git a/test cases/cmake/7 cmake options/subprojects/cmOpts/CMakeLists.txt b/test cases/cmake/7 cmake options/subprojects/cmOpts/CMakeLists.txt new file mode 100644 index 0000000..873b9b3 --- /dev/null +++ b/test cases/cmake/7 cmake options/subprojects/cmOpts/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.7) +project(testPro) + +if(NOT "${SOME_CMAKE_VAR}" STREQUAL "something") + message(FATAL_ERROR "Setting the CMake var failed") +endif() + +if(NOT "${CMAKE_PREFIX_PATH}" STREQUAL "val1;val2") + message(FATAL_ERROR "Setting the CMAKE_PREFIX_PATH failed '${CMAKE_PREFIX_PATH}'") +endif() diff --git a/test cases/cmake/7 cmake options/test.json b/test cases/cmake/7 cmake options/test.json new file mode 100644 index 0000000..f9f0b05 --- /dev/null +++ b/test cases/cmake/7 cmake options/test.json @@ -0,0 +1,12 @@ +{ + "matrix": { + "options": { + "cmake_prefix_path": [ + { "val": ["val1", "val2"] } + ], + "build.cmake_prefix_path": [ + { "val": ["val1", "val2"] } + ] + } + } +} diff --git a/test cases/cmake/8 custom command/main.cpp b/test cases/cmake/8 custom command/main.cpp new file mode 100644 index 0000000..7558d60 --- /dev/null +++ b/test cases/cmake/8 custom command/main.cpp @@ -0,0 +1,11 @@ +#include <iostream> +#include <cmMod.hpp> + +using namespace std; + +int main(void) { + cmModClass obj("Hello"); + cout << obj.getStr() << endl; + cout << obj.getOther() << endl; + return 0; +} diff --git a/test cases/cmake/8 custom command/meson.build b/test cases/cmake/8 custom command/meson.build new file mode 100644 index 0000000..a262252 --- /dev/null +++ b/test cases/cmake/8 custom command/meson.build @@ -0,0 +1,16 @@ +project('cmakeSubTest', ['c', 'cpp']) + +if meson.is_cross_build() + error('MESON_SKIP_TEST this test does not cross compile correctly.') +endif + +cm = import('cmake') + +sub_pro = cm.subproject('cmMod') +sub_dep = sub_pro.dependency('cmModLib') + +assert(sub_pro.target_type('cmModLib') == 'shared_library', 'Target type should be shared_library') +assert(sub_pro.target_type('gen') == 'executable', 'Target type should be executable') + +exe1 = executable('main', ['main.cpp'], dependencies: [sub_dep]) +test('test1', exe1) diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 0000000..0185ddc --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,163 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) +set (CMAKE_CXX_STANDARD 14) +set (CMAKE_CXX_STANDARD_REQUIRED ON) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +add_definitions("-DDO_NOTHING_JUST_A_FLAG=1") + +add_executable(genMain genMain.cpp) +add_custom_command(OUTPUT main.cpp COMMAND genMain > main.cpp) + +add_executable(gen main.cpp) +add_executable(mycpy cp.cpp) + +# cpyBase +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/genTest.cpp" "${CMAKE_CURRENT_BINARY_DIR}/genTest.hpp" + COMMAND gen ARGS genTest +) + +set(CMD_PART) +list(APPEND CMD_PART COMMAND mycpy cpyBase.cpp.in cpyBase.cpp.in.gen) +list(APPEND CMD_PART COMMAND mycpy cpyBase.cpp.in.gen cpyBase.cpp.out) +list(APPEND CMD_PART COMMAND mycpy cpyBase.cpp.out cpyBase.cpp.something) + +add_custom_command( + OUTPUT cpyBase.cpp + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyBase.cpp.am" cpyBase.cpp.in + ${CMD_PART} + COMMAND mycpy cpyBase.cpp.in cpyBase.cpp.something + COMMAND mycpy cpyBase.cpp.something cpyBase.cpp.IAmRunningOutOfIdeas + COMMAND mycpy cpyBase.cpp.IAmRunningOutOfIdeas cpyBase.cpp + DEPENDS cpyBase.cpp.am;gen +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyBase.hpp.in" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyBase.hpp.am" cpyBase.hpp.in + DEPENDS cpyBase.hpp.am +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyBase.hpp.something" + COMMAND mycpy cpyBase.hpp.in cpyBase.hpp.something + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/cpyBase.hpp.in" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyBase.hpp" + COMMAND mycpy cpyBase.hpp.something cpyBase.hpp + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/cpyBase.hpp.something" +) + +# cpyNext (out of order is on purpose) +# -- first copy round +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/s1_a_hpp/file.txt" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyNext.hpp.am" file.txt + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyNext.hpp.am" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s1_a_hpp" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/s1_b_cpp/file.txt" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyNext.cpp.am" file.txt + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyNext.cpp.am" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s1_b_cpp" +) + +# -- final cpy round +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyNext.hpp" + COMMAND mycpy "${CMAKE_CURRENT_BINARY_DIR}/s2_b_hpp/file.txt" cpyNext.hpp + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/s2_b_hpp/file.txt" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyNext.cpp" + COMMAND mycpy "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp/file.txt" cpyNext.cpp + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp/file.txt" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) + +# -- second copy round +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/s2_b_hpp/file.txt" + COMMAND mycpy "${CMAKE_CURRENT_BINARY_DIR}/s1_a_hpp/file.txt" file.txt + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/s1_a_hpp/file.txt" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s2_b_hpp" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp/file.txt" + COMMAND mycpy "${CMAKE_CURRENT_BINARY_DIR}/s1_b_cpp/file.txt" file.txt + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/s1_b_cpp/file.txt" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp" +) + +# cpyTest (copy file without renaming) +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest.hpp" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest.hpp" "${CMAKE_CURRENT_BINARY_DIR}/cpyTest.hpp" + DEPENDS "cpyTest/cpyTest.hpp" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest2.hpp" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest2.hpp" "${CMAKE_CURRENT_BINARY_DIR}/cpyTest2.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest2.hpp" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest3.hpp" + COMMAND mycpy cpyTest3.hpp "${CMAKE_CURRENT_BINARY_DIR}/cpyTest3.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest3.hpp" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest" +) + +add_subdirectory(cpyTest ccppyyTTeesstt) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest/some/directory/cpyTest5.hpp" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest5.hpp" "${CMAKE_CURRENT_BINARY_DIR}/cpyTest/some/directory/cpyTest5.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest5.hpp" +) +include_directories("${CMAKE_CURRENT_BINARY_DIR}/cpyTest/some") + +add_library(cmModLib SHARED cmMod.cpp genTest.cpp cpyBase.cpp cpyBase.hpp cpyNext.cpp cpyNext.hpp cpyTest.cpp cpyTest.hpp cpyTest2.hpp cpyTest3.hpp cpyTest/some/directory/cpyTest5.hpp) +include(GenerateExportHeader) +generate_export_header(cmModLib) + +set(ARGS_TEST arg1) +set(ARGS_TEST ${ARGS_TEST} arg2) + +add_executable(macro_name macro_name.cpp) +add_executable(args_test args_test.cpp) +add_custom_target(args_test_cmd + COMMAND args_test ${ARGS_TEST} +) +add_custom_target(macro_name_cmd COMMAND macro_name) + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + message(STATUS "Running the -include test case on macro_name") + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyInc.hpp" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyInc.hpp.am" "${CMAKE_CURRENT_BINARY_DIR}/cpyInc.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyInc.hpp.am" + ) + target_compile_options(macro_name PUBLIC -DTEST_CMD_INCLUDE -include "${CMAKE_CURRENT_BINARY_DIR}/cpyInc.hpp") +endif() + +# Only executable targets are replaced in the command +# all other target names are kept as is +add_custom_target(clang-format COMMAND clang-format -i cmMod.cpp) + +add_dependencies(cmModLib args_test_cmd tgtCpyTest4) +add_dependencies(args_test_cmd macro_name_cmd;gen;mycpy) + +# Reproduce https://github.com/mesonbuild/meson/issues/10244 +add_custom_target(mycpy.all) +add_dependencies(mycpy.all mycpy) diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp new file mode 100644 index 0000000..abb8a42 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp @@ -0,0 +1,18 @@ +#include <iostream> +#include <fstream> + +using namespace std; + +int main(int argc, const char *argv[]) { + if(argc != 3 || string(argv[1]) != "arg1" || string(argv[2]) != "arg2") { + cerr << argv[0] << " requires 2 args" << endl; + return 1; + } + + ifstream in1("macro_name.txt"); + ofstream out1("cmModLib.hpp"); + out1 << "#define " << in1.rdbuf() << " = \"plop\""; + + + return 0; +} diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.cpp new file mode 100644 index 0000000..a466399 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.cpp @@ -0,0 +1,24 @@ +#include "cmMod.hpp" +#include "genTest.hpp" +#include "cpyBase.hpp" +#include "cpyNext.hpp" +#include "cpyTest.hpp" +#include "cmModLib.hpp" + +#ifndef FOO +#error FOO not declared +#endif + +using namespace std; + +cmModClass::cmModClass(string foo) { + str = foo + " World"; +} + +string cmModClass::getStr() const { + return str; +} + +string cmModClass::getOther() const { + return "Strings:\n - " + getStrCpy() + "\n - " + getStrNext() + "\n - " + getStrCpyTest(); +} diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.hpp b/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.hpp new file mode 100644 index 0000000..cfdbe88 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.hpp @@ -0,0 +1,14 @@ +#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; + std::string getOther() const; +}; diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cp.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/cp.cpp new file mode 100644 index 0000000..09433f2 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cp.cpp @@ -0,0 +1,22 @@ +#include <iostream> +#include <fstream> + +using namespace std; + +int main(int argc, char *argv[]) { + if(argc < 3) { + cerr << argv[0] << " requires an input and an output file!" << endl; + return 1; + } + + ifstream src(argv[1]); + ofstream dst(argv[2]); + + if(!src.is_open()) { + cerr << "Failed to open " << argv[1] << endl; + return 2; + } + + dst << src.rdbuf(); + return 0; +} diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.cpp.am b/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.cpp.am new file mode 100644 index 0000000..98dd09c --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.cpp.am @@ -0,0 +1,5 @@ +#include "cpyBase.hpp" + +std::string getStrCpy() { + return "Hello Copied File"; +} diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.hpp.am b/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.hpp.am new file mode 100644 index 0000000..c255fb1 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.hpp.am @@ -0,0 +1,5 @@ +#pragma once + +#include <string> + +std::string getStrCpy(); diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am b/test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am new file mode 100644 index 0000000..07c8ff7 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_INC_WAS_INCLUDED 1 diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.cpp.am b/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.cpp.am new file mode 100644 index 0000000..20a8815 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.cpp.am @@ -0,0 +1,5 @@ +#include "cpyNext.hpp" + +std::string getStrNext() { + return "Hello Copied File -- now even more convoluted!"; +} diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.hpp.am b/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.hpp.am new file mode 100644 index 0000000..41919d8 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.hpp.am @@ -0,0 +1,5 @@ +#pragma once + +#include <string> + +std::string getStrNext(); diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest.cpp new file mode 100644 index 0000000..627b8f9 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest.cpp @@ -0,0 +1,9 @@ +#include "cpyTest.hpp" +#include "cpyTest2.hpp" +#include "cpyTest3.hpp" +#include "ccppyyTTeesstt/cpyTest4.hpp" +#include "directory/cpyTest5.hpp" + +std::string getStrCpyTest() { + return CPY_TEST_STR_2 CPY_TEST_STR_3 CPY_TEST_STR_4 CPY_TEST_STR_5; +} diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/CMakeLists.txt b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/CMakeLists.txt new file mode 100644 index 0000000..f577dcf --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/CMakeLists.txt @@ -0,0 +1,7 @@ +add_custom_command( + OUTPUT cpyTest4.hpp + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest4.hpp" cpyTest4.hpp + DEPENDS cpyTest4.hpp +) + +add_custom_target(tgtCpyTest4 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/cpyTest4.hpp") diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest.hpp b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest.hpp new file mode 100644 index 0000000..e8dec13 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include <string> + +std::string getStrCpyTest(); diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest2.hpp b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest2.hpp new file mode 100644 index 0000000..bdbcc56 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest2.hpp @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_TEST_STR_2 "Hello " diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest3.hpp b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest3.hpp new file mode 100644 index 0000000..2d13376 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest3.hpp @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_TEST_STR_3 "CopyFile" diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest4.hpp b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest4.hpp new file mode 100644 index 0000000..4124c43 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest4.hpp @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_TEST_STR_4 " test" diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest5.hpp b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest5.hpp new file mode 100644 index 0000000..3669f00 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest5.hpp @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_TEST_STR_5 " test" diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/genMain.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/genMain.cpp new file mode 100644 index 0000000..33f0201 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/genMain.cpp @@ -0,0 +1,40 @@ +#include <iostream> + +using namespace std; + +int main() { + cout << R"asd( +#include <iostream> +#include <fstream> + +using namespace std; + +int main(int argc, const char *argv[]) { + if(argc < 2) { + cerr << argv[0] << " requires an output file!" << endl; + return 1; + } + ofstream out1(string(argv[1]) + ".hpp"); + ofstream out2(string(argv[1]) + ".cpp"); + out1 << R"( +#pragma once + +#include <string> + +std::string getStr(); +)"; + + out2 << R"( +#include ")" << argv[1] << R"(.hpp" + +std::string getStr() { + return "Hello World"; +} +)"; + + return 0; +} +)asd"; + + return 0; +} diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp new file mode 100644 index 0000000..964062f --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp @@ -0,0 +1,20 @@ +#include <iostream> +#include <fstream> +#include <chrono> +#include <thread> + +using namespace std; + +#ifdef TEST_CMD_INCLUDE +#if CPY_INC_WAS_INCLUDED != 1 +#error "cpyInc.hpp was not included" +#endif +#endif + +int main() { + this_thread::sleep_for(chrono::seconds(1)); + ofstream out1("macro_name.txt"); + out1 << "FOO"; + + return 0; +} diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/mycpy/.gitkeep b/test cases/cmake/8 custom command/subprojects/cmMod/mycpy/.gitkeep new file mode 100644 index 0000000..22c19ce --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/mycpy/.gitkeep @@ -0,0 +1 @@ +# Required to reproduce https://github.com/mesonbuild/meson/issues/10244 diff --git a/test cases/cmake/9 disabled subproject/meson.build b/test cases/cmake/9 disabled subproject/meson.build new file mode 100644 index 0000000..c153fa3 --- /dev/null +++ b/test cases/cmake/9 disabled subproject/meson.build @@ -0,0 +1,6 @@ +project('cmakeSubTest', ['c', 'cpp']) + +cm = import('cmake') + +sub_pro = cm.subproject('nothinig', required: false) +assert(not sub_pro.found(), 'subproject found() reports wrong value') |