From 647d80f34cb09d5585fc690399e8aede0f4294b0 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Fri, 28 Jun 2019 13:21:58 +0200 Subject: [PATCH] cmake: Added custom_target test case --- test cases/cmake/8 custom command/main.cpp | 11 +++++ test cases/cmake/8 custom command/meson.build | 12 +++++ .../subprojects/cmMod/CMakeLists.txt | 46 +++++++++++++++++++ .../subprojects/cmMod/cmMod.cpp | 17 +++++++ .../subprojects/cmMod/cmMod.hpp | 14 ++++++ .../8 custom command/subprojects/cmMod/cp.cpp | 17 +++++++ .../subprojects/cmMod/cpyBase.cpp.am | 5 ++ .../subprojects/cmMod/cpyBase.hpp.am | 5 ++ .../subprojects/cmMod/main.cpp | 30 ++++++++++++ 9 files changed, 157 insertions(+) create mode 100644 test cases/cmake/8 custom command/main.cpp create mode 100644 test cases/cmake/8 custom command/meson.build create mode 100644 test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt create mode 100644 test cases/cmake/8 custom command/subprojects/cmMod/cmMod.cpp create mode 100644 test cases/cmake/8 custom command/subprojects/cmMod/cmMod.hpp create mode 100644 test cases/cmake/8 custom command/subprojects/cmMod/cp.cpp create mode 100644 test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.cpp.am create mode 100644 test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.hpp.am create mode 100644 test cases/cmake/8 custom command/subprojects/cmMod/main.cpp 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 000000000..fa6b0fae5 --- /dev/null +++ b/test cases/cmake/8 custom command/main.cpp @@ -0,0 +1,11 @@ +#include +#include + +using namespace std; + +int main() { + 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 000000000..799e339a0 --- /dev/null +++ b/test cases/cmake/8 custom command/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_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 000000000..7143cf323 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,46 @@ +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_executable(gen main.cpp) +add_executable(mycpy cp.cpp) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/genTest.cpp" "${CMAKE_CURRENT_BINARY_DIR}/genTest.hpp" + COMMAND gen genTest +) + +add_custom_command( + OUTPUT cpyBase.cpp + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyBase.cpp.am" cpyBase.cpp.in + 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" +) + +add_library(cmModLib SHARED cmMod.cpp genTest.cpp cpyBase.cpp cpyBase.hpp) +include(GenerateExportHeader) +generate_export_header(cmModLib) 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 000000000..0fb6aa724 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.cpp @@ -0,0 +1,17 @@ +#include "cmMod.hpp" +#include "genTest.hpp" +#include "cpyBase.hpp" + +using namespace std; + +cmModClass::cmModClass(string foo) { + str = foo + " World"; +} + +string cmModClass::getStr() const { + return str; +} + +string cmModClass::getOther() const { + return getStr() + " -- " + getStrCpy(); +} 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 000000000..cfdbe880f --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include +#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 000000000..2744da8fb --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cp.cpp @@ -0,0 +1,17 @@ +#include +#include + +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]); + + 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 000000000..98dd09c9c --- /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 000000000..c255fb1d3 --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.hpp.am @@ -0,0 +1,5 @@ +#pragma once + +#include + +std::string getStrCpy(); diff --git a/test cases/cmake/8 custom command/subprojects/cmMod/main.cpp b/test cases/cmake/8 custom command/subprojects/cmMod/main.cpp new file mode 100644 index 000000000..9fade211d --- /dev/null +++ b/test cases/cmake/8 custom command/subprojects/cmMod/main.cpp @@ -0,0 +1,30 @@ +#include +#include + +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 + +std::string getStr(); +)"; + + out2 << R"( +#include ")" << argv[1] << R"(.hpp" + +std::string getStr() { + return "Hello World"; +} +)"; + + return 0; +}