cmake: Added custom_target test case

pull/5574/head
Daniel Mensinger 6 years ago
parent 5806490219
commit 647d80f34c
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 11
      test cases/cmake/8 custom command/main.cpp
  2. 12
      test cases/cmake/8 custom command/meson.build
  3. 46
      test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt
  4. 17
      test cases/cmake/8 custom command/subprojects/cmMod/cmMod.cpp
  5. 14
      test cases/cmake/8 custom command/subprojects/cmMod/cmMod.hpp
  6. 17
      test cases/cmake/8 custom command/subprojects/cmMod/cp.cpp
  7. 5
      test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.cpp.am
  8. 5
      test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.hpp.am
  9. 30
      test cases/cmake/8 custom command/subprojects/cmMod/main.cpp

@ -0,0 +1,11 @@
#include <iostream>
#include <cmMod.hpp>
using namespace std;
int main() {
cmModClass obj("Hello");
cout << obj.getStr() << endl;
cout << obj.getOther() << endl;
return 0;
}

@ -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)

@ -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)

@ -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();
}

@ -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;
};

@ -0,0 +1,17 @@
#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]);
dst << src.rdbuf();
return 0;
}

@ -0,0 +1,5 @@
#include "cpyBase.hpp"
std::string getStrCpy() {
return "Hello Copied File";
}

@ -0,0 +1,5 @@
#pragma once
#include <string>
std::string getStrCpy();

@ -0,0 +1,30 @@
#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;
}
Loading…
Cancel
Save