CMakeLists.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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}/build)
  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_epos4_root.h
  57. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.h
  58. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.h
  59. ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.h
  60. )
  61. set(QATOOLS_LIBRARY_cxx_files
  62. ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticle.cxx
  63. ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticleLight.cxx
  64. ${CMAKE_CURRENT_SOURCE_DIR}/format/qaEvent.cxx
  65. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_smash_root.cxx
  66. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_epos4_root.cxx
  67. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.cxx
  68. ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.cxx
  69. ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.cxx
  70. )
  71. if(MCINI)
  72. list(APPEND QATOOLS_INCLUDE_DIRECTORIES $ENV{MCINI}/include)
  73. list(APPEND QATOOLS_INCLUDE_LIBRARIES ${MCINI})
  74. list(APPEND QATOOLS_LIBRARY_h_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcini.h)
  75. list(APPEND QATOOLS_LIBRARY_cxx_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcini.cxx)
  76. endif()
  77. if(PHQMD)
  78. list(APPEND QATOOLS_INCLUDE_DIRECTORIES $ENV{PHQMD_PATH})
  79. list(APPEND QATOOLS_INCLUDE_LIBRARIES ${PHQMD})
  80. list(APPEND QATOOLS_LIBRARY_h_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_phqmd.h)
  81. list(APPEND QATOOLS_LIBRARY_cxx_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_phqmd.cxx)
  82. list(APPEND QATOOLS_LIBRARY_h_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_hsd_root.h)
  83. list(APPEND QATOOLS_LIBRARY_cxx_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_hsd_root.cxx)
  84. endif()
  85. include_directories(${QATOOLS_INCLUDE_DIRECTORIES})
  86. set(QATOOLS_LinkDef
  87. ${CMAKE_CURRENT_SOURCE_DIR}/qaTools.LinkDef.h
  88. )
  89. #---Generate dictionary
  90. ROOT_GENERATE_DICTIONARY(G__qaTools
  91. ${QATOOLS_LIBRARY_h_files}
  92. LINKDEF ${QATOOLS_LinkDef}
  93. )
  94. #---Compile library
  95. add_library(qaTools SHARED ${QATOOLS_LIBRARY_cxx_files} G__qaTools.cxx)
  96. target_link_libraries(qaTools ${QATOOLS_INCLUDE_LIBRARIES})
  97. # Get the current working branch
  98. execute_process(
  99. COMMAND git rev-parse --abbrev-ref HEAD
  100. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  101. OUTPUT_VARIABLE GIT_BRANCH
  102. RESULT_VARIABLE GIT_BRANCH_ERROR_CODE
  103. OUTPUT_STRIP_TRAILING_WHITESPACE
  104. )
  105. if( GIT_BRANCH_ERROR_CODE )
  106. set(GIT_BRANCH 0)
  107. endif()
  108. # Get the latest abbreviated commit hash of the working branch
  109. execute_process(
  110. COMMAND git rev-parse --short HEAD
  111. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  112. OUTPUT_VARIABLE GIT_COMMIT_HASH
  113. RESULT_VARIABLE GIT_COMMIT_HASH_ERROR_CODE
  114. OUTPUT_STRIP_TRAILING_WHITESPACE
  115. )
  116. if( GIT_COMMIT_HASH_ERROR_CODE )
  117. set(GIT_COMMIT_HASH 0)
  118. endif()
  119. # Get the current version
  120. execute_process(
  121. COMMAND git describe --tags --match "*"
  122. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  123. OUTPUT_VARIABLE GIT_TAG_VERSION
  124. RESULT_VARIABLE GIT_TAG_VERSION_ERROR_CODE
  125. OUTPUT_STRIP_TRAILING_WHITESPACE
  126. )
  127. if( GIT_TAG_VERSION_ERROR_CODE )
  128. set(GIT_TAG_VERSION 0.0)
  129. endif()
  130. set_target_properties (qaTools
  131. PROPERTIES
  132. VERSION ${GIT_TAG_VERSION} SOVERSION ${GIT_BRANCH}-${GIT_COMMIT_HASH}
  133. )
  134. #---Compile main executable
  135. add_executable(qaProcess "${CMAKE_CURRENT_SOURCE_DIR}/bin/main.cpp")
  136. target_link_libraries(qaProcess qaTools)