Skip to content

Instantly share code, notes, and snippets.

@Chrd26
Last active May 1, 2024 17:15
Show Gist options
  • Save Chrd26/06a48ffec0e975277fdb8ddd7d26f18a to your computer and use it in GitHub Desktop.
Save Chrd26/06a48ffec0e975277fdb8ddd7d26f18a to your computer and use it in GitHub Desktop.
MacOS .app file bundle resource files handler code.
# For multiple resources
file(GLOB_RECURSE YOUR_VARIABLE_NAME "relative/path/to/files/folder/* or *.filetype")
# * grabs everything within the directory
# *.filetype grabs everything with has a certain filetype
# Create .app executable
add_executable( ${PROJECT_NAME} MACOSX_BUNDLE
./src/main.cpp ./src/somefile.h
${YOUR_VARIABLE_NAME})
foreach(VARIABLE_NAME ${YOUR_VARIABLE_NAME})
# Get the folder and the file name
file(RELATIVE_PATH RES_PATH_NAME"${CMAKE_CURRENT_SOURCE_DIR}" ${VARIABLE_NAME})
# keep only the name of the folder
get_filename_component(NEW_FILE_PATH_NAME ${RES_PATH_NAME} DIRECTORY)
# Add current file and directory to the resources folder
set_property(SOURCE ${VARIABLE_NAME} PROPERTY MACOSX_PACKAGE_LOCATION "Resources/${NEW_FILE_PATH_NAME}")
endforeach(VARIABLE_NAME)
# For one resource file
file(GLOB VARIABLE_NAME "path/to/file.filetype")
# Create .app executabled
add_executable( ${PROJECT_NAME} MACOSX_BUNDLE
./src/main.cpp ./src/somefile.h
${YOUR_VARIABLE_NAME}})
# Add single file and directory to the resources folder
file(RELATIVE_PATH GET_REL_PATH_NAME "${CMAKE_CURRENT_SOURCE_DIR}" ${VARIABLE_NAME} )
get_filename_component(FILE_PATH_NAME "${GET_REL_PATH_NAME}" DIRECTORY)
set_property(SOURCE "${VARIABLE_NAME}" PROPERTY MACOSX_PACKAGE_LOCATION "Resources/${FILE_PATH_NAME}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment