CMakeLists.txt 3.4 KB

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