mirror of
https://github.com/transmission/transmission
synced 2024-12-21 23:32:35 +00:00
Minor CMake maintainability improvements (#6186)
* Prefer `PROJECT_{SOURCE,BINARY}_DIR` to `CMAKE_` ones * Extend use of 3rd-party dir vars to reduce duplication * Fix typo in submodule repo name * Remove `CURL::libcurl` target fallback The target is always available since CMake 3.12, which is our current minimum version.
This commit is contained in:
parent
c697d95ad3
commit
1c421d6d23
17 changed files with 51 additions and 56 deletions
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -54,6 +54,6 @@
|
|||
path = third-party/rapidjson
|
||||
url = https://github.com/transmission/rapidjson.git
|
||||
fetchRecurseSubmodules = false
|
||||
[submodule "third-party/rapavlik-cmake-modules"]
|
||||
path = third-party/rapavlik-cmake-modules
|
||||
[submodule "third-party/rpavlik-cmake-modules"]
|
||||
path = third-party/rpavlik-cmake-modules
|
||||
url = https://github.com/transmission/rpavlik-cmake-modules.git
|
||||
|
|
|
@ -20,7 +20,13 @@ endif()
|
|||
|
||||
project(transmission)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
||||
set(TR_THIRD_PARTY_DIR_NAME third-party)
|
||||
set(TR_THIRD_PARTY_SOURCE_DIR ${PROJECT_SOURCE_DIR}/${TR_THIRD_PARTY_DIR_NAME})
|
||||
set(TR_THIRD_PARTY_BINARY_DIR ${PROJECT_BINARY_DIR}/${TR_THIRD_PARTY_DIR_NAME})
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH
|
||||
"${PROJECT_SOURCE_DIR}/cmake"
|
||||
"${TR_THIRD_PARTY_SOURCE_DIR}/rpavlik-cmake-modules")
|
||||
|
||||
set(CMAKE_MACOSX_RPATH ON)
|
||||
|
||||
|
@ -142,11 +148,9 @@ else()
|
|||
endif()
|
||||
string(APPEND TR_PEER_ID_PREFIX "-")
|
||||
|
||||
set(TR_VCS_REVISION_FILE "${CMAKE_SOURCE_DIR}/REVISION")
|
||||
set(TR_VCS_REVISION_FILE "${PROJECT_SOURCE_DIR}/REVISION")
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/third-party/rapavlik-cmake-modules")
|
||||
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/.git)
|
||||
if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
|
||||
find_package(Git)
|
||||
endif()
|
||||
|
||||
|
@ -204,7 +208,8 @@ if(WIN32)
|
|||
endforeach()
|
||||
endif()
|
||||
|
||||
set(CMAKE_FOLDER "third-party")
|
||||
set(CMAKE_FOLDER "${TR_THIRD_PARTY_DIR_NAME}")
|
||||
|
||||
find_package(FastFloat)
|
||||
find_package(Fmt)
|
||||
find_package(RapidJSON)
|
||||
|
@ -216,11 +221,6 @@ find_package(Threads)
|
|||
find_package(PkgConfig QUIET)
|
||||
|
||||
find_package(CURL ${CURL_MINIMUM} REQUIRED)
|
||||
if(NOT TARGET CURL::libcurl)
|
||||
add_library(CURL::libcurl INTERFACE IMPORTED)
|
||||
target_link_libraries(CURL::libcurl INTERFACE ${CURL_LIBRARIES})
|
||||
target_include_directories(CURL::libcurl INTERFACE ${CURL_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
if(ENABLE_DEPRECATED STREQUAL "AUTO")
|
||||
if(DEFINED ENV{CI})
|
||||
|
@ -457,8 +457,6 @@ if(ENABLE_MAC)
|
|||
tr_fixup_auto_option(ENABLE_MAC MAC_FOUND MAC_IS_REQUIRED)
|
||||
endif()
|
||||
|
||||
set(THIRD_PARTY_DIR ${CMAKE_SOURCE_DIR}/third-party)
|
||||
|
||||
if(WIN32 AND NOT MINGW)
|
||||
set(DEFLATE_LIB_NAME deflatestatic)
|
||||
else()
|
||||
|
@ -508,7 +506,7 @@ target_compile_definitions(miniupnpc::libminiupnpc
|
|||
SYSTEM_MINIUPNP
|
||||
$<$<VERSION_LESS:${MINIUPNPC_VERSION},1.7>:MINIUPNPC_API_VERSION=${MINIUPNPC_API_VERSION}>) # API version macro was only added in 1.7
|
||||
|
||||
add_subdirectory(third-party/wildmat)
|
||||
add_subdirectory(${TR_THIRD_PARTY_SOURCE_DIR}/wildmat)
|
||||
|
||||
tr_add_external_auto_library(DHT dht dht
|
||||
TARGET dht::dht)
|
||||
|
@ -530,7 +528,7 @@ tr_add_external_auto_library(B64 libb64 b64
|
|||
CMAKE_ARGS
|
||||
-DLIBB64_SHARED:BOOL=OFF)
|
||||
|
||||
set(TR_WEB_ASSETS ${CMAKE_SOURCE_DIR}/web/public_html)
|
||||
set(TR_WEB_ASSETS ${PROJECT_SOURCE_DIR}/web/public_html)
|
||||
if(NOT ${REBUILD_WEB} STREQUAL "OFF")
|
||||
find_program(NPM npm)
|
||||
if ("${NPM}" STREQUAL "NPM-NOTFOUND")
|
||||
|
@ -830,7 +828,7 @@ if(NOT TR_STABLE_RELEASE AND NOT "${TR_VCS_REVISION}" STREQUAL "")
|
|||
string(APPEND CPACK_SOURCE_PACKAGE_FILE_NAME "+r${TR_VCS_REVISION}")
|
||||
endif()
|
||||
list(APPEND CPACK_SOURCE_IGNORE_FILES
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${PROJECT_BINARY_DIR}"
|
||||
"[.]git"
|
||||
"node_modules")
|
||||
|
||||
|
@ -839,17 +837,17 @@ list(APPEND CPACK_SOURCE_IGNORE_FILES
|
|||
if(GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" rev-parse --show-toplevel
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE TR_GIT_ROOT
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(TR_GIT_ROOT AND IS_DIRECTORY "${TR_GIT_ROOT}/.git")
|
||||
configure_file("${CMAKE_SOURCE_DIR}/extras/pre-commit" "${TR_GIT_ROOT}/.git/hooks/pre-commit" COPYONLY)
|
||||
configure_file("${PROJECT_SOURCE_DIR}/extras/pre-commit" "${TR_GIT_ROOT}/.git/hooks/pre-commit" COPYONLY)
|
||||
add_custom_target(check-format
|
||||
COMMAND "${CMAKE_SOURCE_DIR}/code_style.sh" --check
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
|
||||
COMMAND "${PROJECT_SOURCE_DIR}/code_style.sh" --check
|
||||
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
|
||||
add_custom_target(format
|
||||
COMMAND "${CMAKE_SOURCE_DIR}/code_style.sh"
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
|
||||
COMMAND "${PROJECT_SOURCE_DIR}/code_style.sh"
|
||||
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
|
||||
set_property(
|
||||
TARGET check-format format
|
||||
PROPERTY FOLDER "utility")
|
||||
|
|
|
@ -2,4 +2,4 @@ add_library(FastFloat::fast_float INTERFACE IMPORTED)
|
|||
|
||||
target_include_directories(FastFloat::fast_float
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../third-party/fast_float/include)
|
||||
${TR_THIRD_PARTY_SOURCE_DIR}/fast_float/include)
|
||||
|
|
|
@ -2,7 +2,7 @@ add_library(fmt::fmt-header-only INTERFACE IMPORTED)
|
|||
|
||||
target_include_directories(fmt::fmt-header-only
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../third-party/fmt/include)
|
||||
${TR_THIRD_PARTY_SOURCE_DIR}/fmt/include)
|
||||
|
||||
target_compile_definitions(fmt::fmt-header-only
|
||||
INTERFACE
|
||||
|
|
|
@ -2,7 +2,7 @@ add_library(RapidJSON INTERFACE IMPORTED)
|
|||
|
||||
target_include_directories(RapidJSON
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../third-party/rapidjson/include)
|
||||
${TR_THIRD_PARTY_SOURCE_DIR}/rapidjson/include)
|
||||
|
||||
target_compile_definitions(RapidJSON
|
||||
INTERFACE
|
||||
|
|
|
@ -2,8 +2,7 @@ add_library(small::small INTERFACE IMPORTED)
|
|||
|
||||
target_include_directories(small::small
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../third-party/small/include)
|
||||
|
||||
${TR_THIRD_PARTY_SOURCE_DIR}/small/include)
|
||||
|
||||
target_compile_definitions(small::small
|
||||
INTERFACE
|
||||
|
|
|
@ -2,4 +2,4 @@ add_library(utf8::cpp INTERFACE IMPORTED)
|
|||
|
||||
target_include_directories(utf8::cpp
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../third-party/utfcpp/source)
|
||||
${TR_THIRD_PARTY_SOURCE_DIR}/utfcpp/source)
|
||||
|
|
|
@ -2,4 +2,4 @@ add_library(WideInteger::WideInteger INTERFACE IMPORTED)
|
|||
|
||||
target_include_directories(WideInteger::WideInteger
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../third-party/wide-integer)
|
||||
${TR_THIRD_PARTY_SOURCE_DIR}/wide-integer)
|
||||
|
|
|
@ -88,10 +88,10 @@ macro(tr_eval SCRIPT)
|
|||
|
||||
string(SHA1 _TR_EVAL_TMP_FILE "${_TR_EVAL_SCRIPT}")
|
||||
string(SUBSTRING "${_TR_EVAL_TMP_FILE}" 0 10 _TR_EVAL_TMP_FILE)
|
||||
set(_TR_EVAL_TMP_FILE "${CMAKE_BINARY_DIR}/.tr-cache/tr_eval.${_TR_EVAL_TMP_FILE}.cmake")
|
||||
set(_TR_EVAL_TMP_FILE "${PROJECT_BINARY_DIR}/.tr-cache/tr_eval.${_TR_EVAL_TMP_FILE}.cmake")
|
||||
|
||||
if(NOT EXISTS "${_TR_EVAL_TMP_FILE}")
|
||||
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/.tr-cache")
|
||||
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/.tr-cache")
|
||||
file(WRITE "${_TR_EVAL_TMP_FILE}" "${_TR_EVAL_SCRIPT}")
|
||||
endif()
|
||||
|
||||
|
@ -145,10 +145,10 @@ macro(tr_add_external_auto_library ID DIRNAME LIBNAME)
|
|||
set(${CMAKE_MATCH_1} ${CMAKE_MATCH_3} CACHE INTERNAL "")
|
||||
endif()
|
||||
endforeach()
|
||||
add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/${DIRNAME}" "${CMAKE_BINARY_DIR}/third-party/${DIRNAME}.bld")
|
||||
add_subdirectory("${TR_THIRD_PARTY_SOURCE_DIR}/${DIRNAME}" "${TR_THIRD_PARTY_BINARY_DIR}/${DIRNAME}.bld")
|
||||
else()
|
||||
set(${ID}_UPSTREAM_TARGET ${LIBNAME})
|
||||
set(${ID}_PREFIX "${CMAKE_BINARY_DIR}/third-party/${DIRNAME}.bld/pfx")
|
||||
set(${ID}_PREFIX "${TR_THIRD_PARTY_BINARY_DIR}/${DIRNAME}.bld/pfx")
|
||||
|
||||
set(${ID}_INCLUDE_DIR "${${ID}_PREFIX}/include"
|
||||
CACHE INTERNAL "")
|
||||
|
@ -169,8 +169,8 @@ macro(tr_add_external_auto_library ID DIRNAME LIBNAME)
|
|||
|
||||
ExternalProject_Add(
|
||||
${${ID}_UPSTREAM_TARGET}
|
||||
PREFIX "${CMAKE_BINARY_DIR}/third-party/${DIRNAME}.bld"
|
||||
SOURCE_DIR "${CMAKE_SOURCE_DIR}/third-party/${DIRNAME}"
|
||||
PREFIX "${TR_THIRD_PARTY_BINARY_DIR}/${DIRNAME}.bld"
|
||||
SOURCE_DIR "${TR_THIRD_PARTY_SOURCE_DIR}/${DIRNAME}"
|
||||
INSTALL_DIR "${${ID}_PREFIX}"
|
||||
CMAKE_ARGS
|
||||
-Wno-dev # We don't want to be warned over unused variables
|
||||
|
@ -188,7 +188,7 @@ macro(tr_add_external_auto_library ID DIRNAME LIBNAME)
|
|||
${_TAEAL_ARG_CMAKE_ARGS}
|
||||
BUILD_BYPRODUCTS "${${ID}_LIBRARY}")
|
||||
|
||||
set_property(TARGET ${${ID}_UPSTREAM_TARGET} PROPERTY FOLDER "third-party")
|
||||
set_property(TARGET ${${ID}_UPSTREAM_TARGET} PROPERTY FOLDER "${TR_THIRD_PARTY_DIR_NAME}")
|
||||
|
||||
# Imported target (below) requires include directories to be present at configuration time
|
||||
file(MAKE_DIRECTORY ${${ID}_INCLUDE_DIRS})
|
||||
|
@ -275,7 +275,7 @@ function(tr_win32_app_info TGT DESCR INTNAME ORIGFNAME)
|
|||
set(TR_MAIN_ICON "${ARGN}")
|
||||
endif()
|
||||
|
||||
configure_file("${CMAKE_SOURCE_DIR}/cmake/Transmission.rc.in" "${INTNAME}-app-info.rc")
|
||||
configure_file("${PROJECT_SOURCE_DIR}/cmake/Transmission.rc.in" "${INTNAME}-app-info.rc")
|
||||
|
||||
target_sources(${TGT}
|
||||
PRIVATE
|
||||
|
@ -437,7 +437,7 @@ function(tr_gettext_msgfmt TGT OUTPUT_FILE INPUT_FILE)
|
|||
|
||||
add_custom_command(
|
||||
OUTPUT ${OUTPUT_FILE}
|
||||
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} ${MODE_ARG} -d ${CMAKE_SOURCE_DIR}/po --template ${INPUT_FILE} -o ${OUTPUT_FILE}
|
||||
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} ${MODE_ARG} -d ${PROJECT_SOURCE_DIR}/po --template ${INPUT_FILE} -o ${OUTPUT_FILE}
|
||||
DEPENDS ${INPUT_FILE}
|
||||
VERBATIM)
|
||||
|
||||
|
@ -471,7 +471,7 @@ function(tr_wrap_idl TGT INPUT_FILE OUTPUT_FILE_BASE)
|
|||
DEPENDS ${INPUT_FILE}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
configure_file("${CMAKE_SOURCE_DIR}/cmake/Transmission.tlb.rc.in" ${OUTPUT_FILE_BASE}.tlb.rc)
|
||||
configure_file("${PROJECT_SOURCE_DIR}/cmake/Transmission.tlb.rc.in" ${OUTPUT_FILE_BASE}.tlb.rc)
|
||||
|
||||
target_sources(${TGT}
|
||||
PRIVATE
|
||||
|
|
2
dist/msi/CMakeLists.txt
vendored
2
dist/msi/CMakeLists.txt
vendored
|
@ -58,7 +58,7 @@ else()
|
|||
endif()
|
||||
|
||||
file(
|
||||
COPY "${CMAKE_SOURCE_DIR}/qt/icons/transmission.ico"
|
||||
COPY "${PROJECT_SOURCE_DIR}/qt/icons/transmission.ico"
|
||||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(WEBSRCDIR "${CMAKE_INSTALL_PREFIX}/share/transmission/public_html")
|
||||
|
|
|
@ -448,7 +448,7 @@ install(
|
|||
tr_install_web(Applications/${MAC_BUNDLE_NAME}.app/Contents/Resources)
|
||||
|
||||
install(CODE
|
||||
"list(APPEND CMAKE_MODULE_PATH \"${CMAKE_SOURCE_DIR}/cmake\")
|
||||
"list(APPEND CMAKE_MODULE_PATH \"${PROJECT_SOURCE_DIR}/cmake\")
|
||||
include(TrMacros)
|
||||
include(GetPrerequisites)
|
||||
tr_fixup_bundle_item(
|
||||
|
|
|
@ -91,7 +91,7 @@ install(
|
|||
DESTINATION Applications/${MAC_BUNDLE_NAME}.app/Contents/Library/QuickLook)
|
||||
|
||||
install(CODE
|
||||
"list(APPEND CMAKE_MODULE_PATH \"${CMAKE_SOURCE_DIR}/cmake\")
|
||||
"list(APPEND CMAKE_MODULE_PATH \"${PROJECT_SOURCE_DIR}/cmake\")
|
||||
include(TrMacros)
|
||||
include(GetPrerequisites)
|
||||
tr_fixup_bundle_item(
|
||||
|
|
|
@ -7,7 +7,7 @@ target_sources(vdkqueue
|
|||
|
||||
set_property(
|
||||
TARGET vdkqueue
|
||||
PROPERTY FOLDER "third-party")
|
||||
PROPERTY FOLDER "${TR_THIRD_PARTY_DIR_NAME}")
|
||||
|
||||
target_include_directories(vdkqueue
|
||||
PUBLIC
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
set(GTEST_ROOT_DIR ${TR_THIRD_PARTY_SOURCE_DIR}/googletest/googletest)
|
||||
|
||||
add_library(gtestall STATIC)
|
||||
|
||||
target_sources(gtestall
|
||||
PRIVATE
|
||||
${THIRD_PARTY_DIR}/googletest/googletest/src/gtest-all.cc
|
||||
${THIRD_PARTY_DIR}/googletest/googletest/src/gtest_main.cc)
|
||||
${GTEST_ROOT_DIR}/src/gtest-all.cc
|
||||
${GTEST_ROOT_DIR}/src/gtest_main.cc)
|
||||
|
||||
set_property(
|
||||
TARGET gtestall
|
||||
PROPERTY FOLDER "third-party")
|
||||
PROPERTY FOLDER "${TR_THIRD_PARTY_DIR_NAME}")
|
||||
|
||||
target_include_directories(gtestall SYSTEM
|
||||
PRIVATE
|
||||
${THIRD_PARTY_DIR}/googletest/googletest
|
||||
${GTEST_ROOT_DIR}
|
||||
PUBLIC
|
||||
${THIRD_PARTY_DIR}/googletest/googletest/include)
|
||||
${GTEST_ROOT_DIR}/include)
|
||||
|
|
|
@ -107,10 +107,6 @@ set_property(
|
|||
TARGET subprocess-test
|
||||
PROPERTY FOLDER "tests")
|
||||
|
||||
target_include_directories(subprocess-test
|
||||
PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/libtransmission)
|
||||
|
||||
target_link_libraries(subprocess-test
|
||||
PRIVATE
|
||||
${TR_NAME})
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
// or any future license endorsed by Mnemosyne LLC.
|
||||
// License text can be found in the licenses/ folder.
|
||||
|
||||
#include "file.h" // tr_sys_file_write_line(), tr_sys_file_close(), tr_sy...
|
||||
#include "utils.h" // tr_env_get_string()
|
||||
#include <libtransmission/file.h> // tr_sys_file_write_line(), tr_sys_file_close(), tr_sy...
|
||||
#include <libtransmission/utils.h> // tr_env_get_string()
|
||||
|
||||
#include <string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue