CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
  2. PROJECT(ARTIS_STAR CXX C)
  3. ENABLE_TESTING()
  4. SET(CMAKE_CXX_STANDARD 17)
  5. SET(CMAKE_CXX_STANDARD_REQUIRED ON)
  6. SET(ARTIS_STAR_MAJOR 1)
  7. SET(ARTIS_STAR_MINOR 0)
  8. SET(ARTIS_STAR_PATCH 0)
  9. SET(ARTIS_STAR_EXTRA "")
  10. SET(ARTIS_STAR_VERSION "${ARTIS_STAR_MAJOR}.${ARTIS_STAR_MINOR}.${ARTIS_STAR_PATCH}")
  11. SET(ARTIS_STAR_VERSION_SHORT "${ARTIS_STAR_MAJOR}.${ARTIS_STAR_MINOR}")
  12. SET(ARTIS_STAR_NAME "artis-star")
  13. SET(ARTIS_STAR_NAME_VERSION "${ARTIS_STAR_NAME}-${ARTIS_STAR_VERSION}")
  14. SET(ARTIS_STAR_LOCALE_NAME "${ARTIS_STAR_NAME}-${ARTIS_STAR_MAJOR}-${ARTIS_STAR_MINOR}")
  15. IF ("${ARTIS_STAR_EXTRA}" STREQUAL "")
  16. SET(ARTIS_STAR_COMPLETE "${ARTIS_STAR_MAJOR}.${ARTIS_STAR_MINOR}.${ARTIS_STAR_PATCH}")
  17. ELSE ("${ARTIS_STAR_EXTRA}" STREQUAL "")
  18. SET(ARTIS_STAR_COMPLETE "${ARTIS_STAR_MAJOR}.${ARTIS_STAR_MINOR}.${ARTIS_STAR_PATCH}-${ARTIS_STAR_EXTRA}")
  19. ENDIF ("${ARTIS_STAR_EXTRA}" STREQUAL "")
  20. SET(ARTIS_STAR_NAME_COMPLETE "${ARTIS_STAR_NAME}-${ARTIS_STAR_COMPLETE}")
  21. #
  22. # Installation variables
  23. #
  24. SET(ARTIS_STAR_LIBRARY_DIRS "lib/artis-star-${ARTIS_STAR_VERSION_SHORT}")
  25. SET(ARTIS_STAR_INCLUDE_DIRS "include/artis-star-${ARTIS_STAR_VERSION_SHORT}/artis-star")
  26. SET(ARTIS_STAR_INCLUDE_DIR "include/artis-star-${ARTIS_STAR_VERSION_SHORT}")
  27. SET(ARTIS_STAR_MANPAGE_PATH "share/man/man1")
  28. SET(ARTIS_STAR_SHARE_DIRS "share/artis-star-${ARTIS_STAR_VERSION_SHORT}")
  29. #
  30. # Append the library version information to the library target
  31. # properties.
  32. #
  33. SET(ARTIS_STAR_LIBRARY_PROPERTIES VERSION 0)
  34. SET(ARTIS_STAR_APP_PROPERTIES SOVERSION "${ARTIS_STAR_MAJOR}.${ARTIS_STAR_MINOR}"
  35. VERSION "${ARTIS_STAR_MAJOR}.${ARTIS_STAR_MINOR}")
  36. #
  37. # Debug mode
  38. #
  39. IF (CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
  40. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
  41. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++17 -pthread")
  42. IF (UNIX)
  43. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
  44. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
  45. ENDIF (UNIX)
  46. ENDIF (CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
  47. if (CMAKE_BUILD_TYPE STREQUAL "")
  48. SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build" FORCE)
  49. endif ()
  50. #
  51. # Modules
  52. #
  53. INCLUDE(CheckIncludeFileCXX)
  54. INCLUDE(CheckIncludeFile)
  55. INCLUDE(CheckLibraryExists)
  56. INCLUDE(CMakeDetermineCCompiler)
  57. #
  58. # Boost libraries
  59. #
  60. set(Boost_USE_STATIC_LIBS OFF)
  61. set(Boost_USE_MULTITHREADED ON)
  62. set(Boost_USE_STATIC_RUNTIME OFF)
  63. find_package(Boost 1.71 COMPONENTS mpi serialization unit_test_framework)
  64. #
  65. # Generate the config.h
  66. #
  67. CHECK_INCLUDE_FILE_CXX(cxxabi.h ARTIS_STAR_HAVE_GCC_ABI_DEMANGLE)
  68. CHECK_INCLUDE_FILE_CXX(execinfo.h ARTIS_STAR_HAVE_EXECINFO)
  69. CHECK_INCLUDE_FILE_CXX(signal.h ARTIS_STAR_HAVE_SIGNAL)
  70. INCLUDE_DIRECTORIES(${ARTIS_STAR_BINARY_DIR})
  71. #
  72. # Generate the artis.pc pkg-config file.
  73. #
  74. SET(ARTIS_STAR_PKGCONFIG_PREFIXPATH "${CMAKE_INSTALL_PREFIX}")
  75. SET(ARTIS_STAR_PKGCONFIG_BOOSTINCLUDE_DIRS "${Boost_INCLUDE_DIRS}")
  76. SET(ARTIS_STAR_PKGCONFIG_LIBDIR "lib")
  77. CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/src/artis-star.pc.in
  78. ${ARTIS_STAR_BINARY_DIR}/artis-star-${ARTIS_STAR_VERSION_SHORT}.pc @ONLY)
  79. INSTALL(FILES ${ARTIS_STAR_BINARY_DIR}/artis-star-${ARTIS_STAR_VERSION_SHORT}.pc
  80. DESTINATION lib/pkgconfig)
  81. #
  82. # Install the README
  83. #
  84. IF (UNIX)
  85. INSTALL(FILES "README" DESTINATION "${ARTIS_STAR_SHARE_DIRS}")
  86. INSTALL(FILES "COPYING" DESTINATION "${ARTIS_STAR_SHARE_DIRS}")
  87. ELSE (UNIX)
  88. INSTALL(FILES "README" DESTINATION "${ARTIS_STAR_SHARE_DIRS}" RENAME "Readme.txt")
  89. INSTALL(FILES "COPYING" DESTINATION "${ARTIS_STAR_SHARE_DIRS}" RENAME "CopyRight.txt")
  90. ENDIF (UNIX)
  91. #
  92. # Add sources for a target
  93. # add_sources(<target> <source1> [<source2> ...])
  94. #
  95. function(ADD_SOURCES target)
  96. get_property(prop_defined GLOBAL PROPERTY ${target}_SRCS DEFINED)
  97. if(NOT prop_defined)
  98. define_property(GLOBAL PROPERTY ${target}_SRCS
  99. BRIEF_DOCS "Sources for the ${target} target"
  100. FULL_DOCS "List of source files for the ${target} target")
  101. endif()
  102. set(SRCS)
  103. foreach(src ${ARGN})
  104. if(NOT IS_ABSOLUTE "${src}")
  105. get_filename_component(src "${src}" ABSOLUTE)
  106. endif()
  107. list(APPEND SRCS "${src}")
  108. endforeach()
  109. set_property(GLOBAL APPEND PROPERTY "${target}_SRCS" "${SRCS}")
  110. endfunction()
  111. #
  112. # Browse the src subdirectory
  113. #
  114. ADD_SUBDIRECTORY(src)
  115. ADD_SUBDIRECTORY(tests)
  116. #
  117. # Status
  118. #
  119. MESSAGE(STATUS "- - - -")
  120. MESSAGE(STATUS "${ARTIS_STAR_NAME_COMPLETE} configured successfully")
  121. MESSAGE(STATUS "Using ${CMAKE_INSTALL_PREFIX} for installation")
  122. MESSAGE(STATUS "Build type ${CMAKE_BUILD_TYPE}")
  123. IF (ARTIS_STAR_HAVE_GCC_ABI_DEMANGLE)
  124. MESSAGE(STATUS "Build with GCC ABI Demangle...: yes")
  125. ENDIF (ARTIS_STAR_HAVE_GCC_ABI_DEMANGLE)
  126. IF (ARTIS_STAR_HAVE_EXECINFO)
  127. MESSAGE(STATUS "Build with execinfo.h.........: yes")
  128. ENDIF (ARTIS_STAR_HAVE_EXECINFO)
  129. IF (Boost_FOUND)
  130. MESSAGE(STATUS "Build with boost..............: yes")
  131. ENDIF (Boost_FOUND)