CMakeLists.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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(ModelConverter)
  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(MCONVERTER_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}/writers
  46. ${CMAKE_CURRENT_SOURCE_DIR}/utility
  47. ${ROOT_INLCUDE_DIRS}
  48. )
  49. set(MCONVERTER_INCLUDE_LIBRARIES
  50. ${ROOT_LIBRARIES}
  51. )
  52. set(MCONVERTER_LIBRARY_h_files
  53. ${CMAKE_CURRENT_SOURCE_DIR}/format/mciParticle.h
  54. ${CMAKE_CURRENT_SOURCE_DIR}/format/mciEvent.h
  55. ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_smash_root.h
  56. ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_mcpico.h
  57. ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_manager.h
  58. ${CMAKE_CURRENT_SOURCE_DIR}/writers/mciWriter_mcpico.h
  59. ${CMAKE_CURRENT_SOURCE_DIR}/writers/mciWriter_manager.h
  60. ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.h
  61. )
  62. set(MCONVERTER_LIBRARY_cxx_files
  63. ${CMAKE_CURRENT_SOURCE_DIR}/format/mciParticle.cxx
  64. ${CMAKE_CURRENT_SOURCE_DIR}/format/mciEvent.cxx
  65. ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_smash_root.cxx
  66. ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_mcpico.cxx
  67. ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_manager.cxx
  68. ${CMAKE_CURRENT_SOURCE_DIR}/writers/mciWriter_mcpico.cxx
  69. ${CMAKE_CURRENT_SOURCE_DIR}/writers/mciWriter_manager.cxx
  70. ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.cxx
  71. )
  72. if(MCINI)
  73. list(APPEND MCONVERTER_INCLUDE_DIRECTORIES $ENV{MCINI}/include)
  74. list(APPEND MCONVERTER_INCLUDE_LIBRARIES ${MCINI})
  75. list(APPEND MCONVERTER_LIBRARY_h_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_mcini.h)
  76. list(APPEND MCONVERTER_LIBRARY_cxx_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_mcini.cxx)
  77. endif()
  78. if(PHQMD)
  79. list(APPEND MCONVERTER_INCLUDE_DIRECTORIES $ENV{PHQMD_PATH})
  80. list(APPEND MCONVERTER_INCLUDE_LIBRARIES ${PHQMD})
  81. list(APPEND MCONVERTER_LIBRARY_h_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_phqmd.h)
  82. list(APPEND MCONVERTER_LIBRARY_cxx_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_phqmd.cxx)
  83. list(APPEND MCONVERTER_LIBRARY_h_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_hsd_root.h)
  84. list(APPEND MCONVERTER_LIBRARY_cxx_files ${CMAKE_CURRENT_SOURCE_DIR}/readers/mciReader_hsd_root.cxx)
  85. endif()
  86. include_directories(${MCONVERTER_INCLUDE_DIRECTORIES})
  87. set(MCONVERTER_LinkDef
  88. ${CMAKE_CURRENT_SOURCE_DIR}/mConverter.LinkDef.h
  89. )
  90. #---Generate dictionary
  91. ROOT_GENERATE_DICTIONARY(G__mConverter
  92. ${MCONVERTER_LIBRARY_h_files}
  93. LINKDEF ${MCONVERTER_LinkDef}
  94. )
  95. #---Compile library
  96. add_library(mConverter SHARED ${MCONVERTER_LIBRARY_cxx_files} G__mConverter.cxx)
  97. target_link_libraries(mConverter ${MCONVERTER_INCLUDE_LIBRARIES})
  98. # Get the current working branch
  99. execute_process(
  100. COMMAND git rev-parse --abbrev-ref HEAD
  101. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  102. OUTPUT_VARIABLE GIT_BRANCH
  103. RESULT_VARIABLE GIT_BRANCH_ERROR_CODE
  104. OUTPUT_STRIP_TRAILING_WHITESPACE
  105. )
  106. if( GIT_BRANCH_ERROR_CODE )
  107. set(GIT_BRANCH 0)
  108. endif()
  109. # Get the latest abbreviated commit hash of the working branch
  110. execute_process(
  111. COMMAND git rev-parse --short HEAD
  112. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  113. OUTPUT_VARIABLE GIT_COMMIT_HASH
  114. RESULT_VARIABLE GIT_COMMIT_HASH_ERROR_CODE
  115. OUTPUT_STRIP_TRAILING_WHITESPACE
  116. )
  117. if( GIT_COMMIT_HASH_ERROR_CODE )
  118. set(GIT_COMMIT_HASH 0)
  119. endif()
  120. # Get the current version
  121. execute_process(
  122. COMMAND git describe --tags --match "*"
  123. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  124. OUTPUT_VARIABLE GIT_TAG_VERSION
  125. RESULT_VARIABLE GIT_TAG_VERSION_ERROR_CODE
  126. OUTPUT_STRIP_TRAILING_WHITESPACE
  127. )
  128. if( GIT_TAG_VERSION_ERROR_CODE )
  129. set(GIT_TAG_VERSION 0.0)
  130. endif()
  131. set_target_properties (mConverter
  132. PROPERTIES
  133. VERSION ${GIT_TAG_VERSION} SOVERSION ${GIT_BRANCH}-${GIT_COMMIT_HASH}
  134. )
  135. #---Compile main executable
  136. add_executable(ModelConverter "${CMAKE_CURRENT_SOURCE_DIR}/bin/main.cpp")
  137. target_link_libraries(ModelConverter mConverter)