Skip to content

Commit cd68ba6

Browse files
committed
ui-cpp: upgrade CMakeRC.cmake to fix the ImGUI build
1 parent b2c1b0e commit cd68ba6

1 file changed

Lines changed: 40 additions & 13 deletions

File tree

ui-cpp/CMake/CMakeRC.cmake

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ endif()
5858

5959
set(_version 2.0.0)
6060

61-
cmake_minimum_required(VERSION 3.3)
61+
cmake_minimum_required(VERSION 3.12)
6262
include(CMakeParseArguments)
6363

6464
if(COMMAND cmrc_add_resource_library)
@@ -101,6 +101,10 @@ set(hpp_content [==[
101101
#include <system_error>
102102
#include <type_traits>
103103
104+
#if !(defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) || defined(CMRC_NO_EXCEPTIONS))
105+
#define CMRC_NO_EXCEPTIONS 1
106+
#endif
107+
104108
namespace cmrc { namespace detail { struct dummy; } }
105109
106110
#define CMRC_DECLARE(libid) \
@@ -125,7 +129,7 @@ public:
125129
iterator cbegin() const noexcept { return _begin; }
126130
iterator end() const noexcept { return _end; }
127131
iterator cend() const noexcept { return _end; }
128-
std::size_t size() const { return std::distance(begin(), end()); }
132+
std::size_t size() const { return static_cast<std::size_t>(std::distance(begin(), end())); }
129133
130134
file() = default;
131135
file(iterator beg, iterator end) noexcept : _begin(beg), _end(end) {}
@@ -267,15 +271,15 @@ public:
267271
return !(*this == rhs);
268272
}
269273
270-
iterator operator++() noexcept {
271-
auto cp = *this;
274+
iterator& operator++() noexcept {
272275
++_base_iter;
273-
return cp;
276+
return *this;
274277
}
275278
276-
iterator& operator++(int) noexcept {
279+
iterator operator++(int) noexcept {
280+
auto cp = *this;
277281
++_base_iter;
278-
return *this;
282+
return cp;
279283
}
280284
};
281285
@@ -299,7 +303,7 @@ inline std::string normalize_path(std::string path) {
299303
}
300304
auto off = path.npos;
301305
while ((off = path.find("//")) != path.npos) {
302-
path.erase(path.begin() + off);
306+
path.erase(path.begin() + static_cast<std::string::difference_type>(off));
303307
}
304308
return path;
305309
}
@@ -363,7 +367,12 @@ public:
363367
file open(const std::string& path) const {
364368
auto entry_ptr = _get(path);
365369
if (!entry_ptr || !entry_ptr->is_file()) {
370+
#ifdef CMRC_NO_EXCEPTIONS
371+
fprintf(stderr, "Error no such file or directory: %s\n", path.c_str());
372+
abort();
373+
#else
366374
throw std::system_error(make_error_code(std::errc::no_such_file_or_directory), path);
375+
#endif
367376
}
368377
auto& dat = entry_ptr->as_file();
369378
return file{dat.begin_ptr, dat.end_ptr};
@@ -386,10 +395,20 @@ public:
386395
directory_iterator iterate_directory(const std::string& path) const {
387396
auto entry_ptr = _get(path);
388397
if (!entry_ptr) {
398+
#ifdef CMRC_NO_EXCEPTIONS
399+
fprintf(stderr, "Error no such file or directory: %s\n", path.c_str());
400+
abort();
401+
#else
389402
throw std::system_error(make_error_code(std::errc::no_such_file_or_directory), path);
403+
#endif
390404
}
391405
if (!entry_ptr->is_directory()) {
406+
#ifdef CMRC_NO_EXCEPTIONS
407+
fprintf(stderr, "Error not a directory: %s\n", path.c_str());
408+
abort();
409+
#else
392410
throw std::system_error(make_error_code(std::errc::not_a_directory), path);
411+
#endif
393412
}
394413
return entry_ptr->as_directory().begin();
395414
}
@@ -411,14 +430,14 @@ endif()
411430
file(GENERATE OUTPUT "${cmrc_hpp}" CONTENT "${hpp_content}" CONDITION ${_generate})
412431

413432
add_library(cmrc-base INTERFACE)
414-
target_include_directories(cmrc-base INTERFACE "${CMRC_INCLUDE_DIR}")
433+
target_include_directories(cmrc-base INTERFACE $<BUILD_INTERFACE:${CMRC_INCLUDE_DIR}>)
415434
# Signal a basic C++11 feature to require C++11.
416435
target_compile_features(cmrc-base INTERFACE cxx_nullptr)
417436
set_property(TARGET cmrc-base PROPERTY INTERFACE_CXX_EXTENSIONS OFF)
418437
add_library(cmrc::base ALIAS cmrc-base)
419438

420439
function(cmrc_add_resource_library name)
421-
set(args ALIAS NAMESPACE)
440+
set(args ALIAS NAMESPACE TYPE)
422441
cmake_parse_arguments(ARG "" "${args}" "" "${ARGN}")
423442
# Generate the identifier for the resource library's namespace
424443
set(ns_re "[a-zA-Z_][a-zA-Z0-9_]*")
@@ -434,6 +453,14 @@ function(cmrc_add_resource_library name)
434453
endif()
435454
endif()
436455
set(libname "${name}")
456+
# Check that type is either "STATIC" or "OBJECT", or default to "STATIC" if
457+
# not set
458+
if(NOT DEFINED ARG_TYPE)
459+
set(ARG_TYPE STATIC)
460+
elseif(NOT "${ARG_TYPE}" MATCHES "^(STATIC|OBJECT)$")
461+
message(SEND_ERROR "${ARG_TYPE} is not a valid TYPE (STATIC and OBJECT are acceptable)")
462+
set(ARG_TYPE STATIC)
463+
endif()
437464
# Generate a library with the compiled in character arrays.
438465
string(CONFIGURE [=[
439466
#include <cmrc/cmrc.hpp>
@@ -492,7 +519,7 @@ function(cmrc_add_resource_library name)
492519
# Generate the actual static library. Each source file is just a single file
493520
# with a character array compiled in containing the contents of the
494521
# corresponding resource file.
495-
add_library(${name} STATIC ${libcpp})
522+
add_library(${name} ${ARG_TYPE} ${libcpp})
496523
set_property(TARGET ${name} PROPERTY CMRC_LIBDIR "${libdir}")
497524
set_property(TARGET ${name} PROPERTY CMRC_NAMESPACE "${ARG_NAMESPACE}")
498525
target_link_libraries(${name} PUBLIC cmrc::base)
@@ -582,7 +609,7 @@ function(cmrc_add_resources name)
582609
endif()
583610
get_filename_component(dirpath "${ARG_PREFIX}${relpath}" DIRECTORY)
584611
_cmrc_register_dirs("${name}" "${dirpath}")
585-
get_filename_component(abs_out "${libdir}/intermediate/${relpath}.cpp" ABSOLUTE)
612+
get_filename_component(abs_out "${libdir}/intermediate/${ARG_PREFIX}${relpath}.cpp" ABSOLUTE)
586613
# Generate a symbol name relpath the file's character array
587614
_cm_encode_fpath(sym "${relpath}")
588615
# Get the symbol name for the parent directory
@@ -638,4 +665,4 @@ function(_cm_encode_fpath var fpath)
638665
string(MD5 hash "${fpath}")
639666
string(SUBSTRING "${hash}" 0 4 hash)
640667
set(${var} f_${hash}_${ident} PARENT_SCOPE)
641-
endfunction()
668+
endfunction()

0 commit comments

Comments
 (0)