2016-04-16 00:50:16 +02:00
|
|
|
# before including this module, BasicConfig must be included
|
|
|
|
|
|
|
|
# include for configure_package_config_file and write_basic_package_version_file
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
|
|
|
|
# find template for CMake config file
|
2016-06-09 22:57:51 +02:00
|
|
|
include(TemplateFinder)
|
|
|
|
find_template_file("Config.cmake" CPP_UTILITIES CONFIG_TEMPLATE_FILE)
|
2016-04-16 00:50:16 +02:00
|
|
|
|
2016-06-29 18:43:44 +02:00
|
|
|
# determine library directory suffix
|
|
|
|
set(LIB_SUFFIX "" CACHE STRING "specifies the general suffix for the library directory")
|
|
|
|
set(SELECTED_LIB_SUFFIX "${LIB_SUFFIX}")
|
|
|
|
set(LIB_SUFFIX_32 "" CACHE STRING "specifies the suffix for the library directory to be used when building 32-bit library")
|
|
|
|
set(LIB_SUFFIX_64 "" CACHE STRING "specifies the suffix for the library directory to be used when building 64-bit library")
|
|
|
|
if(CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT ${LIB_SUFFIX_64} STREQUAL "")
|
|
|
|
set(SELECTED_LIB_SUFFIX "${LIB_SUFFIX_64}")
|
|
|
|
elseif(CMAKE_SIZEOF_VOID_P MATCHES "4" AND NOT ${LIB_SUFFIX_32} STREQUAL "")
|
|
|
|
set(SELECTED_LIB_SUFFIX "${LIB_SUFFIX_32}")
|
|
|
|
endif()
|
|
|
|
|
2016-04-16 00:50:16 +02:00
|
|
|
# set install destination for the CMake modules, config files and header files
|
|
|
|
set(HEADER_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/include")
|
2016-07-16 23:04:22 +02:00
|
|
|
set(BIN_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
|
2016-06-29 18:43:44 +02:00
|
|
|
set(LIB_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${SELECTED_LIB_SUFFIX}")
|
2016-04-16 00:50:16 +02:00
|
|
|
set(CMAKE_MODULE_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${META_PROJECT_NAME}/cmake/modules")
|
|
|
|
set(CMAKE_CONFIG_INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${META_PROJECT_NAME}/cmake")
|
|
|
|
|
|
|
|
# remove library prefix when building with mingw-w64 (just for consistency with qmake)
|
|
|
|
if(MINGW)
|
|
|
|
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
|
|
|
endif(MINGW)
|
|
|
|
|
|
|
|
# set the windows extension to "dll", this is required by the mingw-w64 specific WindowsResources module
|
|
|
|
if(MINGW)
|
|
|
|
set(WINDOWS_EXT "dll")
|
|
|
|
endif(MINGW)
|
|
|
|
|
|
|
|
# add target for building the library
|
2016-07-10 00:16:24 +02:00
|
|
|
option(BUILD_SHARED_LIBS "whether to build dynamic libraries (enabled by default)" ON)
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
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})
|
|
|
|
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${LIBRARIES})
|
|
|
|
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} PROPERTIES
|
|
|
|
VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}
|
|
|
|
SOVERSION ${META_VERSION_MAJOR}
|
|
|
|
CXX_STANDARD 11
|
|
|
|
)
|
|
|
|
endif()
|
2016-04-16 00:50:16 +02:00
|
|
|
|
2016-05-28 01:52:55 +02:00
|
|
|
# add target for building a static version of the library
|
2016-04-16 00:50:16 +02:00
|
|
|
if(MINGW)
|
2016-07-10 00:16:24 +02:00
|
|
|
option(BUILD_STATIC_LIBS "whether to build static libraries (enabled by default on mingw-w64 platform)" ON)
|
2016-05-28 01:52:55 +02:00
|
|
|
else()
|
2016-07-10 00:16:24 +02:00
|
|
|
option(BUILD_STATIC_LIBS "whether to build static libraries (disabled by default on none-mingw-w64- platform)" OFF)
|
2016-05-28 01:52:55 +02:00
|
|
|
endif()
|
2016-07-10 00:16:24 +02:00
|
|
|
if(BUILD_STATIC_LIBS)
|
2016-04-16 00:50:16 +02:00
|
|
|
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
|
2016-07-22 01:35:32 +02:00
|
|
|
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static ${STATIC_LIBRARIES})
|
2016-04-16 00:50:16 +02:00
|
|
|
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static PROPERTIES
|
|
|
|
VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}
|
|
|
|
SOVERSION ${META_VERSION_MAJOR}
|
|
|
|
OUTPUT_NAME ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
|
|
|
|
CXX_STANDARD 11
|
|
|
|
)
|
2016-07-22 01:35:32 +02:00
|
|
|
set(META_LIB_DEPENDS ${${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static_LIB_DEPENDS}) # used in config file
|
2016-07-10 00:16:24 +02:00
|
|
|
endif()
|
2016-04-16 00:50:16 +02:00
|
|
|
|
2016-07-22 01:35:32 +02:00
|
|
|
# create the CMake config file from the template
|
|
|
|
configure_package_config_file(
|
|
|
|
"${CONFIG_TEMPLATE_FILE}"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}Config.cmake"
|
|
|
|
INSTALL_DESTINATION
|
|
|
|
"${CMAKE_CONFIG_INSTALL_DESTINATION}"
|
|
|
|
PATH_VARS
|
|
|
|
CMAKE_MODULE_INSTALL_DESTINATION
|
|
|
|
CMAKE_CONFIG_INSTALL_DESTINATION
|
|
|
|
HEADER_INSTALL_DESTINATION
|
|
|
|
BIN_INSTALL_DESTINATION
|
|
|
|
LIB_INSTALL_DESTINATION
|
|
|
|
)
|
|
|
|
|
|
|
|
# write the CMake version config file
|
|
|
|
write_basic_package_version_file(
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}ConfigVersion.cmake
|
|
|
|
VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}"
|
|
|
|
COMPATIBILITY SameMajorVersion
|
|
|
|
)
|
|
|
|
|
2016-04-16 00:50:16 +02:00
|
|
|
# add install target for the CMake config files
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}Config.cmake"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}ConfigVersion.cmake"
|
|
|
|
DESTINATION
|
|
|
|
"${CMAKE_CONFIG_INSTALL_DESTINATION}"
|
|
|
|
COMPONENT
|
|
|
|
cmake-config
|
|
|
|
)
|
|
|
|
|
|
|
|
if(NOT TARGET install-cmake-config)
|
|
|
|
add_custom_target(install-cmake-config
|
|
|
|
DEPENDS ${META_PROJECT_NAME}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=cmake-config -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add install target for dynamic libs
|
2016-07-10 00:16:24 +02:00
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
install(
|
|
|
|
TARGETS ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
COMPONENT binary
|
|
|
|
LIBRARY DESTINATION lib${SELECTED_LIB_SUFFIX}
|
|
|
|
COMPONENT binary
|
|
|
|
ARCHIVE DESTINATION lib${SELECTED_LIB_SUFFIX}
|
|
|
|
COMPONENT binary
|
|
|
|
)
|
|
|
|
endif()
|
2016-04-16 00:50:16 +02:00
|
|
|
|
|
|
|
if(NOT TARGET install-binary)
|
|
|
|
add_custom_target(install-binary
|
|
|
|
DEPENDS ${META_PROJECT_NAME}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=binary -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add install for static libs when building with mingw-w64
|
2016-07-10 00:16:24 +02:00
|
|
|
if(BUILD_STATIC_LIBS)
|
2016-04-16 00:50:16 +02:00
|
|
|
install(
|
|
|
|
TARGETS ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
COMPONENT binary
|
2016-06-29 18:43:44 +02:00
|
|
|
LIBRARY DESTINATION lib${SELECTED_LIB_SUFFIX}
|
2016-04-16 00:50:16 +02:00
|
|
|
COMPONENT binary
|
2016-06-29 18:43:44 +02:00
|
|
|
ARCHIVE DESTINATION lib${SELECTED_LIB_SUFFIX}
|
2016-04-16 00:50:16 +02:00
|
|
|
COMPONENT binary
|
|
|
|
)
|
2016-07-10 00:16:24 +02:00
|
|
|
endif()
|
2016-04-16 00:50:16 +02:00
|
|
|
|
|
|
|
# add install target for stripped libs
|
|
|
|
if(NOT TARGET install-binary-strip)
|
|
|
|
add_custom_target(install-binary-strip
|
|
|
|
DEPENDS ${META_PROJECT_NAME}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_DO_STRIP=1 -DCMAKE_INSTALL_COMPONENT=binary -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add install target for header files
|
2016-04-16 18:32:22 +02:00
|
|
|
foreach(HEADER_FILE ${HEADER_FILES} ${ADDITIONAL_HEADER_FILES})
|
2016-04-16 00:50:16 +02:00
|
|
|
get_filename_component(HEADER_DIR "${HEADER_FILE}" DIRECTORY)
|
|
|
|
install(
|
|
|
|
FILES "${HEADER_FILE}"
|
|
|
|
DESTINATION "include/${META_PROJECT_NAME}/${HEADER_DIR}"
|
|
|
|
COMPONENT header
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(NOT TARGET install-header)
|
|
|
|
add_custom_target(install-header
|
|
|
|
DEPENDS ${META_PROJECT_NAME}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=header -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add install target for CMake modules
|
|
|
|
foreach(CMAKE_MODULE_FILE ${CMAKE_MODULE_FILES})
|
|
|
|
get_filename_component(CMAKE_MODULE_DIR ${CMAKE_MODULE_FILE} DIRECTORY)
|
|
|
|
install(
|
|
|
|
FILES ${CMAKE_MODULE_FILE}
|
|
|
|
DESTINATION share/${META_PROJECT_NAME}/${CMAKE_MODULE_DIR}
|
|
|
|
COMPONENT cmake-modules
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(NOT TARGET install-cmake-modules)
|
|
|
|
add_custom_target(install-cmake-modules
|
|
|
|
DEPENDS ${META_PROJECT_NAME}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=cmake-modules -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add install target for CMake templates
|
|
|
|
foreach(CMAKE_TEMPLATE_FILE ${CMAKE_TEMPLATE_FILES})
|
|
|
|
get_filename_component(CMAKE_TEMPLATE_DIR ${CMAKE_TEMPLATE_FILE} DIRECTORY)
|
|
|
|
install(
|
|
|
|
FILES ${CMAKE_TEMPLATE_FILE}
|
|
|
|
DESTINATION share/${META_PROJECT_NAME}/${CMAKE_TEMPLATE_DIR}
|
|
|
|
COMPONENT cmake-templates
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(NOT TARGET install-cmake-templates)
|
|
|
|
add_custom_target(install-cmake-templates
|
|
|
|
DEPENDS ${META_PROJECT_NAME}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=cmake-templates -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add install target for all the cmake stuff
|
|
|
|
if(NOT TARGET install-cmake-stuff)
|
|
|
|
add_custom_target(install-cmake-stuff
|
|
|
|
DEPENDS install-cmake-config install-cmake-modules install-cmake-templates
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add mingw-w64 specific install targets
|
|
|
|
if(NOT TARGET install-mingw-w64)
|
|
|
|
add_custom_target(install-mingw-w64
|
2016-04-16 18:32:22 +02:00
|
|
|
DEPENDS install-binary install-header install-cmake-stuff ${LOCALIZATION_TARGET}
|
2016-04-16 00:50:16 +02:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT TARGET install-mingw-w64-importlib-strip)
|
|
|
|
add_custom_target(install-mingw-w64-importlib-strip
|
|
|
|
DEPENDS install-binary-strip
|
2016-04-16 18:32:22 +02:00
|
|
|
COMMAND "${CMAKE_FIND_ROOT_PATH}/bin/strip" --strip-unneeded "\$\{DESTDIR\}\$\{DESTDIR:+/\}${CMAKE_INSTALL_PREFIX}/lib/lib${META_PROJECT_NAME}.dll.a"
|
2016-04-16 00:50:16 +02:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT TARGET install-mingw-w64-staticlib-strip)
|
|
|
|
add_custom_target(install-mingw-w64-staticlib-strip
|
|
|
|
DEPENDS install-binary-strip
|
2016-04-16 18:32:22 +02:00
|
|
|
COMMAND "${CMAKE_FIND_ROOT_PATH}/bin/strip" -g "\$\{DESTDIR\}\$\{DESTDIR:+/\}${CMAKE_INSTALL_PREFIX}/lib/lib${META_PROJECT_NAME}.a"
|
2016-04-16 00:50:16 +02:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT TARGET install-mingw-w64-strip)
|
|
|
|
add_custom_target(install-mingw-w64-strip
|
2016-04-16 18:32:22 +02:00
|
|
|
DEPENDS install-binary-strip install-mingw-w64-importlib-strip install-mingw-w64-staticlib-strip install-header install-cmake-stuff ${LOCALIZATION_TARGET}
|
2016-04-16 00:50:16 +02:00
|
|
|
)
|
|
|
|
endif()
|