Warning, /snippets/RootExamples/helloroot/CMakeLists.txt is written in an unsupported language. File is not indexed.
0001 # CMakeLists.txt for helloroot.
0002 # More complicated than needed but demonstrates making and linking your own libraries
0003 # cf. https://cliutils.gitlab.io/modern-cmake/chapters/packages/ROOT.html
0004 # https://root.cern/manual/integrate_root_into_my_cmake_project/
0005
0006 cmake_minimum_required(VERSION 3.10)
0007 project(helloroot VERSION 1.0 LANGUAGES CXX ) # not needed
0008
0009 # Find ROOT. Use at least 6.20 for smoother cmake support
0010 find_package(ROOT 6.20 REQUIRED )
0011
0012 message ( " ROOT Libraries = " ${ROOT_LIBRARIES} )
0013
0014 ###############################################################################################
0015
0016 # Main target is the libhelloroot library
0017 add_library(
0018 # You can use wildcards but it's cleaner to list the files explicitly
0019 helloroot
0020 SHARED
0021 src/helloroot.cxx
0022 )
0023
0024 # The particular syntax here is a bit annoying because you have to list all the sub-modules you need
0025 # but it picks up automatically all the compile options needed for root, e.g. the c++ std version
0026 # You can find all available ROOT modules with `root-config --libs`
0027 target_link_libraries(helloroot PUBLIC ROOT::Core ROOT::RIO ROOT::Rint ROOT::Tree ROOT::EG ROOT::Physics )
0028
0029 ## The above _should_ be true, and it is on most systems. If it's not, uncoment one of the following lines
0030 # target_compile_features(helloroot PUBLIC cxx_std_17)
0031 # target_compile_features(helloroot PUBLIC cxx_std_20)
0032
0033 # include directories - this is also overkill but useful if you want to create dictionaries
0034 # Contact kkauder@gmail.com for that - it's too much for this example
0035 target_include_directories(helloroot
0036 PUBLIC
0037 $<INSTALL_INTERFACE:include>
0038 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
0039 )
0040
0041 # Can add addtional options here
0042 target_compile_options(helloroot PRIVATE -Wall -Wextra -pedantic -g)
0043
0044 ##############################################################################################################
0045
0046 ## Build executables
0047 add_executable(helloexec src/helloexec.cxx)
0048 # target_compile_options(helloexec PRIVATE -Wall -Wextra -pedantic -g)
0049 target_link_libraries(helloexec helloroot )
0050 target_include_directories(helloexec
0051 PRIVATE
0052 ${ROOT_INCLUDE_DIRS}
0053 )
0054
0055 install(TARGETS helloexec DESTINATION bin)
0056
0057
0058 ##############################################################################################################
0059
0060 ## Install library
0061 # Could also use include(GNUInstallDirs)
0062 # and then destinations of the form ${CMAKE_INSTALL_INCLUDEDIR}
0063 install(TARGETS helloroot
0064 EXPORT helloroot-export
0065 LIBRARY DESTINATION lib
0066 ARCHIVE DESTINATION lib
0067 )
0068
0069 ## Install headers
0070 install (DIRECTORY ${CMAKE_SOURCE_DIR}/include/helloroot
0071 DESTINATION include/helloroot
0072 )
0073
0074 ## Generate configuration file - this allows you to use cmake in another project
0075 ## to find and link the installed helloroot library
0076 install(EXPORT helloroot-export
0077 FILE
0078 hellorootConfig.cmake
0079 NAMESPACE
0080 helloroot::
0081 DESTINATION
0082 cmake
0083 )
0084
0085 ## Final message
0086 message( " Done!")
0087
0088