Advertisement
Guest User

Untitled

a guest
Sep 12th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 4.14 KB | None | 0 0
  1. cmake_minimum_required(VERSION 3.0)
  2. project(Cacatuidae VERSION 0.0.1 LANGUAGES CXX)
  3.  
  4. #location of my own modules, basically the include path to include "ColoredMessage" helper in this case
  5. set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/CMakeModules)
  6.  
  7. #include some helpful utility functions
  8. include(ColoredMessage)  #my own helper
  9. include(CMakePackageConfigHelpers) #provided by CMake, required for "write_basic_package_version_file"
  10.  
  11. # ┌──────────────────────────────────────────────────────────────────┐
  12. # │  Options                                                         │
  13. # └──────────────────────────────────────────────────────────────────┘
  14.  
  15. set(INSTALL_LIB_DIR     lib     CACHE PATH "Installation directory for libraries")
  16. set(INSTALL_BIN_DIR     bin     CACHE PATH "Installation directory for executables")
  17. set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
  18.  
  19. #can be ignored. I just used it because I didn't want to install my testing lib to my /usr/local,
  20. #so I default it to the projects "install" dir. Better practice would be to just pass this path
  21. #as param directly when calling cmake.
  22. if(NOT ${CMAKE_INSTALL_PREFIX})
  23.     set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install/")
  24.     message("CMAKE_INSTALL_PREFIX not set. Using ${CMAKE_INSTALL_PREFIX} instead.")
  25. endif()
  26.  
  27. #location of the config file, used by other CMakeFile projects to include this one
  28. set(ConfigPackageLocation ${CMAKE_INSTALL_PREFIX}/cmake/Cacatuidae)
  29.  
  30.  
  31. #just a single var to define all components
  32. set(Cacatuidae_Targets cacGraphics)
  33.  
  34.  
  35. foreach(var ${Cacatuidae_Targets})
  36. #ideally I would have used add_subdirectory. However, CMake doesn't like the use of outside target for the
  37. #installation part. The alternative would be to do the installation part inside the CMakeLists of each of the components.
  38.     include(${CMAKE_CURRENT_LIST_DIR}/src/${var}/CMakeLists.txt)
  39. endforeach()
  40.  
  41. # ┌──────────────────────────────────────────────────────────────────┐
  42. # │  INSTALL                                                         │
  43. # └──────────────────────────────────────────────────────────────────┘
  44.  
  45. #used for install paths to put the lib into the dir, matching the system config. for example Linux/x86_64
  46. set(INSTALL_PATH ${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})
  47.  
  48. #set install paths
  49. install(TARGETS ${Cacatuidae_Targets} EXPORT CacatuidaeTargets
  50.     LIBRARY  DESTINATION ${INSTALL_LIB_DIR}/Cacatuidae/${INSTALL_PATH}
  51.     ARCHIVE  DESTINATION ${INSTALL_LIB_DIR}/Cacatuidae/${INSTALL_PATH}
  52.     RUNTIME  DESTINATION ${INSTALL_BIN_DIR}/Cacatuidae/${INSTALL_PATH}
  53. )
  54.  
  55.  
  56. #install include
  57. install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/ DESTINATION ${INSTALL_INCLUDE_DIR})
  58.  
  59.  
  60. #writing the config file, which will be used by people who use CMake to use this lib
  61. write_basic_package_version_file(
  62.   "${ConfigPackageLocation}/CacatuidaeConfigVersion.cmake"
  63.   VERSION ${Upstream_VERSION}
  64.   COMPATIBILITY AnyNewerVersion
  65. )
  66.  
  67. export(EXPORT CacatuidaeTargets
  68.     FILE "${ConfigPackageLocation}/CacatuidaeTargets.cmake"
  69.     NAMESPACE CAC::
  70. )
  71.  
  72. configure_file(cmake/CacatuidaeConfig.cmake
  73.     "${ConfigPackageLocation}/CacatuidaeConfig.cmake"
  74.     COPYONLY
  75. )
  76.  
  77. #optinal, installing custom helpers and toolchain files. I use them for android and emscripten cross-compilation
  78. install(DIRECTORY cmake/toolchains DESTINATION ${ConfigPackageLocation})
  79. install(DIRECTORY cmake/CMakeModules DESTINATION ${ConfigPackageLocation})
  80.  
  81. #finally install the targets.
  82. install(EXPORT CacatuidaeTargets
  83.     FILE CacatuidaeTargets.cmake
  84.     NAMESPACE CAC::
  85.     DESTINATION ${ConfigPackageLocation}
  86. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement