Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake] Create one command for many resources in ADD_QGIS_RESOURCES #59232

Merged
merged 4 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions cmake/CopyResources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@
##
MACRO(ADD_QGIS_RESOURCES SOURCE_PREFIX TARGET_PREFIX DEST_FILES SOURCE_FILE_PATHS)

# On build copy all resource files to build folder
# Create a list of all copy commands, source paths and destination paths
SET(ALL_COPY_COMMANDS "")
SET(ALL_SOURCE_FILES "")
FOREACH(RESOURCE_FILE ${SOURCE_FILE_PATHS})
ADD_CUSTOM_COMMAND(
OUTPUT "${CMAKE_BINARY_DIR}/output/data/${TARGET_PREFIX}/${RESOURCE_FILE}"
LIST(APPEND ALL_COPY_COMMANDS
COMMAND ${CMAKE_COMMAND} -E copy
"${SOURCE_PREFIX}/${RESOURCE_FILE}"
"${CMAKE_BINARY_DIR}/output/data/${TARGET_PREFIX}/${RESOURCE_FILE}"
DEPENDS "${SOURCE_PREFIX}/${RESOURCE_FILE}"
)
LIST(APPEND ALL_SOURCE_FILES "${SOURCE_PREFIX}/${RESOURCE_FILE}")
LIST(APPEND ${DEST_FILES}
"${CMAKE_BINARY_DIR}/output/data/${TARGET_PREFIX}/${RESOURCE_FILE}")
ENDFOREACH(RESOURCE_FILE)

# Add a single custom command to install all resources to system resource folder
ADD_CUSTOM_COMMAND(
OUTPUT ${${DEST_FILES}}
${ALL_COPY_COMMANDS}
COMMENT "Copying '${TARGET_PREFIX}' resources"
DEPENDS ${ALL_SOURCE_FILES}
)

# Install resources to system resource folder
FOREACH(RESOURCE_FILE ${SOURCE_FILE_PATHS})
GET_FILENAME_COMPONENT(PATH_NAME "${TARGET_PREFIX}/${RESOURCE_FILE}" PATH)
Expand Down
32 changes: 30 additions & 2 deletions resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ if (HAVE_OPENCL)
endif()

# Server, also install server subdirectory
SET(SERVER_DEST_RESOURCE_FILES "")
nyalldawson marked this conversation as resolved.
Show resolved Hide resolved
if (WITH_SERVER)
file(GLOB_RECURSE SERVER_RESOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} server/*)
set(RESOURCES_FILES ${RESOURCES_FILES} ${SERVER_RESOURCE_FILES})
ADD_QGIS_RESOURCES("${CMAKE_CURRENT_SOURCE_DIR}" resources SERVER_DEST_RESOURCE_FILES "${SERVER_RESOURCE_FILES}")
nyalldawson marked this conversation as resolved.
Show resolved Hide resolved
endif()

# Server landingpage webapp
Expand All @@ -43,6 +44,32 @@ if (WITH_SERVER_LANDINGPAGE_WEBAPP)

add_custom_target (server_landingpage ALL DEPENDS ${LANDINGPAGE_OUTPUT_PATH}/landingpage.stamp)

# add_custom_command does not support OUTPUT_QUIET, so we need to make a cmake subcommand first:
file(WRITE ${CMAKE_BINARY_DIR}/yarn_commands.cmake
"execute_process(
COMMAND ${YARN} install --frozen-lockfile
WORKING_DIRECTORY ${LANDINGPAGE_OUTPUT_PATH}
OUTPUT_QUIET
ERROR_FILE ${CMAKE_BINARY_DIR}/yarn_error.log
RESULT_VARIABLE YARN_RESULT
)
if(NOT YARN_RESULT EQUAL 0)
file(READ ${CMAKE_BINARY_DIR}/yarn_error.log ERROR_CONTENTS)
message(FATAL_ERROR \${ERROR_CONTENTS})
endif()

execute_process(
COMMAND ${YARN} build
WORKING_DIRECTORY ${LANDINGPAGE_OUTPUT_PATH}
OUTPUT_QUIET
ERROR_FILE ${CMAKE_BINARY_DIR}/yarn_error.log
RESULT_VARIABLE YARN_RESULT
)
if(NOT YARN_RESULT EQUAL 0)
file(READ ${CMAKE_BINARY_DIR}/yarn_error.log ERROR_CONTENTS)
message(FATAL_ERROR \${ERROR_CONTENTS})
endif()
")
add_custom_command(
POST_BUILD
OUTPUT ${LANDINGPAGE_OUTPUT_PATH}/landingpage.stamp
Expand All @@ -51,7 +78,7 @@ if (WITH_SERVER_LANDINGPAGE_WEBAPP)
${CMAKE_CURRENT_SOURCE_DIR}/server/src/landingpage/
${LANDINGPAGE_OUTPUT_PATH}/
COMMAND ${CMAKE_COMMAND} -E touch ${LANDINGPAGE_OUTPUT_PATH}/landingpage.stamp
COMMAND cd ${LANDINGPAGE_OUTPUT_PATH} && ${YARN} install --frozen-lockfile && ${YARN} build
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/yarn_commands.cmake
)
endif()

Expand All @@ -77,4 +104,5 @@ list(APPEND DEST_RESOURCE_FILES
"${CMAKE_CURRENT_BINARY_DIR}/srs.db")
install(FILES ${SRSDB} DESTINATION ${QGIS_DATA_DIR}/resources RENAME srs.db)

list(APPEND DEST_RESOURCE_FILES ${SERVER_DEST_RESOURCE_FILES})
add_custom_target(resources ALL DEPENDS ${DEST_RESOURCE_FILES})