Improve coding style in CMake modules
This commit is contained in:
parent
eea5aa57bc
commit
0dcbb3de55
|
@ -1,26 +1,30 @@
|
|||
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
|
||||
|
||||
if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
|
||||
# prevent multiple inclusion
|
||||
if(DEFINED THIRD_PARTY_MODULE_LOADED)
|
||||
return()
|
||||
endif()
|
||||
set(THIRD_PARTY_MODULE_LOADED YES)
|
||||
|
||||
macro(save_default_library_suffixes)
|
||||
macro(save_default_library_suffixes)
|
||||
set(DEFAULT_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(restore_default_library_suffixes)
|
||||
macro(restore_default_library_suffixes)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${DEFAULT_CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
unset(DEFAULT_CMAKE_FIND_LIBRARY_SUFFIXES)
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(configure_static_library_suffixes)
|
||||
macro(configure_static_library_suffixes)
|
||||
# allows to look for static libraries in particular
|
||||
if(WIN32)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib)
|
||||
else()
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
|
||||
endif()
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(configure_dynamic_library_suffixes)
|
||||
macro(configure_dynamic_library_suffixes)
|
||||
# allows to look for dynamic libraries in particular
|
||||
if(WIN32)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES .dll .dll.a)
|
||||
|
@ -29,9 +33,9 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
|
|||
else()
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES .so)
|
||||
endif()
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(link_against_library_varnames NAME LINKAGE REQUIRED PRIVATE_LIBRARIES_VARNAME PUBLIC_LIBRARIES_VARNAME PRIVATE_STATIC_LIBRARIES_VARNAME PUBLIC_STATIC_LIBRARIES_VARNAME)
|
||||
macro(link_against_library_varnames NAME LINKAGE REQUIRED PRIVATE_LIBRARIES_VARNAME PUBLIC_LIBRARIES_VARNAME PRIVATE_STATIC_LIBRARIES_VARNAME PUBLIC_STATIC_LIBRARIES_VARNAME)
|
||||
# determine whether the library is required or optional
|
||||
# FIXME: improve passing required argument
|
||||
if("${REQUIRED}" STREQUAL "OPTIONAL")
|
||||
|
@ -165,21 +169,21 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
|
|||
message(WARNING "External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}.")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(link_against_library NAME LINKAGE REQUIRED)
|
||||
macro(link_against_library NAME LINKAGE REQUIRED)
|
||||
link_against_library_varnames("${NAME}" "${LINKAGE}" "${REQUIRED}"
|
||||
PRIVATE_LIBRARIES PUBLIC_LIBRARIES PRIVATE_STATIC_LIBRARIES PUBLIC_STATIC_LIBRARIES
|
||||
)
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(link_tests_against_library NAME LINKAGE REQUIRED)
|
||||
macro(link_tests_against_library NAME LINKAGE REQUIRED)
|
||||
link_against_library_varnames("${NAME}" "${LINKAGE}" "${REQUIRED}"
|
||||
TEST_LIBRARIES TEST_LIBRARIES STATIC_TEST_LIBRARIES STATIC_TEST_LIBRARIES
|
||||
)
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(find_external_library NAME LINKAGE REQUIRED)
|
||||
macro(find_external_library NAME LINKAGE REQUIRED)
|
||||
set(${NAME}_DYNAMIC_INCLUDE_DIR NOTFOUND CACHE PATH "${NAME} include dir (dynamic)")
|
||||
set(${NAME}_DYNAMIC_LIB NOTFOUND CACHE FILEPATH "${NAME} lib (dynamic)")
|
||||
set(${NAME}_STATIC_INCLUDE_DIR NOTFOUND CACHE PATH "${NAME} include dir (static)")
|
||||
|
@ -200,30 +204,30 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
|
|||
endif()
|
||||
|
||||
restore_default_library_suffixes()
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(use_external_library NAME LINKAGE REQUIRED)
|
||||
macro(use_external_library NAME LINKAGE REQUIRED)
|
||||
find_external_library("${NAME}" "${LINKAGE}" "${REQUIRED}")
|
||||
link_against_library("${NAME}" "${LINKAGE}" "${REQUIRED}")
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
function(use_external_library_from_package_dynamic NAME PKGNAME INCLUDE_VAR LIBRARY_VAR COMPAT_VERSION)
|
||||
function(use_external_library_from_package_dynamic NAME PKGNAME INCLUDE_VAR LIBRARY_VAR COMPAT_VERSION)
|
||||
# internally used by find_external_library_from_package to find dynamic libraries
|
||||
configure_dynamic_library_suffixes()
|
||||
find_package(${PKGNAME} ${COMPAT_VERSION})
|
||||
set(${NAME}_DYNAMIC_INCLUDE_DIR ${${INCLUDE_VAR}} CACHE PATH "${NAME} include dir (dynamic)" FORCE)
|
||||
set(${NAME}_DYNAMIC_LIB ${${LIBRARY_VAR}} CACHE FILEPATH "${NAME} lib (dynamic)" FORCE)
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
function(use_external_library_from_package_static NAME PKGNAME INCLUDE_VAR LIBRARY_VAR COMPAT_VERSION)
|
||||
function(use_external_library_from_package_static NAME PKGNAME INCLUDE_VAR LIBRARY_VAR COMPAT_VERSION)
|
||||
# internally used by find_external_library_from_package to find static libraries
|
||||
configure_static_library_suffixes()
|
||||
find_package(${PKGNAME} ${COMPAT_VERSION})
|
||||
set(${NAME}_STATIC_INCLUDE_DIR ${${INCLUDE_VAR}} CACHE PATH "${NAME} include dir (static)" FORCE)
|
||||
set(${NAME}_STATIC_LIB ${${LIBRARY_VAR}} CACHE FILEPATH "${NAME} lib (static)" FORCE)
|
||||
endfunction()
|
||||
endfunction()
|
||||
|
||||
macro(find_external_library_from_package NAME PKGNAME VERSION INCLUDE_VAR LIBRARY_VAR LINKAGE REQUIRED)
|
||||
macro(find_external_library_from_package NAME PKGNAME VERSION INCLUDE_VAR LIBRARY_VAR LINKAGE REQUIRED)
|
||||
# handle specified VERSION
|
||||
if("${VERSION}" STREQUAL "ANY_VERSION")
|
||||
set(${NAME}_COMPATIBLE_VERSION "")
|
||||
|
@ -246,14 +250,14 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
|
|||
use_external_library_from_package_static(${NAME} ${PKGNAME} ${INCLUDE_VAR} "${LIBRARY_VAR}" "${${NAME}_COMPATIBLE_VERSION}")
|
||||
endif()
|
||||
restore_default_library_suffixes()
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(use_external_library_from_package NAME PKGNAME VERSION INCLUDE_VAR LIBRARY_VAR LINKAGE REQUIRED)
|
||||
macro(use_external_library_from_package NAME PKGNAME VERSION INCLUDE_VAR LIBRARY_VAR LINKAGE REQUIRED)
|
||||
find_external_library_from_package("${NAME}" "${PKGNAME}" "${VERSION}" "${INCLUDE_VAR}" "${LIBRARY_VAR}" "${LINKAGE}" "${REQUIRED}")
|
||||
link_against_library("${NAME}" "${LINKAGE}" "${REQUIRED}")
|
||||
endmacro()
|
||||
endmacro()
|
||||
|
||||
macro(use_iconv LINKAGE REQUIRED)
|
||||
macro(use_iconv LINKAGE REQUIRED)
|
||||
set(FORCE_EXTERNAL_ICONV OFF CACHE PATH "whether to force usage of external iconv (rather than the using the one bundled with glibc)")
|
||||
if(NOT FORCE_EXTERNAL_ICONV)
|
||||
# check whether iconv exists in standard lib
|
||||
|
@ -266,7 +270,4 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
|
|||
# find external iconv library
|
||||
use_external_library(iconv ${LINKAGE} ${REQUIRED})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
set(THIRD_PARTY_MODULE_LOADED YES)
|
||||
endif()
|
||||
endmacro()
|
||||
|
|
|
@ -3,65 +3,69 @@ if(NOT BASIC_PROJECT_CONFIG_DONE)
|
|||
endif()
|
||||
|
||||
option(NO_DOXYGEN "whether creation of Doxygen targets is disabled (enabled by default)" OFF)
|
||||
|
||||
if(NOT NO_DOXYGEN)
|
||||
# find doxygen.h template
|
||||
include(TemplateFinder)
|
||||
find_template_file("doxygen" CPP_UTILITIES DOXYGEN_TEMPLATE_FILE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# find executables
|
||||
find_program(DOXYGEN_BIN doxygen)
|
||||
find_program(PERL_BIN perl)
|
||||
find_program(DIA_BIN dia)
|
||||
if(DIA_BIN)
|
||||
# find doxygen.h template
|
||||
include(TemplateFinder)
|
||||
find_template_file("doxygen" CPP_UTILITIES DOXYGEN_TEMPLATE_FILE)
|
||||
|
||||
# find executables
|
||||
find_program(DOXYGEN_BIN doxygen)
|
||||
find_program(PERL_BIN perl)
|
||||
find_program(DIA_BIN dia)
|
||||
if(DIA_BIN)
|
||||
set(HAVE_DIA "YES")
|
||||
else()
|
||||
else()
|
||||
set(HAVE_DIA "NO")
|
||||
endif()
|
||||
find_program(DOT_BIN dot)
|
||||
if(DOT_BIN)
|
||||
endif()
|
||||
find_program(DOT_BIN dot)
|
||||
if(DOT_BIN)
|
||||
set(HAVE_DOT "YES")
|
||||
else()
|
||||
else()
|
||||
set(HAVE_DOT "NO")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT DOXYGEN_BIN)
|
||||
if(NOT DOXYGEN_BIN)
|
||||
message(WARNING "Doxygen not found, unable to add target for generating API documentation for ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
|
||||
else()
|
||||
# load cached configuration and other variables
|
||||
set(DOXY_LANGUAGE "English" CACHE STRING "specifies the language of the API documentation generated with Doxygen")
|
||||
set(DOXY_CUSTOM_CONFIG "" CACHE STRING "specifies extra options for Doxygen")
|
||||
set(DOXY_NUMBER "${META_APP_VERSION}")
|
||||
set(DOXY_INPUT_FILES
|
||||
return()
|
||||
endif()
|
||||
|
||||
# load cached configuration and other variables
|
||||
set(DOXY_LANGUAGE "English" CACHE STRING "specifies the language of the API documentation generated with Doxygen")
|
||||
set(DOXY_CUSTOM_CONFIG "" CACHE STRING "specifies extra options for Doxygen")
|
||||
set(DOXY_NUMBER "${META_APP_VERSION}")
|
||||
set(DOXY_INPUT_FILES
|
||||
${HEADER_FILES} ${SRC_FILES} ${TEST_HEADER_FILES} ${TEST_SRC_FILES} ${WIDGETS_HEADER_FILES} ${WIDGETS_SRC_FILES}
|
||||
${QML_HEADER_FILES} ${QML_SRC_FILES} ${DOC_FILES} ${DOC_ONLY_FILES}
|
||||
)
|
||||
set(DOXY_PATH_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/")
|
||||
list(GET DOC_FILES 0 DOXY_MAIN_PAGE_FILE)
|
||||
set(DOXY_MAIN_PAGE_FILE "${DOXY_PATH_PREFIX}${DOXY_MAIN_PAGE_FILE}")
|
||||
)
|
||||
set(DOXY_PATH_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/")
|
||||
list(GET DOC_FILES 0 DOXY_MAIN_PAGE_FILE)
|
||||
set(DOXY_MAIN_PAGE_FILE "${DOXY_PATH_PREFIX}${DOXY_MAIN_PAGE_FILE}")
|
||||
|
||||
# convert DOXY_INPUT_FILES to whitespace-separated list
|
||||
include(ListToString)
|
||||
list_to_string(" " "\"${DOXY_PATH_PREFIX}" "\"" "${DOXY_INPUT_FILES}" DOXY_INPUT_FILES_WHITESPACE_SEPARATED)
|
||||
# convert DOXY_INPUT_FILES to whitespace-separated list
|
||||
include(ListToString)
|
||||
list_to_string(" " "\"${DOXY_PATH_PREFIX}" "\"" "${DOXY_INPUT_FILES}" DOXY_INPUT_FILES_WHITESPACE_SEPARATED)
|
||||
|
||||
# generate Doxygen configuration
|
||||
configure_file(
|
||||
# generate Doxygen configuration
|
||||
configure_file(
|
||||
"${DOXYGEN_TEMPLATE_FILE}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/doxygen.config"
|
||||
)
|
||||
)
|
||||
|
||||
# add target for generating API documentation
|
||||
add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apidoc"
|
||||
# add target for generating API documentation
|
||||
add_custom_target("${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apidoc"
|
||||
COMMAND "${DOXYGEN_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/doxygen.config"
|
||||
SOURCES ${DOXY_INPUT_FILES}
|
||||
)
|
||||
if(NOT TARGET apidoc)
|
||||
)
|
||||
if(NOT TARGET apidoc)
|
||||
add_custom_target(apidoc)
|
||||
endif()
|
||||
add_dependencies(apidoc "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apidoc")
|
||||
endif()
|
||||
add_dependencies(apidoc "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_apidoc")
|
||||
|
||||
# add install target for API documentation
|
||||
if(NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
|
||||
# add install target for API documentation
|
||||
if(NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
|
||||
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/api-doc"
|
||||
DESTINATION "share/${META_PROJECT_NAME}"
|
||||
COMPONENT api-doc
|
||||
|
@ -72,9 +76,6 @@ if(NOT NO_DOXYGEN)
|
|||
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=api-doc -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "Generating target for generating API documentation for ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} with Doxygen")
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "Generating target for generating API documentation for ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} with Doxygen")
|
||||
|
|
|
@ -4,10 +4,12 @@ endif()
|
|||
|
||||
option(SHELL_COMPLETION_ENABLED "controls whether shell completion is enabled in general" ON)
|
||||
option(BASH_COMPLETION_ENABLED "controls whether shell completion for bash is enabled" ON)
|
||||
if(NOT SHELL_COMPLETION_ENABLED)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(SHELL_COMPLETION_ENABLED)
|
||||
# add bash completion (currently the only supported shell completion)
|
||||
if(BASH_COMPLETION_ENABLED)
|
||||
# add bash completion (currently the only supported shell completion)
|
||||
if(BASH_COMPLETION_ENABLED)
|
||||
# find bash-completion.sh template
|
||||
include(TemplateFinder)
|
||||
find_template_file("bash-completion.sh" CPP_UTILITIES BASH_COMPLETION_TEMPLATE_FILE)
|
||||
|
@ -33,5 +35,4 @@ if(SHELL_COMPLETION_ENABLED)
|
|||
endif()
|
||||
|
||||
message(STATUS "Generating files for bash completion.")
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
if(NOT DEFINED TEMPLATE_FINDER_LOADED)
|
||||
# prevent multiple inclusion
|
||||
if(DEFINED TEMPLATE_FINDER_LOADED)
|
||||
return()
|
||||
endif()
|
||||
set(TEMPLATE_FINDER_LOADED YES)
|
||||
|
||||
function(find_template_file FILE_NAME PROJECT_VAR_NAME OUTPUT_VAR)
|
||||
function(find_template_file FILE_NAME PROJECT_VAR_NAME OUTPUT_VAR)
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/${FILE_NAME}.in")
|
||||
# check own source directory
|
||||
set(${OUTPUT_VAR} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/${FILE_NAME}.in" PARENT_SCOPE)
|
||||
|
@ -16,7 +20,4 @@ if(NOT DEFINED TEMPLATE_FINDER_LOADED)
|
|||
else()
|
||||
message(FATAL_ERROR "Template for ${FILE_NAME} file can not be located.")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
set(TEMPLATE_FINDER_LOADED YES)
|
||||
endif()
|
||||
endfunction()
|
||||
|
|
|
@ -6,18 +6,21 @@ if(NOT BASIC_PROJECT_CONFIG_DONE)
|
|||
message(FATAL_ERROR "Before including the WindowsResources module, the LibraryConfig/ApplicationConfig module must be included.")
|
||||
endif()
|
||||
|
||||
option(WINDOWS_RESOURCES_ENABLED "controls Windows resources are enabled" ON)
|
||||
option(WINDOWS_ICON_ENABLED "controls Windows icon is enabled" ON)
|
||||
option(WINDOWS_RESOURCES_ENABLED "controls whether Windows resources are enabled" ON)
|
||||
option(WINDOWS_ICON_ENABLED "controls whether Windows icon is enabled" ON)
|
||||
|
||||
if(MINGW AND WINDOWS_RESOURCES_ENABLED)
|
||||
# find rc template
|
||||
include(TemplateFinder)
|
||||
find_template_file("windows.rc" CPP_UTILITIES RC_TEMPLATE_FILE)
|
||||
if(NOT MINGW OR NOT WINDOWS_RESOURCES_ENABLED)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# create Windows icon from png with ffmpeg if available
|
||||
unset(WINDOWS_ICON_PATH)
|
||||
unset(WINDOWS_ICON_RC_ENTRY)
|
||||
if(WINDOWS_ICON_ENABLED)
|
||||
# find rc template
|
||||
include(TemplateFinder)
|
||||
find_template_file("windows.rc" CPP_UTILITIES RC_TEMPLATE_FILE)
|
||||
|
||||
# create Windows icon from png with ffmpeg if available
|
||||
unset(WINDOWS_ICON_PATH)
|
||||
unset(WINDOWS_ICON_RC_ENTRY)
|
||||
if(WINDOWS_ICON_ENABLED)
|
||||
find_program(FFMPEG_BIN ffmpeg avconv)
|
||||
if(FFMPEG_BIN)
|
||||
if(NOT PNG_ICON_PATH)
|
||||
|
@ -42,17 +45,16 @@ if(MINGW AND WINDOWS_RESOURCES_ENABLED)
|
|||
message(FATAL_ERROR "The specified PNG_ICON_PATH \"${PNG_ICON_PATH}\" is invalid.")
|
||||
endif()
|
||||
unset(USING_DEFAULT_PNG_ICON_PATH)
|
||||
endif(FFMPEG_BIN)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# create Windows rc file from template
|
||||
configure_file(
|
||||
# create Windows rc file from template
|
||||
configure_file(
|
||||
"${RC_TEMPLATE_FILE}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/resources/windows.rc"
|
||||
)
|
||||
# set windres as resource compiler
|
||||
list(APPEND RES_FILES "${CMAKE_CURRENT_BINARY_DIR}/resources/windows.rc")
|
||||
set(CMAKE_RC_COMPILER_INIT windres)
|
||||
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
|
||||
enable_language(RC)
|
||||
endif()
|
||||
)
|
||||
# set windres as resource compiler
|
||||
list(APPEND RES_FILES "${CMAKE_CURRENT_BINARY_DIR}/resources/windows.rc")
|
||||
set(CMAKE_RC_COMPILER_INIT windres)
|
||||
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
|
||||
enable_language(RC)
|
||||
|
|
Loading…
Reference in New Issue