Skip to content

Commit

Permalink
Fixes for macOS building rlottie/samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan committed Oct 18, 2023
1 parent 8c7dd3f commit 93d08e8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Primary CMake build target
/Build/
/Dependencies/

# Other common build targets
/build*/
Expand Down
39 changes: 31 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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})
Expand All @@ -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})
Expand All @@ -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
Expand Down

0 comments on commit 93d08e8

Please sign in to comment.