Commit f08ee5ab authored by Luca Giambonini's avatar Luca Giambonini

cmake refactoring

to be able to automatically generate:
*Config.cmake
*ConfigVersion.cmake
*Targets.cmake
parent 6bd3aadc
@PACKAGE_INIT@
# Required components to use this framework
include(CMakeFindDependencyMacro)
find_dependency(Qt5Core "@REQUIRED_QT_VERSION@")
find_dependency(Qt5Test "@REQUIRED_QT_VERSION@")
find_dependency(Qt5Concurrent "@REQUIRED_QT_VERSION@")
find_dependency(Qt5DBus "@REQUIRED_QT_VERSION@")
find_dependency(Qt5Widgets "@REQUIRED_QT_VERSION@")
include("${CMAKE_CURRENT_LIST_DIR}/AkabeiCoreConfig.cmake")
@PACKAGE_INCLUDE_QCHTARGETS@
cmake_minimum_required(VERSION 3.4.0 FATAL_ERROR) cmake_minimum_required(VERSION 3.4.0 FATAL_ERROR)
project(akabeicore) #project(akabeicore)
project(akabeicore VERSION 0.0.1)
set(MAJOR_AKABEI_VERSION 0 CACHE INT "Akabei’s major version number" FORCE) set(MAJOR_AKABEI_VERSION 0 CACHE INT "Akabei’s major version number" FORCE)
set(MINOR_AKABEI_VERSION 0 CACHE INT "Akabei’s minor version number" FORCE) set(MINOR_AKABEI_VERSION 0 CACHE INT "Akabei’s minor version number" FORCE)
...@@ -61,34 +62,13 @@ set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE "Akabei library installa ...@@ -61,34 +62,13 @@ set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE "Akabei library installa
set(INCLUDES_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/akabeicore" CACHE "Akabei includes installation directory" STRING) set(INCLUDES_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/akabeicore" CACHE "Akabei includes installation directory" STRING)
set(STATE_DIR "/var" CACHE "Directory to store cache data and log files, usually under ${STATE_DIR}/{cache,log,etc...})" STRING) set(STATE_DIR "/var" CACHE "Directory to store cache data and log files, usually under ${STATE_DIR}/{cache,log,etc...})" STRING)
set(CONFIGURATION_DIR "/etc" CACHE "Directory to store Akabei’s configuration files" STRING) set(CONFIGURATION_DIR "/etc" CACHE "Directory to store Akabei’s configuration files" STRING)
# Create a Config.cmake and a ConfigVersion.cmake file and install them
set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/akabeicore") set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/akabeicore")
# Create the CMake Config files
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/AkabeiCoreConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/AkabeiCoreConfig.cmake"
INSTALL_DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/AkabeiCoreConfigVersion.cmake"
VERSION ${AKABEI_VERSION_STRING}
COMPATIBILITY AnyNewerVersion
)
configure_file( configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/akabeicoreconfig.h.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/akabeicoreconfig.h.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/akabeicoreconfig.h" "${CMAKE_CURRENT_BINARY_DIR}/akabeicoreconfig.h"
IMMEDIATE @ONLY) IMMEDIATE @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/AkabeiCoreConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/AkabeiCoreConfigVersion.cmake"
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
COMPONENT Devel)
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
add_subdirectory(lib) add_subdirectory(lib)
add_subdirectory(tools) add_subdirectory(tools)
......
# based on https://github.com/forexample/package-example
set(AKABEI_CORE_SRCS set(AKABEI_CORE_SRCS
akabeibackend.cpp akabeibackend.cpp
akabeiconfig.cpp akabeiconfig.cpp
...@@ -86,13 +87,17 @@ operations/akabeiplainhookoperation.h ...@@ -86,13 +87,17 @@ operations/akabeiplainhookoperation.h
operations/akabeioperationutils.h operations/akabeioperationutils.h
) )
####
# Create targets
add_library(akabeicore SHARED ${AKABEI_CORE_SRCS} ${AKABEI_OPERATION_SRCS} ${AKABEI_MISSING_MOCS}) add_library(akabeicore SHARED ${AKABEI_CORE_SRCS} ${AKABEI_OPERATION_SRCS} ${AKABEI_MISSING_MOCS})
target_include_directories(akabeicore PUBLIC # Global includes. Used by all targets
${CMAKE_CURRENT_BINARY_DIR}/lib # Note:
${CMAKE_CURRENT_BINARY_DIR}/tools/polkit-helper # * header location in project: foo/Bar.h
${CMAKE_SOURCE_DIR}/lib # * header can be included by C++ code `#include <foo/Bar.h>`
${CMAKE_SOURCE_DIR}/tools/polkit-helper target_include_directories(
akabeicore PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/>"
) )
set_target_properties(akabeicore PROPERTIES AUTOMOC TRUE) set_target_properties(akabeicore PROPERTIES AUTOMOC TRUE)
...@@ -107,11 +112,77 @@ target_link_libraries(akabeicore Qt5::Core ...@@ -107,11 +112,77 @@ target_link_libraries(akabeicore Qt5::Core
${SQLITE_LIBRARIES} ${SQLITE_LIBRARIES}
${POLKITQT-1_LIBRARIES}) ${POLKITQT-1_LIBRARIES})
install(TARGETS akabeicore DESTINATION ${LIB_INSTALL_DIR}) # 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 akabeicore
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_CORE_HDRS} DESTINATION ${INCLUDES_INSTALL_DIR}) install(FILES ${AKABEI_CORE_HDRS} DESTINATION ${INCLUDES_INSTALL_DIR})
install(FILES ${AKABEI_OPERATION_HDRS} DESTINATION ${INCLUDES_INSTALL_DIR}/operations) install(FILES ${AKABEI_OPERATION_HDRS} DESTINATION ${INCLUDES_INSTALL_DIR}/operations)
install(FILES ${AKABEI_ARCHIVE_HDRS} DESTINATION ${INCLUDES_INSTALL_DIR}/libarchive++) install(FILES ${AKABEI_ARCHIVE_HDRS} DESTINATION ${INCLUDES_INSTALL_DIR}/libarchive++)
# Config
# * <prefix>/lib/cmake/AkabeiCore/AkabeiCoreConfig.cmake
# * <prefix>/lib/cmake/AkabeiCore/AkabeiCoreConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
# Config
# * <prefix>/lib/cmake/AkabeiCore/AkabeiCoreTargets.cmake
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
add_subdirectory(benchmarks) add_subdirectory(benchmarks)
if(BUILD_TESTS) if(BUILD_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