cmake: Added Code generation test

pull/4969/head
Daniel Mensinger 6 years ago
parent 316f4f4948
commit d9481f2359
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 8
      test cases/cmake/3 code gen/main.cpp
  2. 18
      test cases/cmake/3 code gen/meson.build
  3. 5
      test cases/cmake/3 code gen/subprojects/cmCodeGen/CMakeLists.txt
  4. 21
      test cases/cmake/3 code gen/subprojects/cmCodeGen/main.cpp
  5. 5
      test cases/cmake/3 code gen/test.hpp

@ -0,0 +1,8 @@
#include <iostream>
#include "test.hpp"
using namespace std;
int main() {
cout << getStr() << endl;
}

@ -0,0 +1,18 @@
project('cmake_code_gen', ['cpp'])
# Subproject with the "code generator"
sub_pro = subproject('cmCodeGen')
sub_exe = sub_pro.get_variable('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)

@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.7)
set(CMAKE_CXX_STANDARD 14)
add_executable(genA 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;
}

@ -0,0 +1,5 @@
#pragma once
#include <string>
std::string getStr();
Loading…
Cancel
Save