Improve CMake modules

This commit is contained in:
Martchus 2017-02-11 02:30:46 +01:00
parent 789b9e9184
commit 64cc931555
11 changed files with 81 additions and 13 deletions

View File

@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
if(NOT DEFINED FIND_THIRD_PARTY_LIBRARIES_EXISTS)
set(FIND_THIRD_PARTY_LIBRARIES_EXISTS true)
if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
macro(save_default_library_suffixes)
set(DEFAULT_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
@ -54,7 +53,7 @@ if(NOT DEFINED FIND_THIRD_PARTY_LIBRARIES_EXISTS)
endif()
message(STATUS "Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} statically against external library ${NAME} (${${NAME}_STATIC_LIB}).")
elseif((${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB) AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE") OR ("${LINKAGE}" STREQUAL "SHARED")))
set(USE_STATIC_${NAME} OFF)
set(USE_SHARED_${NAME} ON)
if(NOT ${NAME}_DYNAMIC_LIB)
set(${NAME}_DYNAMIC_LIB ${${NAME}_SHARED_LIB})
endif()
@ -152,4 +151,6 @@ if(NOT DEFINED FIND_THIRD_PARTY_LIBRARIES_EXISTS)
use_external_library(iconv ${LINKAGE} ${REQUIRED})
endif()
endmacro()
set(THIRD_PARTY_MODULE_LOADED YES)
endif()

View File

@ -1,4 +1,9 @@
# before including this module, BasicConfig must be included
if(NOT BASIC_PROJECT_CONFIG_DONE)
message(FATAL_ERROR "Before including the AppTarget module, the BasicConfig module must be included.")
endif()
if(TARGET_CONFIG_DONE)
message(FATAL_ERROR "Can not include AppTarget module when targets are already configured.")
endif()
# check whether project type is set correctly
if(NOT "${META_PROJECT_TYPE}" STREQUAL "application")
@ -186,3 +191,5 @@ function(add_desktop_file)
"${DESKTOP_FILE_ADDITIONAL_ENTRIES}"
)
endfunction()
set(TARGET_CONFIG_DONE YES)

View File

@ -1,4 +1,16 @@
# before including this module, the project meta-data must be set
if(NOT META_PROJECT_NAME)
message(FATAL_ERROR "No project name (META_PROJECT_NAME) specified.")
endif()
if(NOT META_APP_NAME)
message(FATAL_ERROR "No project name (META_APP_NAME) specified.")
endif()
if(NOT META_APP_AUTHOR)
message(FATAL_ERROR "No project name (META_APP_AUTHOR) specified.")
endif()
if(NOT META_APP_DESCRIPTION)
message(FATAL_ERROR "No project name (META_APP_DESCRIPTION) specified.")
endif()
# set project name (displayed in Qt Creator)
message(STATUS "Configuring project ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
@ -11,6 +23,10 @@ endif()
if(NOT META_PROJECT_VARNAME_UPPER)
string(TOUPPER ${META_PROJECT_VARNAME} META_PROJECT_VARNAME_UPPER)
endif()
if(NOT META_PROJECT_VARNAME_LOWER)
string(REGEX REPLACE "_+" "" META_PROJECT_VARNAME_LOWER "${META_PROJECT_VARNAME}")
string(TOLOWER "${META_PROJECT_VARNAME_LOWER}" META_PROJECT_VARNAME_LOWER)
endif()
# set META_GENERIC_NAME to META_APP_NAME if not specified explicitely
if(NOT META_GENERIC_NAME)
@ -22,6 +38,17 @@ if(NOT META_CXX_STANDARD)
set(META_CXX_STANDARD 14)
endif()
# set version to 0.0.0 if not specified explicitely
if(NOT META_VERSION_MAJOR)
set(META_VERSION_MAJOR 0)
endif()
if(NOT META_VERSION_MINOR)
set(META_VERSION_MINOR 0)
endif()
if(NOT META_VERSION_PATCH)
set(META_VERSION_PATCH 0)
endif()
# provide variables for other projects built as part of the same subdirs project
# to access files from this project
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
@ -113,3 +140,5 @@ if(QML_HEADER_FILES OR QML_SRC_FILES)
else()
set(QUICK_GUI OFF)
endif()
set(BASIC_PROJECT_CONFIG_DONE YES)

View File

@ -1,5 +1,9 @@
# before including this module, all relevant variables must be set
# (just include this module as last one since nothing should depend on it)
# just include this module as last one since nothing should depend on it
if(NOT TARGET_CONFIG_DONE)
message(FATAL_ERROR "Before including the ConfigHeader module, the BasicConfig module must be included.")
endif()
# find config.h template
include(TemplateFinder)

View File

@ -1,3 +1,7 @@
if(NOT BASIC_PROJECT_CONFIG_DONE)
message(FATAL_ERROR "Before including the Doxygen module, the BasicConfig module must be included.")
endif()
option(NO_DOXYGEN "whether creation of Doxygen targets is disabled (enabled by default)" OFF)
if(NOT NO_DOXYGEN)

View File

@ -1,6 +1,11 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
# before including this module, BasicConfig must be included
if(NOT BASIC_PROJECT_CONFIG_DONE)
message(FATAL_ERROR "Before including the LibraryTarget module, the BasicConfig module must be included.")
endif()
if(TARGET_CONFIG_DONE)
message(FATAL_ERROR "Can not include LibraryTarget module when targets are already configured.")
endif()
# check whether project type is set correctly
if((NOT "${META_PROJECT_TYPE}" STREQUAL "library") AND (NOT "${META_PROJECT_TYPE}" STREQUAL ""))
@ -366,3 +371,5 @@ if(BUILD_STATIC_LIBS)
add_dependencies(install-${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}-mingw-w64-staticlib-strip install-binary-strip)
add_dependencies(install-mingw-w64-strip install-${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}-mingw-w64-staticlib-strip)
endif()
set(TARGET_CONFIG_DONE YES)

View File

@ -1,5 +1,5 @@
if(NOT DEFINED LIST_TO_STRING_EXISTS)
set(LIST_TO_STRING_EXISTS true)
if(NOT DEFINED LIST_TO_STRING_LOADED)
function(list_to_string separator prefix suffix input_list output_string_var)
set(res "")
# get list length
@ -24,4 +24,6 @@ if(NOT DEFINED LIST_TO_STRING_EXISTS)
endif()
set(${output_string_var} "${res}" PARENT_SCOPE)
endfunction()
set(LIST_TO_STRING_LOADED YES)
endif()

View File

@ -1,3 +1,7 @@
if(NOT BASIC_PROJECT_CONFIG_DONE)
message(FATAL_ERROR "Before including the ShellCompletion module, the BasicConfig module must be included.")
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)

View File

@ -1,5 +1,5 @@
if(NOT DEFINED FIND_TEMPLATE_FILE_EXISTS)
set(FIND_TEMPLATE_FILE_EXISTS true)
if(NOT DEFINED TEMPLATE_FINDER_LOADED)
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
@ -17,4 +17,6 @@ if(NOT DEFINED FIND_TEMPLATE_FILE_EXISTS)
message(FATAL_ERROR "Template for ${FILE_NAME} file can not be located.")
endif()
endfunction()
set(TEMPLATE_FINDER_LOADED YES)
endif()

View File

@ -1,4 +1,9 @@
# before including this module, BasicConfig must be included
if(NOT BASIC_PROJECT_CONFIG_DONE)
message(FATAL_ERROR "Before including the AppTarget module, the BasicConfig module must be included.")
endif()
if(TEST_CONFIG_DONE)
message(FATAL_ERROR "Can not include TestTarget module when tests are already configured.")
endif()
# always link test applications against c++utilities and cppunit
find_library(CPP_UNIT_LIB cppunit)
@ -78,5 +83,6 @@ if(CPP_UNIT_LIB)
else()
message(WARNING "Unable to add test target because cppunit could not be located.")
endif()
set(TEST_CONFIG_DONE YES)

View File

@ -2,7 +2,9 @@
# also attaches the application icon if ffmpeg is available
# does nothing if not building with mingw-w64
# before including this module, LibraryConfig/ApplicationConfig must be included
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)