Open briankendall opened 4 weeks ago
I'm getting a bit more competent with CMake now, and I've figured out a way to get all of my resource files being compiled together properly. I figure I'd post it here so that others may benefit from it.
First I create a file named generate_combined_resource_file.cmake
and place it in my source directory, with the contents:
file(WRITE ${COMBINED_RESOURCE_FILE} "#include \"Types.r\"\n#include \"SysTypes.r\"\n")
foreach(FILE ${ALL_RESOURCE_FILES})
file(APPEND ${COMBINED_RESOURCE_FILE} "#include \"${FILE}\"\n")
endforeach()
This creates a .r file that includes all of my various other .r files, along with Types.r
and SysTypes.r
.
Then in CMakeLists.txt, I include the following:
set(COMBINED_RESOURCE_FILE ${CMAKE_BINARY_DIR}/resources-combined.r)
add_application(YourAppNameHere
... (your source files here)
${COMBINED_RESOURCE_FILE}
)
# Variable containing all of my resource files. Update the path to point to where your .r files are!
file(GLOB ALL_RESOURCE_FILES "${CMAKE_SOURCE_DIR}/resources/*.r")
# Create .r file combining together all resource files:
add_custom_command(
OUTPUT ${COMBINED_RESOURCE_FILE}
COMMAND ${CMAKE_COMMAND}
-D COMBINED_RESOURCE_FILE="${COMBINED_RESOURCE_FILE}"
-D "ALL_RESOURCE_FILES=\"${ALL_RESOURCE_FILES}\""
-P ${CMAKE_SOURCE_DIR}/generate_combined_resource_file.cmake
DEPENDS ${ALL_RESOURCE_FILES}
COMMENT "Generating combined resource file"
)
add_custom_target(generate_combined_resources ALL DEPENDS ${COMBINED_RESOURCE_FILE})
add_dependencies(YourAppNameHere generate_combined_resources)
I'm using a .r file (exported using DeRez, though that's probably not important) in my project named
resources-exported.r
. This is#include
'd in another .r file namedresources.r
. Any time I changeresources-exported.r
it doesn't trigger a recompilation ofresources.r
. So I have to manually touchresources.r
to get things to build properly.It's a bit annoying and I can work around it, but it'd be nice if there was a way to define this dependency. I've tried to work out how to change my project's
CMakeLists.txt
to set this up manually, but I'm a bit of a cmake newbie and I haven't figured it out so far.