Use option for CMake options

This commit is contained in:
Martchus 2016-07-10 00:16:24 +02:00
parent 3301f8518f
commit 18845b3ce0
3 changed files with 38 additions and 33 deletions

View File

@ -46,8 +46,8 @@ configure_file(
include_directories("${CMAKE_CURRENT_BINARY_DIR}") include_directories("${CMAKE_CURRENT_BINARY_DIR}")
# disable new ABI (can't catch ios_base::failure with new ABI) # disable new ABI (can't catch ios_base::failure with new ABI)
set(FORCE_OLD_ABI "no" CACHE STRING "specifies whether usage of old ABI should be forced") option(FORCE_OLD_ABI "specifies whether usage of old ABI should be forced" OFF)
if(${FORCE_OLD_ABI} STREQUAL "yes") if(FORCE_OLD_ABI)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
message(STATUS "Forcing usage of old CXX11 ABI.") message(STATUS "Forcing usage of old CXX11 ABI.")
endif() endif()
@ -59,7 +59,8 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif() endif()
# enable logging when option is set # enable logging when option is set
set(LOGGING_ENABLED "no" CACHE STRING "specifies whether logging is enabled") option(LOGGING_ENABLED "specifies whether logging is enabled" OFF)
if(${LOGGING_ENABLED} STREQUAL "yes") if(LOGGING_ENABLED)
add_definitions(-DLOGGING_ENABLED) add_definitions(-DLOGGING_ENABLED)
message(STATUS "Logging is enabled.")
endif() endif()

View File

@ -55,21 +55,24 @@ if(MINGW)
endif(MINGW) endif(MINGW)
# add target for building the library # add target for building the library
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} SHARED ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_FILES} ${QML_FILES} ${RES_FILES} ${QM_FILES} ${WINDOWS_ICON_PATH}) option(BUILD_SHARED_LIBS "whether to build dynamic libraries (enabled by default)" ON)
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${LIBRARIES}) if(BUILD_SHARED_LIBS)
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} PROPERTIES add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} SHARED ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_FILES} ${QML_FILES} ${RES_FILES} ${QM_FILES} ${WINDOWS_ICON_PATH})
VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH} target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${LIBRARIES})
SOVERSION ${META_VERSION_MAJOR} set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} PROPERTIES
CXX_STANDARD 11 VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}
) SOVERSION ${META_VERSION_MAJOR}
CXX_STANDARD 11
)
endif()
# add target for building a static version of the library # add target for building a static version of the library
if(MINGW) if(MINGW)
set(BUILD_STATIC_LIBS "yes" CACHE STRING "specifies whether to build static libraries (enabled by default on mingw-w64 platform)") option(BUILD_STATIC_LIBS "whether to build static libraries (enabled by default on mingw-w64 platform)" ON)
else() else()
set(BUILD_STATIC_LIBS "no" CACHE STRING "specifies whether to build static libraries (disabled by default on none-mingw-w64- platform)") option(BUILD_STATIC_LIBS "whether to build static libraries (disabled by default on none-mingw-w64- platform)" OFF)
endif() endif()
if(${BUILD_STATIC_LIBS} STREQUAL "yes") if(BUILD_STATIC_LIBS)
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static STATIC ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_FILES} ${QML_FILES} ${RES_FILES} ${QM_FILES} ${WINDOWS_ICON_PATH}) add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static STATIC ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_FILES} ${QML_FILES} ${RES_FILES} ${QM_FILES} ${WINDOWS_ICON_PATH})
# add target link libraries for the static lib also because otherwise Qt header files can not be located # add target link libraries for the static lib also because otherwise Qt header files can not be located
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static ${LIBRARIES}) target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static ${LIBRARIES})
@ -79,10 +82,7 @@ if(${BUILD_STATIC_LIBS} STREQUAL "yes")
OUTPUT_NAME ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} OUTPUT_NAME ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
CXX_STANDARD 11 CXX_STANDARD 11
) )
elseif(${BUILD_STATIC_LIBS} STREQUAL "no") endif()
else()
message(FATAL_ERROR "The specification whether to build static libs or not is invalid.")
endif(${BUILD_STATIC_LIBS} STREQUAL "yes")
# add install target for the CMake config files # add install target for the CMake config files
install( install(
@ -103,15 +103,17 @@ if(NOT TARGET install-cmake-config)
endif() endif()
# add install target for dynamic libs # add install target for dynamic libs
install( if(BUILD_SHARED_LIBS)
TARGETS ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} install(
RUNTIME DESTINATION bin TARGETS ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
COMPONENT binary RUNTIME DESTINATION bin
LIBRARY DESTINATION lib${SELECTED_LIB_SUFFIX} COMPONENT binary
COMPONENT binary LIBRARY DESTINATION lib${SELECTED_LIB_SUFFIX}
ARCHIVE DESTINATION lib${SELECTED_LIB_SUFFIX} COMPONENT binary
COMPONENT binary ARCHIVE DESTINATION lib${SELECTED_LIB_SUFFIX}
) COMPONENT binary
)
endif()
if(NOT TARGET install-binary) if(NOT TARGET install-binary)
add_custom_target(install-binary add_custom_target(install-binary
@ -121,7 +123,7 @@ if(NOT TARGET install-binary)
endif() endif()
# add install for static libs when building with mingw-w64 # add install for static libs when building with mingw-w64
if(${BUILD_STATIC_LIBS} STREQUAL "yes") if(BUILD_STATIC_LIBS)
install( install(
TARGETS ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static TARGETS ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
@ -131,7 +133,7 @@ if(${BUILD_STATIC_LIBS} STREQUAL "yes")
ARCHIVE DESTINATION lib${SELECTED_LIB_SUFFIX} ARCHIVE DESTINATION lib${SELECTED_LIB_SUFFIX}
COMPONENT binary COMPONENT binary
) )
endif(${BUILD_STATIC_LIBS} STREQUAL "yes") endif()
# add install target for stripped libs # add install target for stripped libs
if(NOT TARGET install-binary-strip) if(NOT TARGET install-binary-strip)

View File

@ -1,14 +1,14 @@
set(SHELL_COMPLETION_ENABLED "yes" CACHE STRING "controls whether shell completion is enabled") option(SHELL_COMPLETION_ENABLED "controls whether shell completion is enabled in general" ON)
set(BASH_COMPLETION_ENABLED "yes" CACHE STRING "controls whether bash completion is enabled") option(BASH_COMPLETION_ENABLED "controls whether shell completion for bash is enabled" ON)
if(${SHELL_COMPLETION_ENABLED} STREQUAL "yes") if(SHELL_COMPLETION_ENABLED)
if(NOT COMPLETION_META_PROJECT_NAME) if(NOT COMPLETION_META_PROJECT_NAME)
set(COMPLETION_META_PROJECT_NAME ${META_PROJECT_NAME}) set(COMPLETION_META_PROJECT_NAME ${META_PROJECT_NAME})
endif() endif()
# add bash completion (currently the only supported shell completion) # add bash completion (currently the only supported shell completion)
if(${BASH_COMPLETION_ENABLED} STREQUAL "yes") if(BASH_COMPLETION_ENABLED)
# find bash-completion.sh template # find bash-completion.sh template
include(TemplateFinder) include(TemplateFinder)
find_template_file("bash-completion.sh" CPP_UTILITIES BASH_COMPLETION_TEMPLATE_FILE) find_template_file("bash-completion.sh" CPP_UTILITIES BASH_COMPLETION_TEMPLATE_FILE)
@ -30,6 +30,8 @@ if(${SHELL_COMPLETION_ENABLED} STREQUAL "yes")
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=bash-completion -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=bash-completion -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
) )
endif() endif()
message(STATUS "Generating files for bash completion.")
endif() endif()
endif() endif()