CMakeLists.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # CMakeLists.txt for FAS package. It creates a library with dictionary and a main program
  2. cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
  3. project(MpdFlow)
  4. #---Add PicoDst submodule with PicoDst shared library
  5. find_library(PicoDst NAMES PicoDst PATHS ${PICO_DST_BIN})
  6. if (PicoDst)
  7. # If PicoDst is already installed, use the installed one
  8. message(STATUS "PicoDst is found: ${PicoDst}")
  9. endif()
  10. if (NOT PicoDst)
  11. # If PicoDst is not found in the system, compile it now
  12. message(STATUS "PicoDst is not found: Compiling it from the submodule")
  13. add_subdirectory(PicoDst)
  14. set (PicoDst PicoDst)
  15. endif()
  16. # You need to tell CMake where to find the ROOT installation. This can be done
  17. # in a number of ways:
  18. # - ROOT built with classic configure/make use the provided
  19. # $ROOTSYS/etc/cmake/FindROOT.cmake
  20. # - ROOT built with CMake. Add in CMAKE_PREFIX_PATH the installation prefix
  21. # for ROOT
  22. find_package(Git)
  23. list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
  24. #---Locate the ROOT package and defines a number of variables (e.g. ROOT_INCLUDE_DIRS)
  25. find_package(ROOT REQUIRED COMPONENTS MathCore RIO Hist Tree Net MathMore EG)
  26. #---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)
  27. include(${ROOT_USE_FILE})
  28. #---Add PicoDst library. Make sure setPicoDst.sh is executed
  29. # find_library(PicoDst NAMES PicoDst PATHS $ENV{PICO_DST_BIN})
  30. # if (PicoDst)
  31. # message(STATUS "PicoDst is found: ${PicoDst}")
  32. # endif()
  33. # if (NOT PicoDst)
  34. # message(FATAL_ERROR "PicoDst is NOT found! Make sure you have sourced setPicoDst.sh")
  35. # endif()
  36. #set (CMAKE_CXX_STANDARD 11)
  37. add_definitions(${ROOT_CXX_FLAGS})
  38. set(CMAKE_BUILD_TYPE Debug)
  39. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall -g")
  40. set(MPD_FLOW_INCLUDE_DIRECTORIES
  41. ${CMAKE_CURRENT_SOURCE_DIR}
  42. "${CMAKE_CURRENT_SOURCE_DIR}/utils"
  43. "${CMAKE_CURRENT_SOURCE_DIR}/qvector"
  44. "${CMAKE_CURRENT_SOURCE_DIR}/selector"
  45. "${CMAKE_CURRENT_SOURCE_DIR}/corrections"
  46. "${CMAKE_CURRENT_SOURCE_DIR}/inputreader"
  47. "${CMAKE_CURRENT_SOURCE_DIR}/eventanalysis"
  48. "${CMAKE_CURRENT_SOURCE_DIR}/bin"
  49. ${ROOT_INCLUDE_DIRS}
  50. $ENV{PICO_DST_INC}
  51. )
  52. include_directories(${MPD_FLOW_INCLUDE_DIRECTORIES})
  53. set(MPD_FLOW_INCLUDE_LIBRARIES
  54. ${PicoDst}
  55. ${ROOT_LIBRARIES}
  56. )
  57. set(MpdFlow_LinkDef "${CMAKE_CURRENT_SOURCE_DIR}/MpdFlow.LinkDef.h")
  58. file(GLOB MpdFlow_h_files
  59. "*/*.h"
  60. )
  61. list (REMOVE_ITEM MpdFlow_h_files ${MpdFlow_LinkDef})
  62. file(GLOB MpdFlow_cxx_files
  63. "*/*.cxx"
  64. )
  65. #---Generate dictionary
  66. ROOT_GENERATE_DICTIONARY(G__MpdFlow
  67. ${MpdFlow_h_files}
  68. LINKDEF ${MpdFlow_LinkDef}
  69. )
  70. #---Compile library
  71. add_library(MpdFlow SHARED ${MpdFlow_cxx_files} G__MpdFlow.cxx)
  72. target_link_libraries(MpdFlow ${MPD_FLOW_INCLUDE_LIBRARIES})
  73. #---Get the current working branch
  74. execute_process(
  75. COMMAND git rev-parse --abbrev-ref HEAD
  76. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  77. OUTPUT_VARIABLE GIT_BRANCH
  78. RESULT_VARIABLE GIT_BRANCH_ERROR_CODE
  79. OUTPUT_STRIP_TRAILING_WHITESPACE
  80. )
  81. if( GIT_BRANCH_ERROR_CODE )
  82. set(GIT_BRANCH 0)
  83. endif()
  84. #---Get the latest abbreviated commit hash of the working branch
  85. execute_process(
  86. COMMAND git rev-parse --short HEAD
  87. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  88. OUTPUT_VARIABLE GIT_COMMIT_HASH
  89. RESULT_VARIABLE GIT_COMMIT_HASH_ERROR_CODE
  90. OUTPUT_STRIP_TRAILING_WHITESPACE
  91. )
  92. if( GIT_COMMIT_HASH_ERROR_CODE )
  93. set(GIT_COMMIT_HASH 0)
  94. endif()
  95. #---Get the current version
  96. execute_process(
  97. COMMAND git describe --tags --match "*"
  98. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  99. OUTPUT_VARIABLE GIT_TAG_VERSION
  100. RESULT_VARIABLE GIT_TAG_VERSION_ERROR_CODE
  101. OUTPUT_STRIP_TRAILING_WHITESPACE
  102. )
  103. if( GIT_TAG_VERSION_ERROR_CODE )
  104. set(GIT_TAG_VERSION 0)
  105. endif()
  106. #---Set libMpdFlow.so properties
  107. set_target_properties(MpdFlow PROPERTIES
  108. VERSION ${GIT_TAG_VERSION} SOVERSION ${GIT_BRANCH}-${GIT_COMMIT_HASH}
  109. )
  110. #---Compile executables
  111. add_subdirectory(bin)