From 07797988b51c681db155cfba34769b75f82e77d6 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sun, 24 Oct 2021 15:54:04 +0200 Subject: [PATCH] Fix a critical bug in generate_resources.cmake --- cmake/cmkr.cmake | 5 +++-- cmake/generate_resources.cmake | 13 ++++++------- cmake/resource.hpp.in | 7 +++++++ src/build.cpp | 2 +- src/cmake_generator.cpp | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 cmake/resource.hpp.in diff --git a/cmake/cmkr.cmake b/cmake/cmkr.cmake index 4fdc1ca..7377cbb 100644 --- a/cmake/cmkr.cmake +++ b/cmake/cmkr.cmake @@ -2,15 +2,16 @@ include_guard() # Change these defaults to point to your infrastructure if desired set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE) -set(CMKR_TAG "archive_9e1fa5dc" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) +set(CMKR_TAG "archive_a718dfd6" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) # Set these from the command line to customize for development/debugging purposes set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable") set(CMKR_SKIP_GENERATION OFF CACHE BOOL "skip automatic cmkr generation") # Disable cmkr if generation is disabled -if(DEFINED ENV{CI} OR CMKR_SKIP_GENERATION) +if(DEFINED ENV{CI} OR CMKR_SKIP_GENERATION OR CMKR_BUILD_SKIP_GENERATION) message(STATUS "[cmkr] Skipping automatic cmkr generation") + unset(CMKR_BUILD_SKIP_GENERATION CACHE) macro(cmkr) endmacro() return() diff --git a/cmake/generate_resources.cmake b/cmake/generate_resources.cmake index d2ada59..57533c3 100644 --- a/cmake/generate_resources.cmake +++ b/cmake/generate_resources.cmake @@ -7,13 +7,12 @@ function(generate_resources target) foreach(SOURCE ${TARGET_SOURCES}) if(SOURCE MATCHES ".cmake$") get_filename_component(RESOURCE_NAME "${SOURCE}" NAME_WE) - set(RESOURCE_HEADER "include/resources/${RESOURCE_NAME}.h") - configure_file("${SOURCE}" "${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_HEADER}") - file(READ "${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_HEADER}" RESOURCE_CONTENTS) - file(GENERATE - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_HEADER}" - CONTENT "namespace cmkr {\nnamespace resources {\nstatic const char* ${RESOURCE_NAME} = R\"RESOURCE(${RESOURCE_CONTENTS})RESOURCE\";\n}\n}" - ) + set(RESOURCE_HEADER "include/resources/${RESOURCE_NAME}.hpp") + # Add configure-time dependency on the source file + configure_file("${SOURCE}" "${RESOURCE_HEADER}" COPYONLY) + # Generate the actual resource into the header + file(READ "${SOURCE}" RESOURCE_CONTENTS) + configure_file("${PROJECT_SOURCE_DIR}/cmake/resource.hpp.in" "${RESOURCE_HEADER}" @ONLY) message(STATUS "[cmkr] Generated ${RESOURCE_HEADER}") endif() endforeach() diff --git a/cmake/resource.hpp.in b/cmake/resource.hpp.in new file mode 100644 index 0000000..70d8411 --- /dev/null +++ b/cmake/resource.hpp.in @@ -0,0 +1,7 @@ +namespace cmkr { +namespace resources { + +static const char* @RESOURCE_NAME@ = R"RESOURCE(@RESOURCE_CONTENTS@)RESOURCE"; + +} +} \ No newline at end of file diff --git a/src/build.cpp b/src/build.cpp index 96248fd..c1b425f 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -25,7 +25,7 @@ int run(int argc, char **argv) { if (gen::generate_cmake(fs::current_path().string().c_str())) throw std::runtime_error("CMake generation failure!"); - ss << "cmake -S. -DCMKR_SKIP_GENERATION=ON -B" << project.build_dir << " "; + ss << "cmake -S. -DCMKR_BUILD_SKIP_GENERATION=ON -B" << project.build_dir << " "; if (!project.generator.empty()) { ss << "-G \"" << project.generator << "\" "; diff --git a/src/cmake_generator.cpp b/src/cmake_generator.cpp index e714a19..8a0ab8d 100644 --- a/src/cmake_generator.cpp +++ b/src/cmake_generator.cpp @@ -1,7 +1,7 @@ #include "cmake_generator.hpp" #include "error.hpp" #include "literals.hpp" -#include +#include #include "fs.hpp" #include