From 93d08e8d1315b428c8c7c5b76c5b10c93dc170fd Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 18 Oct 2023 22:04:43 +0200 Subject: [PATCH] Fixes for macOS building rlottie/samples --- .gitignore | 1 + CMakeLists.txt | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 918cfb7ac..602b0dcee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Primary CMake build target /Build/ +/Dependencies/ # Other common build targets /build*/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d373b333..c449c4a75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,8 @@ if(SAMPLES_BACKEND STREQUAL "auto") endif() endif() +set(SAMPLES_DIR ${PROJECT_SOURCE_DIR}/Samples CACHE PATH "Path to samples directory.") + option(MATRIX_ROW_MAJOR "Use row-major matrices. Column-major matrices are used by default." OFF) if(APPLE) @@ -418,7 +420,7 @@ elseif( ENABLE_LOTTIE_PLUGIN ) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/rlottie/build) find_package(rlottie CONFIG) - find_path(rlottie_INCLUDE_DIR rlottie.h HINTS ${rlottie_DIR} $ENV{rlottie_DIR} PATH_SUFFIXES inc rlottie/inc ) + find_path(rlottie_INCLUDE_DIR rlottie.h HINTS ${rlottie_DIR} $ENV{rlottie_DIR} PATH_SUFFIXES inc rlottie/inc ../inc) if(rlottie_FOUND AND rlottie_INCLUDE_DIR) message("-- Can Lottie plugin be added to RmlCore - yes - rlottie library found") @@ -662,12 +664,33 @@ endif() # Build samples ==================== #=================================== +function(resource VAR SOURCE_PATH DESTINATION PATTERN) + file(GLOB_RECURSE _LIST CONFIGURE_DEPENDS ${SOURCE_PATH}/${PATTERN}) + foreach (RESOURCE ${_LIST}) + get_filename_component(_PARENT ${RESOURCE} DIRECTORY) + if (${_PARENT} STREQUAL ${SOURCE_PATH}) + set(_DESTINATION ${DESTINATION}) + else () + file(RELATIVE_PATH _DESTINATION ${SOURCE_PATH} ${_PARENT}) + set(_DESTINATION ${DESTINATION}/${_DESTINATION}) + endif () + set_property(SOURCE ${RESOURCE} PROPERTY MACOSX_PACKAGE_LOCATION ${_DESTINATION}) + endforeach (RESOURCE) + set(${VAR} ${_LIST} PARENT_SCOPE) +endfunction() + # Build and link the samples -macro(bl_sample NAME) +macro(bl_sample NAME SDIR) if (WIN32) add_executable(${NAME} WIN32 ${${NAME}_SRC_FILES} ${${NAME}_HDR_FILES} ) elseif(APPLE) - add_executable(${NAME} MACOSX_BUNDLE ${${NAME}_SRC_FILES} ${${NAME}_HDR_FILES} ) + resource(ASSETS ${SAMPLES_DIR}/assets Resources/assets *) + resource(DATA ${SAMPLES_DIR}${SDIR}/data Resources${SDIR}/data *) + resource(LUA ${SAMPLES_DIR}${SDIR}/lua Resources${SDIR}/lua *) + + set(RESOURCE_FILES ${ASSETS} ${DATA} ${LUA}) + + add_executable(${NAME} MACOSX_BUNDLE ${${NAME}_SRC_FILES} ${${NAME}_HDR_FILES} ${RESOURCE_FILES}) # The first rpath is to the proper location where the framework/library SHOULD be, the second is to the location actually seen # in the build environment @@ -705,7 +728,7 @@ if(BUILD_SAMPLES OR BUILD_TESTING) ) endif() - set(SAMPLES_DIR opt/RmlUi/Samples CACHE PATH "Path to samples directory.") + set(SAMPLES_DIR ${PROJECT_SOURCE_DIR}/Samples CACHE PATH "Path to samples directory.") if(WIN32) mark_as_advanced(SAMPLES_DIR) endif() @@ -863,7 +886,7 @@ if(BUILD_SAMPLES) # Build and install the basic samples foreach(sample ${samples}) - bl_sample(${sample} ${sample_LIBRARIES}) + bl_sample(${sample} /basic/${sample} ${sample_LIBRARIES} ) # The samples always set this as their current working directory install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/${sample}) @@ -875,7 +898,7 @@ if(BUILD_SAMPLES) # Build and install the tutorials foreach(tutorial ${tutorials}) set(tutorial_fullname tutorial_${tutorial}) - bl_sample(${tutorial_fullname} ${sample_LIBRARIES}) + bl_sample(${tutorial_fullname} /tutorial/${tutorial} ${sample_LIBRARIES}) # The tutorials always set this as their current working directory install(DIRECTORY DESTINATION ${SAMPLES_DIR}/tutorial/${tutorial}) @@ -885,14 +908,14 @@ if(BUILD_SAMPLES) endforeach() # Build and install invaders sample - bl_sample(invaders ${sample_LIBRARIES}) + bl_sample(invaders /invaders ${sample_LIBRARIES}) install(DIRECTORY DESTINATION ${SAMPLES_DIR}/invaders) install(TARGETS invaders RUNTIME DESTINATION ${SAMPLES_DIR}/invaders BUNDLE DESTINATION ${SAMPLES_DIR}) if(BUILD_LUA_BINDINGS) - bl_sample(luainvaders RmlLua ${sample_LIBRARIES} ${LUA_BINDINGS_LINK_LIBS}) + bl_sample(luainvaders /luainvaders RmlLua ${sample_LIBRARIES} ${LUA_BINDINGS_LINK_LIBS}) install(DIRECTORY DESTINATION ${SAMPLES_DIR}/luainvaders) install(TARGETS luainvaders RUNTIME DESTINATION ${SAMPLES_DIR}/luainvaders