From 9840eeabe80eecb9a3b91f34b7fb4bf3845cc702 Mon Sep 17 00:00:00 2001 From: JosiahWI <41302989+JosiahWI@users.noreply.github.com> Date: Tue, 13 Apr 2021 14:08:16 -0500 Subject: [PATCH] CMake Config and Version exports (#22) --- CMakeLists.txt | 48 +++++++++++++++++++++++++++++----- Config.cmake.in | 5 ++++ source/Irrlicht/CMakeLists.txt | 10 ++----- 3 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index d23959dc..2c690db5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,11 @@ cmake_minimum_required(VERSION 3.5) -project(Irrlicht CXX) +project(Irrlicht + VERSION 1.9.0 + LANGUAGES CXX +) -set(IRRLICHT_VERSION_MAJOR 1) -set(IRRLICHT_VERSION_MINOR 9) -set(IRRLICHT_VERSION_RELEASE 0) - -set(VERSION "${IRRLICHT_VERSION_MAJOR}.${IRRLICHT_VERSION_MINOR}.${IRRLICHT_VERSION_RELEASE}") -message(STATUS "*** Building IrrlichtMt ${VERSION} ***") +message(STATUS "*** Building IrrlichtMt ${PROJECT_VERSION} ***") if(ANDROID) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/Android) @@ -28,3 +26,39 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") add_subdirectory(source/Irrlicht) + +# Installation of library and headers. +include(GNUInstallDirs) +install(TARGETS IrrlichtMt + EXPORT IrrlichtMt-export + DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) + +install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/IrrlichtMt" +) + +# Installation of CMake target and configuration files. +install(EXPORT IrrlichtMt-export + FILE IrrlichtMtTargets.cmake + NAMESPACE IrrlichtMt:: + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/IrrlichtMt" +) + +include(CMakePackageConfigHelpers) +configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/IrrlichtMtConfig.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/IrrlichtMt" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/IrrlichtMtConfigVersion.cmake" + COMPATIBILITY AnyNewerVersion +) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/IrrlichtMtConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/IrrlichtMtConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/IrrlichtMt" +) diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 00000000..96194f3c --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +if(NOT TARGET IrrlichtMt::IrrlichtMt) + include("${CMAKE_CURRENT_LIST_DIR}/IrrlichtMtTargets.cmake") +endif() diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 621f7bd8..f8bf8196 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -394,16 +394,10 @@ add_library(IrrlichtMt ) set_target_properties(IrrlichtMt PROPERTIES - VERSION ${VERSION} - SOVERSION ${IRRLICHT_VERSION_MAJOR}.${IRRLICHT_VERSION_MINOR} + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} ) if(WIN32) set_target_properties(IrrlichtMt PROPERTIES PREFIX "") # for DLL name endif() - -# Installation - -include(GNUInstallDirs) -install(TARGETS IrrlichtMt DESTINATION "${CMAKE_INSTALL_LIBDIR}") -install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/irrlichtmt")