CMakeLists.txt 2.64 KB
Newer Older
David Blyth's avatar
David Blyth committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(EICTrack VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 11)

# ---------------------------------------------------------------------------
# set default install prefix and build type
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE)
    set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "..." FORCE)
endif()

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "..." FORCE)
endif()

#----------------------------------------------------------------------------
# Find Libraries
find_path(GENFIT_INCLUDE_DIR NAMES ProlateSpacepointMeasurement.h)
if(NOT GENFIT_INCLUDE_DIR)
    message(FATAL_ERROR "GenFit headers not found!")
endif()
include_directories(${GENFIT_INCLUDE_DIR})
find_library(GENFIT_LIBRARY NAMES genfit2)
if(NOT GENFIT_LIBRARY)
    message(FATAL_ERROR "GenFit was not found!")
endif()
get_filename_component(GENFIT_LIBRARY_DIR ${GENFIT_LIBRARY} DIRECTORY)
link_directories(${GENFIT_LIBRARY_DIR})
find_package(proio 0.10.0 REQUIRED)
include_directories(${proio_INCLUDE_DIR})
find_package(ROOT 6 REQUIRED)
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIRS})

#-----------------------------------------------------------------------------------
file(GLOB SRCS
    ${CMAKE_CURRENT_SOURCE_DIR}/src/EICTrack.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/src/bfields/*.cc
    )
file(GLOB HEADERS
    ${CMAKE_CURRENT_SOURCE_DIR}/src/EICTrack.h
    )
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

add_executable(eictrack ${SRCS} ${HEADERS})
target_link_libraries(eictrack
    ${GENFIT_LIBRARY}
    proio proio.pb
    ${ROOT_LIBRARIES} ROOT::Geom
    ${EIGEN3_LIBRARIES}
    )

install(TARGETS eictrack
    EXPORT ${PROJECT_NAME}Targets
    DESTINATION bin
    )

#----------------------------------------------------------------------------
# Install and export targets
install(EXPORT ${PROJECT_NAME}Targets
    FILE ${PROJECT_NAME}Targets.cmake
    DESTINATION lib/${PROJECT_NAME}
    )

include(CMakePackageConfigHelpers)

set(TARGETS_INSTALL_PATH lib/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake)
CONFIGURE_PACKAGE_CONFIG_FILE(
    cmake/${PROJECT_NAME}Config.cmake.in  
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
    INSTALL_DESTINATION lib/${PROJECT_NAME}
    PATH_VARS TARGETS_INSTALL_PATH
    )

write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
    VERSION ${${PROJECT_NAME}_VERSION}
    COMPATIBILITY SameMajorVersion
    )

install(FILES
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
    DESTINATION lib/${PROJECT_NAME}
    )