parent
a2f94ca18b
commit
08e838a235
9 changed files with 151 additions and 0 deletions
@ -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; |
||||
} |
@ -0,0 +1,24 @@ |
||||
project('cmake_set_opt', ['c', 'cpp']) |
||||
|
||||
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) |
@ -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) |
@ -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; |
||||
} |
@ -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; |
||||
}; |
@ -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; |
||||
} |
@ -0,0 +1,3 @@ |
||||
#pragma once |
||||
|
||||
int getTestInt(); |
@ -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; |
||||
} |
@ -0,0 +1,8 @@ |
||||
{ |
||||
"installed": [ |
||||
{"type": "exe", "file": "usr/bin/cm_testEXE"} |
||||
], |
||||
"tools": { |
||||
"cmake": ">=3.11" |
||||
} |
||||
} |
Loading…
Reference in new issue