1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00
transmission/dist/msi/UtilityFunctions.cmake
Mike Gelfand bc380511db
Modernize CMake code (ongoing refactoring) (#4507)
* Reformat CMake code

* Bump minimum CMake version to 3.12

* Add target sources separately via `target_source()`

* Make `tr_win32_app_info()` add target sources on its own

* Don't use `include_directories()`

* Don't use `add_definitions()`

* Limit use of `add_compile_options()`

* Move VDKQueue target declaration to a subdirectory

* Add `tr_disable_source_files_compile()` helper

* Add `tr_target_glib_resources()` helper

* Add `tr_gettext_msgfmt()` helper

* Enable AUTOUIC for Qt client

* Enable AUTORCC for Qt client

* Remove AUTO{MOC,RCC,UIC} source group overrides

* Add `tr_target_idl_files()` helper

* Move source group setup to `tr_qt_add_translation()`

* Add `tr_target_xib_files()` helper

* Prefer `target_sources()` to intermediate variables

* Use explicit visibility versions of `target_*()` commands

* Prefer genexes to conditions in `target_*()` commands

* Add `tr_allow_compile_if()` helper

* Leave only top-level `project()`, remove the rest

* Minor fixups

* Fixup Mac QL plugin install

* Fixup IDE target folders and source groups
2023-01-01 19:49:48 +00:00

111 lines
3.7 KiB
CMake

include(CMakeParseArguments)
function(find_msvc_crt_msm OUTPUT_VAR)
if(${OUTPUT_VAR})
return()
endif()
message(STATUS "Looking for a CRT MSM:")
set(MSM_FILE "Microsoft_VC${MSVC_TOOLSET_VERSION}_CRT_${ARCH}.msm")
message(STATUS " * File name: ${MSM_FILE}")
set(VC_DIR "${CMAKE_CXX_COMPILER}")
while(VC_DIR AND NOT VC_DIR MATCHES "/VC$")
get_filename_component(VC_DIR "${VC_DIR}" DIRECTORY)
endwhile()
message(STATUS " * VC directory: ${VC_DIR}")
file(GLOB VC_VER_DIRS "${VC_DIR}/Redist/MSVC/*")
message(STATUS " * Redist directories: ${VC_VER_DIRS}")
set(CMN_PF_DIR "CommonProgramFiles(x86)")
find_file(${OUTPUT_VAR}
NAMES "${MSM_FILE}"
PATHS
${VC_VER_DIRS}
$ENV{${CMN_PF_DIR}}
PATH_SUFFIXES
"MergeModules"
"Merge Modules")
message(STATUS " * Result: ${${OUTPUT_VAR}}")
set(${OUTPUT_VAR} "${${OUTPUT_VAR}}" PARENT_SCOPE)
endfunction()
function(wix_heat OUTPUT_FILE SOURCE_DIR CG_NAME DR_NAME VAR_NAME)
cmake_parse_arguments(HEAT "" "XSL_TRANSFORM" "" ${ARGN})
if(NOT IS_ABSOLUTE "${OUTPUT_FILE}")
set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_FILE}")
endif()
set(OPTIONS -nologo -sfrag -ag -srd -indent 2 -cg "${CG_NAME}" -dr "${DR_NAME}" -var "${VAR_NAME}")
set(DEPENDS "${SOURCE_DIR}")
if(HEAT_XSL_TRANSFORM)
if(NOT IS_ABSOLUTE "${HEAT_XSL_TRANSFORM}")
set(HEAT_XSL_TRANSFORM "${CMAKE_CURRENT_SOURCE_DIR}/${HEAT_XSL_TRANSFORM}")
endif()
list(APPEND OPTIONS -t "${HEAT_XSL_TRANSFORM}")
list(APPEND DEPENDS "${HEAT_XSL_TRANSFORM}")
endif()
add_custom_command(
OUTPUT "${OUTPUT_FILE}"
COMMAND heat dir "${SOURCE_DIR}" ${OPTIONS} -out "${OUTPUT_FILE}"
DEPENDS ${DEPENDS})
list(APPEND ${OUTPUT_VAR} "${OUTPUT_FILE}")
set(${OUTPUT_VAR} "${${OUTPUT_VAR}}" PARENT_SCOPE)
endfunction()
function(wix_candle OUTPUT_VAR)
cmake_parse_arguments(CANDLE "" "ARCHITECTURE" "SOURCES;EXTENSIONS;DEFINITIONS;EXTRA_DEPENDS" ${ARGN})
set(OPTIONS -nologo -pedantic -arch "${CANDLE_ARCHITECTURE}" "-I${CMAKE_CURRENT_BINARY_DIR}")
foreach(X ${CANDLE_EXTENSIONS})
list(APPEND OPTIONS -ext "${X}")
endforeach()
foreach(X ${CANDLE_DEFINITIONS})
list(APPEND OPTIONS "-d${X}")
endforeach()
foreach(F ${CANDLE_SOURCES})
if(NOT IS_ABSOLUTE "${F}")
set(F "${CMAKE_CURRENT_SOURCE_DIR}/${F}")
endif()
get_filename_component(F_NAME "${F}" NAME)
string(REGEX REPLACE "[.]wxs$" "" F_NAME "${F_NAME}")
set(CANDLE_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${F_NAME}.wixobj")
add_custom_command(
OUTPUT "${CANDLE_OUTPUT}"
COMMAND candle ${OPTIONS} "${F}" -out "${CANDLE_OUTPUT}"
DEPENDS
"${F}"
${CANDLE_EXTRA_DEPENDS})
list(APPEND ${OUTPUT_VAR} "${CANDLE_OUTPUT}")
endforeach()
set(${OUTPUT_VAR} "${${OUTPUT_VAR}}" PARENT_SCOPE)
endfunction()
function(wix_light OUTPUT_VAR)
cmake_parse_arguments(LIGHT "" "NAME" "OBJECTS;EXTENSIONS;EXTRA_DEPENDS" ${ARGN})
set(OPTIONS -nologo -pedantic -sw1076)
foreach(X ${LIGHT_EXTENSIONS})
list(APPEND OPTIONS -ext "${X}")
endforeach()
set(LIGHT_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${LIGHT_NAME}.msi")
add_custom_command(
OUTPUT ${LIGHT_OUTPUT}
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/${LIGHT_NAME}.wixpdb"
COMMAND light ${OPTIONS} -out "${CMAKE_CURRENT_BINARY_DIR}/${LIGHT_NAME}.msi" ${LIGHT_OBJECTS}
DEPENDS
${LIGHT_OBJECTS}
${LIGHT_EXTRA_DEPENDS})
list(APPEND ${OUTPUT_VAR} ${LIGHT_OUTPUT})
set(${OUTPUT_VAR} "${${OUTPUT_VAR}}" PARENT_SCOPE)
endfunction()