1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-28 10:38:45 +00:00
transmission/cmake/TrMacros.cmake
Charles Kerr abac811dd2
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings

* fix: implicit fallthrough warning

* fixup! fix: implicit fallthrough warning

* fix: disable warnings for 3rd party code

Since we want to leave upstream code as-is

* fixup! fix: disable warnings for 3rd party code

* fixup! fix: disable warnings for 3rd party code

* silence spurious alignment warning

Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: 90ac46f710/f/src/util/util_safealign.h (_35)

* fixup! fix: disable warnings for 3rd party code

* fixup! fix: implicit fallthrough warning

* make uncrustify happy

* remove uncrustify-test.sh

that's probably off-topic for this PR

* fixup! fix: __attribute__(__printf__) warnings

* Update libtransmission/CMakeLists.txt

Co-Authored-By: ckerr <ckerr@github.com>

* fixup! silence spurious alignment warning

* use -w for DISABLE_WARNINGS in Clang

* refactor: fix libtransmission deprecation warnings

* fix: pthread_create's start_routine's return value

This was defined as `void` on non-Windows but should have been `void*`

* chore: uncrustify

* fix: add DISABLE_WARNINGS option for SunPro Studio

* fix "unused in lambda capture" warnings by clang++

* fix 'increases required alignment' warning

Caused from storing int16_t's in a char array.

* fix net.c 'increases required alignment' warning

The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.

* make building quieter so warnings are more visible

* fixup! fix 'increases required alignment' warning

* Fix -Wcast-function-type warnings in GTK+ app code

https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.

GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.

Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.

In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).

* fixup! fix "unused in lambda capture" warnings by clang++

* fixup! fix "unused in lambda capture" warnings by clang++

* fix two more libtransmission compiler warnings

* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 11:27:03 -06:00

198 lines
7.4 KiB
CMake

