Commit 1ad99534 authored by Luca Giambonini's avatar Luca Giambonini

cmake refactoring

to be able to automatically generate:
*Config.cmake
*ConfigVersion.cmake
*Targets.cmake
parent dd3868a7
project(akabeiclient)
cmake_minimum_required(VERSION 3.4.0 FATAL_ERROR)
#add_definitions(-DQT_NO_DEBUG_OUTPUT)
project(akabeiclient VERSION 0.0.1)
set(MAJOR_AKABEICLIENT_VERSION 0 CACHE INT "Akabei's major version number" FORCE)
set(MINOR_AKABEICLIENT_VERSION 0 CACHE INT "Akabei's minor version number" FORCE)
set(PATCH_AKABEICLIENT_VERSION 1 CACHE INT "Akabei's patch version number" FORCE)
set(FIX_AKABEICLIENT_VERSION 0 CACHE INT "Akabei's fix version number" FORCE)
set(AKABEI_VERSION_STRING "${MAJOR_AKABEICLIENT_VERSION}.${MINOR_AKABEICLIENT_VERSION}.${PATCH_AKABEICLIENT_VERSION}.${FIX_AKABEICLIENT_VERSION}")
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
option(BUILD_TESTS "Builds various tests and examples for Akabei" ON)
option(BUILD_COVERAGE "Builds code coverage data for Akabei" OFF)
if(CMAKE_COMPILER_IS_GNUCXX AND BUILD_COVERAGE AND BUILD_TESTS)
include(CodeCoverage)
setup_target_for_coverage(coverage ctest coverage)
SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-W -Wall)
add_definitions(-Werror)
# set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Compiles with debugging symbols (Debug mode)
if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS_DEBUG "-ggdb")
endif(CMAKE_COMPILER_IS_GNUCC)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
......@@ -19,12 +46,6 @@ add_definitions(#-DQT_NO_CAST_TO_ASCII
-DQT_USE_QSTRINGBUILDER
)
set(MAJOR_AKABEICLIENT_VERSION 0 CACHE INT "Akabei's major version number" FORCE)
set(MINOR_AKABEICLIENT_VERSION 0 CACHE INT "Akabei's minor version number" FORCE)
set(PATCH_AKABEICLIENT_VERSION 1 CACHE INT "Akabei's patch version number" FORCE)
set(FIX_AKABEICLIENT_VERSION 0 CACHE INT "Akabei's fix version number" FORCE)
set(AKABEI_VERSION_STRING "${MAJOR_AKABEICLIENT_VERSION}.${MINOR_AKABEICLIENT_VERSION}.${PATCH_AKABEICLIENT_VERSION}.${FIX_AKABEICLIENT_VERSION}")
# Define install directories
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/akabei" CACHE "Akabei data's install dir" STRING)
set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE "Akabei binary install dir" STRING)
......@@ -47,24 +68,6 @@ add_definitions(${QT_DEFINITIONS} -W -Wall)
add_definitions(-Werror)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/AkabeiClientConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/AkabeiClientConfig.cmake"
INSTALL_DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/AkabeiClientConfigVersion.cmake"
VERSION ${AKABEI_VERSION_STRING}
COMPATIBILITY AnyNewerVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/AkabeiClientConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/AkabeiClientConfigVersion.cmake"
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
COMPONENT Devel)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/akabeiclientconfig.h.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/akabeiclientconfig.h"
......
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS_DEBUG "-ggdb")
endif(CMAKE_COMPILER_IS_GNUCC)
# based on https://github.com/forexample/package-example
set(AKABEI_CLIENT_SRCS
akabeiclientbackend.cpp
akabeiclientconfiguration.cpp
......@@ -46,13 +38,23 @@ set(AKABEI_OPERATION_HDRS
operations/akabeiplainsignatureoperation.h
)
####
# Create targets
add_library(akabeiclient SHARED ${AKABEI_CLIENT_SRCS} ${AKABEI_OPERATION_SRCS} ${AKABEI_CLIENT_MISSING_MOCS})
# Global includes. Used by all targets
# Note:
# * header location in project: foo/Bar.h
# * header can be included by C++ code `#include <foo/Bar.h>`
target_include_directories(
akabeiclient PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/>"
)
set_target_properties(akabeiclient PROPERTIES AUTOMOC TRUE)
set_target_properties(akabeiclient PROPERTIES VERSION ${MAJOR_AKABEICLIENT_VERSION}.${MINOR_AKABEICLIENT_VERSION}.${PATCH_AKABEICLIENT_VERSION}
SOVERSION ${MAJOR_AKABEICLIENT_VERSION}
)
SOVERSION ${MAJOR_AKABEICLIENT_VERSION})
target_link_libraries(akabeiclient
Qt5::Core
......@@ -66,8 +68,73 @@ target_link_libraries(akabeiclient
${GPGME_VANILLA_LIBRARIES}
)
add_subdirectory(tests)
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
# Layout. This works for all platforms:
# * <prefix>/lib*/cmake/<PROJECT-NAME>
# * <prefix>/lib*/
# * <prefix>/include/
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
# Configuration
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
# Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
# Configure '<PROJECT-NAME>Config.cmake'
# Use variables:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
install(TARGETS akabeiclient DESTINATION ${LIB_INSTALL_DIR})
install(
TARGETS akabeiclient
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
# Install header files
install(FILES ${AKABEI_CLIENT_HDRS} DESTINATION ${INCLUDES_INSTALL_DIR})
install(FILES ${AKABEI_OPERATION_HDRS} DESTINATION ${INCLUDES_INSTALL_DIR}/operations)
# Config
# * <prefix>/lib/cmake/AkabeiClient/AkabeiCoreConfig.cmake
# * <prefix>/lib/cmake/AkabeiClient/AkabeiCoreConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
# Config
# * <prefix>/lib/cmake/AkabeiClient/AkabeiCoreTargets.cmake
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
add_subdirectory(tests)
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment