From d9481f23599d8eab5ef4bceb9cde23a14ef4f066 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sat, 23 Feb 2019 12:18:33 +0100 Subject: [PATCH] cmake: Added Code generation test --- test cases/cmake/3 code gen/main.cpp | 8 +++++++ test cases/cmake/3 code gen/meson.build | 18 ++++++++++++++++ .../subprojects/cmCodeGen/CMakeLists.txt | 5 +++++ .../3 code gen/subprojects/cmCodeGen/main.cpp | 21 +++++++++++++++++++ test cases/cmake/3 code gen/test.hpp | 5 +++++ 5 files changed, 57 insertions(+) create mode 100644 test cases/cmake/3 code gen/main.cpp create mode 100644 test cases/cmake/3 code gen/meson.build create mode 100644 test cases/cmake/3 code gen/subprojects/cmCodeGen/CMakeLists.txt create mode 100644 test cases/cmake/3 code gen/subprojects/cmCodeGen/main.cpp create mode 100644 test cases/cmake/3 code gen/test.hpp diff --git a/test cases/cmake/3 code gen/main.cpp b/test cases/cmake/3 code gen/main.cpp new file mode 100644 index 000000000..3ddbf636b --- /dev/null +++ b/test cases/cmake/3 code gen/main.cpp @@ -0,0 +1,8 @@ +#include +#include "test.hpp" + +using namespace std; + +int main() { + cout << getStr() << endl; +} diff --git a/test cases/cmake/3 code gen/meson.build b/test cases/cmake/3 code gen/meson.build new file mode 100644 index 000000000..daa93cedd --- /dev/null +++ b/test cases/cmake/3 code gen/meson.build @@ -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) \ No newline at end of file diff --git a/test cases/cmake/3 code gen/subprojects/cmCodeGen/CMakeLists.txt b/test cases/cmake/3 code gen/subprojects/cmCodeGen/CMakeLists.txt new file mode 100644 index 000000000..268743c73 --- /dev/null +++ b/test cases/cmake/3 code gen/subprojects/cmCodeGen/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.7) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(genA main.cpp) diff --git a/test cases/cmake/3 code gen/subprojects/cmCodeGen/main.cpp b/test cases/cmake/3 code gen/subprojects/cmCodeGen/main.cpp new file mode 100644 index 000000000..5b7fed2b9 --- /dev/null +++ b/test cases/cmake/3 code gen/subprojects/cmCodeGen/main.cpp @@ -0,0 +1,21 @@ +#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 out(argv[1]); + out << R"( +#include "test.hpp" + +std::string getStr() { + return "Hello World"; +} +)"; + + return 0; +} diff --git a/test cases/cmake/3 code gen/test.hpp b/test cases/cmake/3 code gen/test.hpp new file mode 100644 index 000000000..8e25a0a5e --- /dev/null +++ b/test cases/cmake/3 code gen/test.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include + +std::string getStr();