CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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(QAtools)
  4. # You need to tell CMake where to find the ROOT installation. This can be done
  5. # in a number of ways:
  6. # - ROOT built with classic configure/make use the provided
  7. # $ROOTSYS/etc/cmake/FindROOT.cmake
  8. # - ROOT built with CMake. Add in CMAKE_PREFIX_PATH the installation prefix
  9. # for ROOT
  10. find_package(Git)
  11. list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
  12. #---Locate the ROOT package and defines a number of variables (e.g. ROOT_INCLUDE_DIRS)
  13. find_package(ROOT REQUIRED COMPONENTS MathCore RIO Hist Tree Net EG)
  14. #---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)
  15. include(${ROOT_USE_FILE})
  16. add_definitions(${ROOT_CXX_FLAGS})
  17. #---Locate MCINI package
  18. find_library(MCINI NAMES McIniData PATHS $ENV{MCINI})
  19. IF(MCINI)
  20. message(STATUS "mcini is found: ${MCINI}")
  21. add_definitions("-D_MCINI_")
  22. endif()
  23. IF(NOT MCINI)
  24. message(STATUS "mcini is not found. Building without it.")
  25. endif()
  26. #---Locate PHQMDEvent library
  27. find_library(PHQMD NAMES PHQMDEvent PATHS $ENV{PHQMD_PATH}/phqmd2root/lib/)
  28. if(PHQMD)
  29. message(STATUS "libPHQMDEvent is found: ${PHQMD}")
  30. add_definitions("-D_PHQMD_")
  31. add_definitions("-D_HSD_ROOT_")
  32. endif()
  33. if(NOT PHQMD)
  34. message(STATUS "libPHQMDEvent is not found. Building without it.")
  35. endif()
  36. set(CMAKE_BUILD_TYPE Debug)
  37. #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -Wall -pthread")
  38. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -ffast-math")
  39. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall")
  40. set(QATOOLS_INCLUDE_DIRECTORIES
  41. ${CMAKE_CURRENT_SOURCE_DIR}
  42. ${CMAKE_CURRENT_SOURCE_DIR}/bin
  43. ${CMAKE_CURRENT_SOURCE_DIR}/format
  44. ${CMAKE_CURRENT_SOURCE_DIR}/readers
  45. ${CMAKE_CURRENT_SOURCE_DIR}/utility
  46. ${ROOT_INLCUDE_DIRS}
  47. )
  48. set(QATOOLS_INCLUDE_LIBRARIES
  49. ${ROOT_LIBRARIES}
  50. )
  51. set(QATOOLS_LIBRARY_h_files
  52. ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticle.h
  53. ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticleLight.h
  54. ${CMAKE_CURRENT_SOURCE_DIR}/format/qaEvent.h
  55. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_smash_root.h
  56. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.h
  57. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.h
  58. ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.h
  59. )
  60. set(QATOOLS_LIBRARY_cxx_files
  61. ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticle.cxx
  62. ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticleLight.cxx
  63. ${CMAKE_CURRENT_SOURCE_DIR}/format/qaEvent.cxx
  64. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_smash_root.cxx
  65. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.cxx
  66. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.cxx
  67. ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.cxx
  68. )
  69. if(MCINI)
  70. list(APPEND QATOOLS_INCLUDE_DIRECTORIES $ENV{MCINI}/include)
  71. list(APPEND QATOOLS_INCLUDE_LIBRARIES ${MCINI})
  72. list(APPEND QATOOLS_LIBRARY_h_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcini.h)
  73. list(APPEND QATOOLS_LIBRARY_cxx_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcini.cxx)
  74. endif()
  75. if(PHQMD)
  76. list(APPEND QATOOLS_INCLUDE_DIRECTORIES $ENV{PHQMD_PATH})
  77. list(APPEND QATOOLS_INCLUDE_LIBRARIES ${PHQMD})
  78. list(APPEND QATOOLS_LIBRARY_h_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_phqmd.h)
  79. list(APPEND QATOOLS_LIBRARY_cxx_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_phqmd.cxx)
  80. list(APPEND QATOOLS_LIBRARY_h_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_hsd_root.h)
  81. list(APPEND QATOOLS_LIBRARY_cxx_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_hsd_root.cxx)
  82. endif()
  83. include_directories(${QATOOLS_INCLUDE_DIRECTORIES})
  84. set(QATOOLS_LinkDef
  85. ${CMAKE_CURRENT_SOURCE_DIR}/qaTools.LinkDef.h
  86. )
  87. #---Generate dictionary
  88. ROOT_GENERATE_DICTIONARY(G__qaTools
  89. ${QATOOLS_LIBRARY_h_files}
  90. LINKDEF ${QATOOLS_LinkDef}
  91. )
  92. #---Compile library
  93. add_library(qaTools SHARED ${QATOOLS_LIBRARY_cxx_files} G__qaTools.cxx)
  94. target_link_libraries(qaTools ${QATOOLS_INCLUDE_LIBRARIES})
  95. # Get the current working branch
  96. execute_process(
  97. COMMAND git rev-parse --abbrev-ref HEAD
  98. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  99. OUTPUT_VARIABLE GIT_BRANCH
  100. RESULT_VARIABLE GIT_BRANCH_ERROR_CODE
  101. OUTPUT_STRIP_TRAILING_WHITESPACE
  102. )
  103. if( GIT_BRANCH_ERROR_CODE )
  104. set(GIT_BRANCH 0)
  105. endif()
  106. # Get the latest abbreviated commit hash of the working branch
  107. execute_process(
  108. COMMAND git rev-parse --short HEAD
  109. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  110. OUTPUT_VARIABLE GIT_COMMIT_HASH
  111. RESULT_VARIABLE GIT_COMMIT_HASH_ERROR_CODE
  112. OUTPUT_STRIP_TRAILING_WHITESPACE
  113. )
  114. if( GIT_COMMIT_HASH_ERROR_CODE )
  115. set(GIT_COMMIT_HASH 0)
  116. endif()
  117. # Get the current version
  118. execute_process(
  119. COMMAND git describe --tags --match "*"
  120. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  121. OUTPUT_VARIABLE GIT_TAG_VERSION
  122. RESULT_VARIABLE GIT_TAG_VERSION_ERROR_CODE
  123. OUTPUT_STRIP_TRAILING_WHITESPACE
  124. )
  125. if( GIT_TAG_VERSION_ERROR_CODE )
  126. set(GIT_TAG_VERSION 0.0)
  127. endif()
  128. set_target_properties (qaTools
  129. PROPERTIES
  130. VERSION ${GIT_TAG_VERSION} SOVERSION ${GIT_BRANCH}-${GIT_COMMIT_HASH}
  131. )
  132. #---Compile main executable
  133. add_executable(qaProcess "${CMAKE_CURRENT_SOURCE_DIR}/bin/main.cpp")
  134. target_link_libraries(qaProcess qaTools)