125 lines
4.7 KiB
CMake
125 lines
4.7 KiB
CMake
# First, set up registration functions for the kinds of resources we handle.
|
|
set(resource_root ${CMAKE_CURRENT_SOURCE_DIR}/)
|
|
set(resource_list)
|
|
if(WIN32)
|
|
set(rc_file ${CMAKE_CURRENT_BINARY_DIR}/resources.rc)
|
|
file(WRITE ${rc_file} "// Autogenerated; do not edit\n")
|
|
|
|
function(add_resource name)
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${name})
|
|
|
|
list(GET "${ARGN}" 0 id)
|
|
if(id STREQUAL NOTFOUND)
|
|
string(REPLACE ${resource_root} "" id ${source})
|
|
endif()
|
|
list(GET "${ARGN}" 1 type)
|
|
if(type STREQUAL NOTFOUND)
|
|
set(type RCDATA)
|
|
endif()
|
|
file(SHA512 "${source}" hash)
|
|
file(APPEND ${rc_file} "${id} ${type} \"${source}\" // ${hash}\n")
|
|
# CMake doesn't track file dependencies across directories, so we force
|
|
# a reconfigure (which changes the RC file because of the hash above)
|
|
# every time a resource is changed.
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${source}")
|
|
endfunction()
|
|
elseif(APPLE)
|
|
set(app_resource_dir ${CMAKE_BINARY_DIR}/src/solvespace.app/Contents/Resources)
|
|
|
|
function(add_resource name)
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${name})
|
|
set(target ${app_resource_dir}/${name})
|
|
set(resource_list "${resource_list};${target}" PARENT_SCOPE)
|
|
|
|
get_filename_component(target_dir ${target} DIRECTORY)
|
|
add_custom_command(
|
|
OUTPUT ${target}
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${target_dir}
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${source} ${target}
|
|
COMMENT "Copying resource ${name}"
|
|
DEPENDS ${source}
|
|
VERBATIM)
|
|
endfunction()
|
|
|
|
function(add_xib name)
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${name})
|
|
get_filename_component(basename ${name} NAME_WE)
|
|
set(target ${app_resource_dir}/${basename}.nib)
|
|
set(resource_list "${resource_list};${target}" PARENT_SCOPE)
|
|
|
|
add_custom_command(
|
|
OUTPUT ${target}
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${app_resource_dir}
|
|
COMMAND ibtool --errors --warnings --notices --output-format human-readable-text
|
|
--compile ${target} ${source}
|
|
COMMENT "Building Interface Builder file ${name}"
|
|
DEPENDS ${source}
|
|
VERBATIM)
|
|
endfunction()
|
|
|
|
function(add_iconset name)
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${name})
|
|
get_filename_component(basename ${name} NAME_WE)
|
|
set(target ${app_resource_dir}/${basename}.icns)
|
|
set(resource_list "${resource_list};${target}" PARENT_SCOPE)
|
|
|
|
add_custom_command(
|
|
OUTPUT ${target}
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${app_resource_dir}
|
|
COMMAND iconutil -c icns -o ${target} ${source}
|
|
COMMENT "Building icon set ${name}"
|
|
DEPENDS ${source}
|
|
VERBATIM)
|
|
endfunction()
|
|
else() # Unix
|
|
include(GNUInstallDirs)
|
|
|
|
set(app_resource_dir ${CMAKE_BINARY_DIR}/res)
|
|
|
|
function(add_resource name)
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${name})
|
|
set(target ${app_resource_dir}/${name})
|
|
set(resource_list "${resource_list};${target}" PARENT_SCOPE)
|
|
|
|
get_filename_component(target_dir ${target} DIRECTORY)
|
|
add_custom_command(
|
|
OUTPUT ${target}
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${target_dir}
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${source} ${target}
|
|
COMMENT "Copying resource ${name}"
|
|
DEPENDS ${source}
|
|
VERBATIM)
|
|
|
|
get_filename_component(name_dir ${name} DIRECTORY)
|
|
install(FILES ${source}
|
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/solvespace/${name_dir})
|
|
endfunction()
|
|
endif()
|
|
|
|
# Second, register all resources.
|
|
if(WIN32)
|
|
add_resource(win32/icon.ico RT_ICON_GROUP APP_ICON)
|
|
add_resource(win32/manifest.xml RT_MANIFEST APP_MANIFEST)
|
|
elseif(APPLE)
|
|
else()
|
|
install(FILES freedesktop/solvespace.desktop
|
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
|
|
|
|
foreach(SIZE 16x16 24x24 32x32 48x48)
|
|
install(FILES freedesktop/solvespace-${SIZE}.png
|
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${SIZE}/apps
|
|
RENAME solvespace.png)
|
|
install(FILES freedesktop/solvespace-${SIZE}.png
|
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${SIZE}/mimetypes
|
|
RENAME application.x-solvespace.png)
|
|
endforeach()
|
|
endif()
|
|
add_resource(banner.txt)
|
|
|
|
# Third, distribute the resources.
|
|
add_custom_target(resources
|
|
DEPENDS ${resource_list})
|
|
if(WIN32)
|
|
set_property(TARGET resources PROPERTY EXTRA_SOURCES ${rc_file})
|
|
endif()
|