Skip to content

Commit

Permalink
Use CPack to create a release package on windows (simulationcraft#6501)
Browse files Browse the repository at this point in the history
Tries to mirror the current nightly to some degree (Version number separator is different), and also better structures windeployqt
  • Loading branch information
scamille authored Apr 1, 2022
1 parent 38cf4e4 commit 8d553bf
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 17 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ function(sc_common_compiler_options target)
)
endfunction()


### Git Hash ###
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# link in all activated targets
add_subdirectory(engine)
if (BUILD_GUI)
Expand Down Expand Up @@ -76,3 +93,5 @@ install(FILES
LICENSE.MIT
LICENSE.UNLICENSE
DESTINATION ${SIMC_INSTALL_SHARED})

include(${PROJECT_SOURCE_DIR}/cmake/package.cmake)
31 changes: 31 additions & 0 deletions cmake/package.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use Cpack for packaging Simc
# This can be used to package eg. a nightly release

# Parse version from config file
file(READ "${PROJECT_SOURCE_DIR}/engine/config.hpp" SC_CONFIG_FILE_CONTENT)
string(REGEX MATCH "SC_MAJOR_VERSION \"([0-9]*)\"" SC_MAJOR_VERSION_MATCH ${SC_CONFIG_FILE_CONTENT})
if (SC_MAJOR_VERSION_MATCH)
message(VERBOSE "Simc major version: ${CMAKE_MATCH_1}")
set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
endif()
string(REGEX MATCH "SC_MINOR_VERSION \"([0-9]*)\"" SC_MINOR_VERSION_MATCH ${SC_CONFIG_FILE_CONTENT})
if (SC_MINOR_VERSION_MATCH)
message(VERBOSE "Simc minor version: ${CMAKE_MATCH_1}")
set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_1})
endif()
message(VERBOSE "Simc git hash: ${GIT_COMMIT_HASH}")
set(CPACK_PACKAGE_VERSION_PATCH ${GIT_COMMIT_HASH})

# Global options
set(CPACK_PACKAGE_VENDOR "SimulationCraft")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.simulationcraft.org/")
set(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/qt/icon/Simcraft2.ico")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")

if(WIN32)
set(CPACK_GENERATOR "7Z")
endif()

include(CPack)
27 changes: 27 additions & 0 deletions cmake/windeployqt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

function(windeployqt target)
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}" REQUIRED)

# Bundle Library Files
if(CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
set(WINDEPLOYQT_ARGS --debug)
else()
set(WINDEPLOYQT_ARGS --release)
endif()

message(VERBOSE "WINDEPLOYQT_EXECUTABLE ${WINDEPLOYQT_EXECUTABLE}")

add_custom_command(TARGET ${target} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/winqt/"
COMMAND "${CMAKE_COMMAND}" -E
env PATH="${_qt_bin_dir}" "${WINDEPLOYQT_EXECUTABLE}"
${WINDEPLOYQT_ARGS}
--verbose 0
--no-compiler-runtime
--no-translations
--dir "${CMAKE_CURRENT_BINARY_DIR}/winqt/"
$<TARGET_FILE:${target}>
COMMENT "Deploying Qt..."
)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/winqt/" DESTINATION ${SIMC_INSTALL_BIN})
endfunction()
16 changes: 0 additions & 16 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,6 @@ if(NOT SC_NO_NETWORKING)
endif()
endif()

### Git Hash ###
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

target_compile_definitions(engine PRIVATE "SC_GIT_REV=\"${GIT_COMMIT_HASH}\"" "SC_GIT_BRANCH=\"${GIT_BRANCH}\"")

add_custom_target(file_toucher
Expand Down
8 changes: 7 additions & 1 deletion qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebEngineCore REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebEngineWidgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS LinguistTools QUIET)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
Expand Down Expand Up @@ -63,4 +64,9 @@ install(FILES
locale/sc_cn.qm
locale/sc_it.qm
locale/sc_ko.qm
DESTINATION ${SIMC_INSTALL_SHARED}/locale)
DESTINATION ${SIMC_INSTALL_SHARED}/locale)

if(WIN32)
include(${PROJECT_SOURCE_DIR}/cmake/windeployqt.cmake)
windeployqt(SimulationCraft)
endif()

0 comments on commit 8d553bf

Please sign in to comment.