diff options
Diffstat (limited to 'meson/test cases/cmake/8 custom command/subprojects/cmMod')
19 files changed, 353 insertions, 0 deletions
diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt b/meson/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 000000000..e27a4690e --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,159 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) +set (CMAKE_CXX_STANDARD 14) +set (CMAKE_CXX_STANDARD_REQUIRED ON) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +add_definitions("-DDO_NOTHING_JUST_A_FLAG=1") + +add_executable(genMain genMain.cpp) +add_custom_command(OUTPUT main.cpp COMMAND genMain > main.cpp) + +add_executable(gen main.cpp) +add_executable(mycpy cp.cpp) + +# cpyBase +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/genTest.cpp" "${CMAKE_CURRENT_BINARY_DIR}/genTest.hpp" + COMMAND gen ARGS genTest +) + +set(CMD_PART) +list(APPEND CMD_PART COMMAND mycpy cpyBase.cpp.in cpyBase.cpp.in.gen) +list(APPEND CMD_PART COMMAND mycpy cpyBase.cpp.in.gen cpyBase.cpp.out) +list(APPEND CMD_PART COMMAND mycpy cpyBase.cpp.out cpyBase.cpp.something) + +add_custom_command( + OUTPUT cpyBase.cpp + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyBase.cpp.am" cpyBase.cpp.in + ${CMD_PART} + 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" +) + +# cpyNext (out of order is on purpose) +# -- first copy round +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/s1_a_hpp/file.txt" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyNext.hpp.am" file.txt + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyNext.hpp.am" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s1_a_hpp" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/s1_b_cpp/file.txt" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyNext.cpp.am" file.txt + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyNext.cpp.am" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s1_b_cpp" +) + +# -- final cpy round +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyNext.hpp" + COMMAND mycpy "${CMAKE_CURRENT_BINARY_DIR}/s2_b_hpp/file.txt" cpyNext.hpp + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/s2_b_hpp/file.txt" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyNext.cpp" + COMMAND mycpy "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp/file.txt" cpyNext.cpp + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp/file.txt" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) + +# -- second copy round +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/s2_b_hpp/file.txt" + COMMAND mycpy "${CMAKE_CURRENT_BINARY_DIR}/s1_a_hpp/file.txt" file.txt + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/s1_a_hpp/file.txt" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s2_b_hpp" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp/file.txt" + COMMAND mycpy "${CMAKE_CURRENT_BINARY_DIR}/s1_b_cpp/file.txt" file.txt + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/s1_b_cpp/file.txt" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/s2_a_cpp" +) + +# cpyTest (copy file without renaming) +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest.hpp" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest.hpp" "${CMAKE_CURRENT_BINARY_DIR}/cpyTest.hpp" + DEPENDS "cpyTest/cpyTest.hpp" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest2.hpp" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest2.hpp" "${CMAKE_CURRENT_BINARY_DIR}/cpyTest2.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest2.hpp" +) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest3.hpp" + COMMAND mycpy cpyTest3.hpp "${CMAKE_CURRENT_BINARY_DIR}/cpyTest3.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest3.hpp" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest" +) + +add_subdirectory(cpyTest ccppyyTTeesstt) + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyTest/some/directory/cpyTest5.hpp" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest5.hpp" "${CMAKE_CURRENT_BINARY_DIR}/cpyTest/some/directory/cpyTest5.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest/cpyTest5.hpp" +) +include_directories("${CMAKE_CURRENT_BINARY_DIR}/cpyTest/some") + +add_library(cmModLib SHARED cmMod.cpp genTest.cpp cpyBase.cpp cpyBase.hpp cpyNext.cpp cpyNext.hpp cpyTest.cpp cpyTest.hpp cpyTest2.hpp cpyTest3.hpp cpyTest/some/directory/cpyTest5.hpp) +include(GenerateExportHeader) +generate_export_header(cmModLib) + +set(ARGS_TEST arg1) +set(ARGS_TEST ${ARGS_TEST} arg2) + +add_executable(macro_name macro_name.cpp) +add_executable(args_test args_test.cpp) +add_custom_target(args_test_cmd + COMMAND args_test ${ARGS_TEST} +) +add_custom_target(macro_name_cmd COMMAND macro_name) + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + message(STATUS "Running the -include test case on macro_name") + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cpyInc.hpp" + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyInc.hpp.am" "${CMAKE_CURRENT_BINARY_DIR}/cpyInc.hpp" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cpyInc.hpp.am" + ) + target_compile_options(macro_name PUBLIC -DTEST_CMD_INCLUDE -include "${CMAKE_CURRENT_BINARY_DIR}/cpyInc.hpp") +endif() + +# Only executable targets are replaced in the command +# all other target names are kept as is +add_custom_target(clang-format COMMAND clang-format -i cmMod.cpp) + +add_dependencies(cmModLib args_test_cmd tgtCpyTest4) +add_dependencies(args_test_cmd macro_name_cmd;gen;mycpy) diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp new file mode 100644 index 000000000..abb8a4266 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/args_test.cpp @@ -0,0 +1,18 @@ +#include <iostream> +#include <fstream> + +using namespace std; + +int main(int argc, const char *argv[]) { + if(argc != 3 || string(argv[1]) != "arg1" || string(argv[2]) != "arg2") { + cerr << argv[0] << " requires 2 args" << endl; + return 1; + } + + ifstream in1("macro_name.txt"); + ofstream out1("cmModLib.hpp"); + out1 << "#define " << in1.rdbuf() << " = \"plop\""; + + + return 0; +} diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.cpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.cpp new file mode 100644 index 000000000..e4d531829 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.cpp @@ -0,0 +1,24 @@ +#include "cmMod.hpp" +#include "genTest.hpp" +#include "cpyBase.hpp" +#include "cpyNext.hpp" +#include "cpyTest.hpp" +#include "cmModLib.hpp" + +#ifndef FOO +#error FOO not declared +#endif + +using namespace std; + +cmModClass::cmModClass(string foo) { + str = foo + " World"; +} + +string cmModClass::getStr() const { + return str; +} + +string cmModClass::getOther() const { + return "Srings:\n - " + getStrCpy() + "\n - " + getStrNext() + "\n - " + getStrCpyTest(); +} diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.hpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.hpp new file mode 100644 index 000000000..cfdbe880f --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cmMod.hpp @@ -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; +}; diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cp.cpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cp.cpp new file mode 100644 index 000000000..09433f24f --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cp.cpp @@ -0,0 +1,22 @@ +#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]); + + if(!src.is_open()) { + cerr << "Failed to open " << argv[1] << endl; + return 2; + } + + dst << src.rdbuf(); + return 0; +} diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.cpp.am b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.cpp.am new file mode 100644 index 000000000..98dd09c9c --- /dev/null +++ b/meson/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/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.hpp.am b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.hpp.am new file mode 100644 index 000000000..c255fb1d3 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyBase.hpp.am @@ -0,0 +1,5 @@ +#pragma once + +#include <string> + +std::string getStrCpy(); diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am new file mode 100644 index 000000000..07c8ff790 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyInc.hpp.am @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_INC_WAS_INCLUDED 1 diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.cpp.am b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.cpp.am new file mode 100644 index 000000000..20a8815ae --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.cpp.am @@ -0,0 +1,5 @@ +#include "cpyNext.hpp" + +std::string getStrNext() { + return "Hello Copied File -- now even more convoluted!"; +} diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.hpp.am b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.hpp.am new file mode 100644 index 000000000..41919d8d6 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyNext.hpp.am @@ -0,0 +1,5 @@ +#pragma once + +#include <string> + +std::string getStrNext(); diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest.cpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest.cpp new file mode 100644 index 000000000..627b8f900 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest.cpp @@ -0,0 +1,9 @@ +#include "cpyTest.hpp" +#include "cpyTest2.hpp" +#include "cpyTest3.hpp" +#include "ccppyyTTeesstt/cpyTest4.hpp" +#include "directory/cpyTest5.hpp" + +std::string getStrCpyTest() { + return CPY_TEST_STR_2 CPY_TEST_STR_3 CPY_TEST_STR_4 CPY_TEST_STR_5; +} diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/CMakeLists.txt b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/CMakeLists.txt new file mode 100644 index 000000000..f577dcf2a --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/CMakeLists.txt @@ -0,0 +1,7 @@ +add_custom_command( + OUTPUT cpyTest4.hpp + COMMAND mycpy "${CMAKE_CURRENT_SOURCE_DIR}/cpyTest4.hpp" cpyTest4.hpp + DEPENDS cpyTest4.hpp +) + +add_custom_target(tgtCpyTest4 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/cpyTest4.hpp") diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest.hpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest.hpp new file mode 100644 index 000000000..e8dec13c0 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include <string> + +std::string getStrCpyTest(); diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest2.hpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest2.hpp new file mode 100644 index 000000000..bdbcc56cb --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest2.hpp @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_TEST_STR_2 "Hello " diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest3.hpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest3.hpp new file mode 100644 index 000000000..2d13376b1 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest3.hpp @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_TEST_STR_3 "CopyFile" diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest4.hpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest4.hpp new file mode 100644 index 000000000..4124c430b --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest4.hpp @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_TEST_STR_4 " test" diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest5.hpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest5.hpp new file mode 100644 index 000000000..3669f00b4 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/cpyTest/cpyTest5.hpp @@ -0,0 +1,3 @@ +#pragma once + +#define CPY_TEST_STR_5 " test" diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/genMain.cpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/genMain.cpp new file mode 100644 index 000000000..33f020159 --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/genMain.cpp @@ -0,0 +1,40 @@ +#include <iostream> + +using namespace std; + +int main() { + cout << R"asd( +#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; +} +)asd"; + + return 0; +} diff --git a/meson/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp b/meson/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp new file mode 100644 index 000000000..964062ffe --- /dev/null +++ b/meson/test cases/cmake/8 custom command/subprojects/cmMod/macro_name.cpp @@ -0,0 +1,20 @@ +#include <iostream> +#include <fstream> +#include <chrono> +#include <thread> + +using namespace std; + +#ifdef TEST_CMD_INCLUDE +#if CPY_INC_WAS_INCLUDED != 1 +#error "cpyInc.hpp was not included" +#endif +#endif + +int main() { + this_thread::sleep_for(chrono::seconds(1)); + ofstream out1("macro_name.txt"); + out1 << "FOO"; + + return 0; +} |