Skip to content

Commit

Permalink
Fix a critical bug in generate_resources.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Oct 24, 2021
1 parent 285614e commit 0779798
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions cmake/cmkr.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 6 additions & 7 deletions cmake/generate_resources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions cmake/resource.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace cmkr {
namespace resources {

static const char* @RESOURCE_NAME@ = R"RESOURCE(@RESOURCE_CONTENTS@)RESOURCE";

}
}
2 changes: 1 addition & 1 deletion src/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << "\" ";
Expand Down
2 changes: 1 addition & 1 deletion src/cmake_generator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "cmake_generator.hpp"
#include "error.hpp"
#include "literals.hpp"
#include <resources/cmkr.h>
#include <resources/cmkr.hpp>

#include "fs.hpp"
#include <cassert>
Expand Down

0 comments on commit 0779798

Please sign in to comment.