CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. cmake_minimum_required(VERSION 3.10)
  2. ################################################################################
  3. # This Top-level project is for a single Top-level library
  4. #
  5. # A single library
  6. # Unit tests for the library
  7. # A set of executables which use this library
  8. ################################################################################
  9. ################################################################################
  10. # Project name
  11. #
  12. # many targets will be created:
  13. # myProject::warnings
  14. # myProject:
  15. ################################################################################
  16. project( gul
  17. VERSION 1.0.0.0
  18. LANGUAGES CXX)
  19. ################################################################################
  20. include(.cmake/extras.cmake)
  21. option( ${PROJECT_NAME}_BUILD_UNIT_TESTS "Build the unit tests for this library" TRUE)
  22. option( ${PROJECT_NAME}_ENABLE_COVERAGE "Enable Coverage. After build, execute: make coverage" TRUE)
  23. option( ${PROJECT_NAME}_ENABLE_WARNINGS "Enable Strict Warnings" TRUE)
  24. option( ${PROJECT_NAME}_PACKAGE_INCLUDE_SOURCE "Include source files when building the package" TRUE)
  25. ################################################################################
  26. # Find all the packages we need
  27. #
  28. # Each module in the src/ folder can also define its own find_package
  29. # if they are meant to be private
  30. #
  31. ################################################################################
  32. #find_package(fmt REQUIRED)
  33. #find_package(glm REQUIRED)
  34. #find_package(glm REQUIRED)
  35. ################################################################################
  36. ################################################################################
  37. # Top level INTERFACE library which can be used to
  38. ################################################################################
  39. set(outName interface) # name of the library within the proje
  40. # Will create the target ${PROJECT_NAME}::${outName}
  41. set(PublicLinkedTargets "" ) # Any additional public targets you want to include
  42. #-------------------------------------------------------------------------------
  43. add_library( ${outName} INTERFACE )
  44. add_library( ${PROJECT_NAME}::${outName} ALIAS ${outName})
  45. target_compile_features( ${outName}
  46. INTERFACE
  47. cxx_std_20)
  48. target_compile_definitions( ${outName}
  49. INTERFACE
  50. CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}"
  51. CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}"
  52. )
  53. target_link_libraries( ${outName} INTERFACE ${PublicLinkedTargets})
  54. include(GNUInstallDirs)
  55. ################################################################################
  56. #####################################################
  57. # Macro get get all subdirectories
  58. #####################################################
  59. MACRO(SUBDIRLIST result curdir)
  60. FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
  61. SET(dirlist "")
  62. FOREACH(child ${children})
  63. IF(IS_DIRECTORY ${curdir}/${child})
  64. LIST(APPEND dirlist ${child})
  65. ENDIF()
  66. ENDFOREACH()
  67. SET(${result} ${dirlist})
  68. ENDMACRO()
  69. #####################################################
  70. #####################################################
  71. # Loop through all the subdirectories in the /src folder and
  72. # compile each of the folders into its own library
  73. #####################################################
  74. SUBDIRLIST(LIB_FOLDERS ${CMAKE_CURRENT_SOURCE_DIR}/src)
  75. FOREACH(subdir ${LIB_FOLDERS})
  76. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/${subdir}/CMakeLists.txt")
  77. add_subdirectory("src/${subdir}")
  78. endif()
  79. ENDFOREACH()
  80. # enable testing on the root folder so that we can run ctest from it,
  81. # otherwise we will have to CD into each sub folder to run the unit tests
  82. enable_testing()
  83. #####################################################
  84. ## PACKAGE
  85. #####################################################
  86. SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
  87. SET(CPACK_PACKAGE_VENDOR ${PROJECT_NAME})
  88. SET(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME};${PROJECT_NAME})
  89. SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${PROJECT_NAME}")
  90. SET(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
  91. SET(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
  92. SET(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
  93. SET(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
  94. SET(CPACK_PACKAGE_CONTACT "me")
  95. INCLUDE(InstallRequiredSystemLibraries)
  96. IF(WIN32 AND NOT UNIX)
  97. SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\${PROJECT_NAME}.exe")
  98. SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}${PROJECT_NAME}")
  99. SET(CPACK_NSIS_MODIFY_PATH ON)
  100. ENDIF(WIN32 AND NOT UNIX)
  101. #####################################################
  102. INCLUDE(CPack)
  103. return()