macro(tr_auto_option_changed NAME ACC VAL FIL STK)
if(NOT ("${VAL}" STREQUAL "AUTO" OR "${VAL}" STREQUAL "ON" OR "${VAL}" STREQUAL "OFF"))
if("${VAL}" STREQUAL "0" OR "${VAL}" STREQUAL "NO" OR "${VAL}" STREQUAL "FALSE" OR "${VAL}" STREQUAL "N")
set_property(CACHE ${NAME} PROPERTY VALUE OFF)
elseif("${VAL}" MATCHES "^[-+]?[0-9]+$" OR "${VAL}" STREQUAL "YES" OR "${VAL}" STREQUAL "TRUE" OR "${VAL}" STREQUAL "Y")
set_property(CACHE ${NAME} PROPERTY VALUE ON)
else()
message(FATAL_ERROR "Option '${NAME}' set to unrecognized value '${VAL}'. Should be boolean or 'AUTO'.")
endif()
endif()
endmacro()
macro(tr_auto_option NAME DESC VAL)
set(${NAME} "${VAL}" CACHE STRING "${DESC}")
set_property(CACHE ${NAME} PROPERTY STRINGS "AUTO;ON;OFF")
variable_watch(${NAME} tr_auto_option_changed)
endmacro()
macro(tr_fixup_auto_option NAME ISFOUND ISREQ)
if(${ISFOUND})
set_property(CACHE ${NAME} PROPERTY VALUE ON)
elseif(NOT (${ISREQ}))
set_property(CACHE ${NAME} PROPERTY VALUE OFF)
endif()
endmacro()
function(tr_list_option_changed NAME ACC VAL FIL STK)
get_property(VAR_STRINGS CACHE ${NAME} PROPERTY STRINGS)
string(TOUPPER "${VAL}" VAL_UPCASE)
foreach(X ${VAR_STRINGS})
string(TOUPPER "${X}" X_UPCASE)
if("${VAL_UPCASE}" STREQUAL "${X_UPCASE}")
if(NOT "${VAL}" STREQUAL "${X}")
set_property(CACHE ${NAME} PROPERTY VALUE "${X}")
message(STATUS ">>> (list) ${NAME} -> ${X}")
endif()
return()
endif()
endforeach()
string(REPLACE ";" "', '" VAR_STRINGS "${VAR_STRINGS}")
message(FATAL_ERROR "Option '${NAME}' set to unrecognized value '${VAL}'. Should be one of '${VAR_STRINGS}'.")
endfunction()
macro(tr_list_option NAME DESC VAL)
set(${NAME} "${VAL}" CACHE STRING "${DESC}")
set_property(CACHE ${NAME} PROPERTY STRINGS "${VAL};${ARGN}")
variable_watch(${NAME} tr_list_option_changed)
endmacro()
macro(tr_fixup_list_option NAME FVAL ISFOUND RVAL ISREQ)
if(${ISFOUND})
set_property(CACHE ${NAME} PROPERTY VALUE "${FVAL}")
elseif(NOT (${ISREQ}))
set_property(CACHE ${NAME} PROPERTY VALUE "${RVAL}")
endif()
endmacro()
macro(tr_get_required_flag IVAR OVAR)
set(${OVAR})
if (${IVAR} AND NOT ${IVAR} STREQUAL "AUTO")
set(${OVAR} REQUIRED)
endif()
endmacro()
function(tr_make_id INPUT OVAR)
string(TOUPPER "${INPUT}" ID)
string(REGEX REPLACE "[^A-Z0-9]+" "_" ID "${ID}")
# string(REGEX REPLACE "^_+|_+$" "" ID "${ID}")
set(${OVAR} "${ID}" PARENT_SCOPE)
endfunction()
macro(tr_add_external_auto_library ID DIRNAME LIBNAME)
if(USE_SYSTEM_${ID})
tr_get_required_flag(USE_SYSTEM_${ID} SYSTEM_${ID}_IS_REQUIRED)
find_package(${ID} ${${ID}_MINIMUM} ${SYSTEM_${ID}_IS_REQUIRED})
tr_fixup_auto_option(USE_SYSTEM_${ID} ${ID}_FOUND SYSTEM_${ID}_IS_REQUIRED)
endif()
if(USE_SYSTEM_${ID})
unset(${ID}_UPSTREAM_TARGET)
else()
set(${ID}_UPSTREAM_TARGET ${LIBNAME})
set(${ID}_PREFIX "${CMAKE_BINARY_DIR}/third-party/${${ID}_UPSTREAM_TARGET}")
set(${ID}_INCLUDE_DIR "${${ID}_PREFIX}/include" CACHE INTERNAL "")
set(${ID}_LIBRARY "${${ID}_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${LIBNAME}${CMAKE_STATIC_LIBRARY_SUFFIX}" CACHE INTERNAL "")
set(${ID}_INCLUDE_DIRS ${${ID}_INCLUDE_DIR})
set(${ID}_LIBRARIES ${${ID}_LIBRARY})
ExternalProject_Add(
${${ID}_UPSTREAM_TARGET}
URL "${CMAKE_SOURCE_DIR}/third-party/${DIRNAME}"
${ARGN}
PREFIX "${${ID}_PREFIX}"
CMAKE_ARGS
-Wno-dev # We don't want to be warned over unused variables
"-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}"
"-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE}"
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
"-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}"
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
"-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>"
BUILD_BYPRODUCTS "${${ID}_LIBRARY}"
)
set_property(TARGET ${${ID}_UPSTREAM_TARGET} PROPERTY FOLDER "ThirdParty")
endif()
endmacro()
function(tr_append_target_property TGT PROP VAL)
get_target_property(OVAL ${TGT} ${PROP})
if(OVAL)
set(VAL "${OVAL} ${VAL}")
endif()
set_target_properties(${TGT} PROPERTIES ${PROP} "${VAL}")
endfunction()
function(tr_win32_app_info OVAR DESCR INTNAME ORIGFNAME)
if(NOT WIN32)
return()
endif()
set(TR_FILE_DESCRIPTION "${DESCR}")
set(TR_INTERNAL_NAME "${INTNAME}")
set(TR_ORIGINAL_FILENAME "${ORIGFNAME}")
if(ARGN)
set(TR_MAIN_ICON "${ARGN}")
endif()
configure_file("${CMAKE_SOURCE_DIR}/cmake/Transmission.rc.in" "${INTNAME}-app-info.rc")
set(${OVAR} "${CMAKE_CURRENT_BINARY_DIR}/${INTNAME}-app-info.rc" PARENT_SCOPE)
endfunction()
function(tr_select_library LIBNAMES FUNCNAME DIRS OVAR)
set(LIBNAME)
foreach(X ${LIBNAMES})
set(VAR_NAME "HAVE_${FUNCNAME}_IN_LIB${X}")
string(TOUPPER "${VAR_NAME}" VAR_NAME)
check_library_exists("${X}" "${FUNCNAME}" "${DIRS}" ${VAR_NAME})
if(${VAR_NAME})
set(LIBNAME "${X}")
break()
endif()
endforeach()
set(${OVAR} "${LIBNAME}" PARENT_SCOPE)
endfunction()
function(tr_fixup_bundle_item BUNDLE_DIR BUNDLE_ITEMS DEP_DIRS)
while(BUNDLE_ITEMS)
list(GET BUNDLE_ITEMS 0 ITEM)
list(REMOVE_AT BUNDLE_ITEMS 0)
set(ITEM_FULL_BUNDLE_PATH "${BUNDLE_DIR}/${ITEM}")
get_filename_component(ITEM_FULL_BUNDLE_DIR "${ITEM_FULL_BUNDLE_PATH}" PATH)
unset(ITEM_DEPS)
get_prerequisites("${ITEM_FULL_BUNDLE_PATH}" ITEM_DEPS 1 0 "${ITEM_FULL_BUNDLE_PATH}" "${DEP_DIRS}")
foreach(DEP IN LISTS ITEM_DEPS)
gp_resolve_item("${ITEM_FULL_BUNDLE_PATH}" "${DEP}" "${ITEM_FULL_BUNDLE_DIR}" "${DEP_DIRS}" DEP_FULL_PATH)
if(DEP_FULL_PATH MATCHES "[.]dylib$")
get_filename_component(DEP_NAME "${DEP_FULL_PATH}" NAME)
file(COPY "${DEP_FULL_PATH}" DESTINATION "${BUNDLE_DIR}/Contents/MacOS/")
set(DEP_BUNDLE_PATH "Contents/MacOS/${DEP_NAME}")
elseif(DEP_FULL_PATH MATCHES "^(.+)/(([^/]+[.]framework)/.+)$")
set(DEP_NAME "${CMAKE_MATCH_2}")
file(COPY "${CMAKE_MATCH_1}/${CMAKE_MATCH_3}" DESTINATION "${BUNDLE_DIR}/Contents/Frameworks/" PATTERN "Headers" EXCLUDE)
set(DEP_BUNDLE_PATH "Contents/Frameworks/${DEP_NAME}")
else()
message(FATAL_ERROR "Don't know how to fixup '${DEP_FULL_PATH}'")
endif()
execute_process(COMMAND install_name_tool -change "${DEP}" "@rpath/${DEP_NAME}" "${ITEM_FULL_BUNDLE_PATH}")
set(DEP_FULL_BUNDLE_PATH "${BUNDLE_DIR}/${DEP_BUNDLE_PATH}")
execute_process(COMMAND chmod u+w "${DEP_FULL_BUNDLE_PATH}")
execute_process(COMMAND install_name_tool -id "@rpath/${DEP_NAME}" "${DEP_FULL_BUNDLE_PATH}")
list(REMOVE_ITEM BUNDLE_ITEMS "${DEP_BUNDLE_PATH}")
list(APPEND BUNDLE_ITEMS "${DEP_BUNDLE_PATH}")
endforeach()
endwhile()
endfunction()
macro(tr_qt_wrap_ui)
qt5_wrap_ui(${ARGN})
endmacro()
macro(tr_qt_add_resources)
qt5_add_resources(${ARGN})
endmacro()
macro(tr_qt_add_translation)
qt5_add_translation(${ARGN} OPTIONS -silent)
endmacro()