Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cmake_minimum_required(VERSION 3.0)
- project(Cacatuidae VERSION 0.0.1 LANGUAGES CXX)
- #location of my own modules, basically the include path to include "ColoredMessage" helper in this case
- set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/CMakeModules)
- #include some helpful utility functions
- include(ColoredMessage) #my own helper
- include(CMakePackageConfigHelpers) #provided by CMake, required for "write_basic_package_version_file"
- # ┌──────────────────────────────────────────────────────────────────┐
- # │ Options │
- # └──────────────────────────────────────────────────────────────────┘
- set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
- set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
- set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
- #can be ignored. I just used it because I didn't want to install my testing lib to my /usr/local,
- #so I default it to the projects "install" dir. Better practice would be to just pass this path
- #as param directly when calling cmake.
- if(NOT ${CMAKE_INSTALL_PREFIX})
- set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install/")
- message("CMAKE_INSTALL_PREFIX not set. Using ${CMAKE_INSTALL_PREFIX} instead.")
- endif()
- #location of the config file, used by other CMakeFile projects to include this one
- set(ConfigPackageLocation ${CMAKE_INSTALL_PREFIX}/cmake/Cacatuidae)
- #just a single var to define all components
- set(Cacatuidae_Targets cacGraphics)
- foreach(var ${Cacatuidae_Targets})
- #ideally I would have used add_subdirectory. However, CMake doesn't like the use of outside target for the
- #installation part. The alternative would be to do the installation part inside the CMakeLists of each of the components.
- include(${CMAKE_CURRENT_LIST_DIR}/src/${var}/CMakeLists.txt)
- endforeach()
- # ┌──────────────────────────────────────────────────────────────────┐
- # │ INSTALL │
- # └──────────────────────────────────────────────────────────────────┘
- #used for install paths to put the lib into the dir, matching the system config. for example Linux/x86_64
- set(INSTALL_PATH ${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})
- #set install paths
- install(TARGETS ${Cacatuidae_Targets} EXPORT CacatuidaeTargets
- LIBRARY DESTINATION ${INSTALL_LIB_DIR}/Cacatuidae/${INSTALL_PATH}
- ARCHIVE DESTINATION ${INSTALL_LIB_DIR}/Cacatuidae/${INSTALL_PATH}
- RUNTIME DESTINATION ${INSTALL_BIN_DIR}/Cacatuidae/${INSTALL_PATH}
- )
- #install include
- install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/ DESTINATION ${INSTALL_INCLUDE_DIR})
- #writing the config file, which will be used by people who use CMake to use this lib
- write_basic_package_version_file(
- "${ConfigPackageLocation}/CacatuidaeConfigVersion.cmake"
- VERSION ${Upstream_VERSION}
- COMPATIBILITY AnyNewerVersion
- )
- export(EXPORT CacatuidaeTargets
- FILE "${ConfigPackageLocation}/CacatuidaeTargets.cmake"
- NAMESPACE CAC::
- )
- configure_file(cmake/CacatuidaeConfig.cmake
- "${ConfigPackageLocation}/CacatuidaeConfig.cmake"
- COPYONLY
- )
- #optinal, installing custom helpers and toolchain files. I use them for android and emscripten cross-compilation
- install(DIRECTORY cmake/toolchains DESTINATION ${ConfigPackageLocation})
- install(DIRECTORY cmake/CMakeModules DESTINATION ${ConfigPackageLocation})
- #finally install the targets.
- install(EXPORT CacatuidaeTargets
- FILE CacatuidaeTargets.cmake
- NAMESPACE CAC::
- DESTINATION ${ConfigPackageLocation}
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement