# cmake for manalyzer # # template from https://dominikberner.ch/cmake-interface-lib/ # cmake_minimum_required(VERSION 3.10) project("manalyzer" VERSION 1 DESCRIPTION "MIDAS C++ analyzer") # HOMEPAGE_URL "https://midas.triumf.ca") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # in standalone mode, install under /bin set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR} CACHE PATH "" FORCE) else() # there is an user choice or a higher level project # specifying the install path - keep that set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) endif() message(STATUS "manalyzer: CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") add_compile_options("-O2") add_compile_options("-g") #add_compile_options("-std=c++11") #add_compile_options("-fsanitize=address") #add_link_options("-fsanitize=address") #add_compile_options("-fsanitize=thread") #add_link_options("-fsanitize=thread") # # Find MIDAS # if (NO_MIDAS) message(STATUS "manalyzer: MIDAS support is disabled via NO_MIDAS") unset(MIDAS_FOUND) elseif(TARGET midas) message(STATUS "manalyzer: Building as a subproject of MIDAS") set(MIDAS_FOUND true) elseif((DEFINED ENV{MIDASSYS}) AND (NOT ("$ENV{MIDASSYS}" STREQUAL ""))) include($ENV{MIDASSYS}/lib/midas-targets.cmake) message(STATUS "manalyzer: Building with MIDAS from $ENV{MIDASSYS}/lib/midas-targets.cmake") set(MIDAS_FOUND TRUE) else() message(STATUS "manalyzer: Building without MIDAS") unset(MIDAS_FOUND) endif() # # Find ROOT # if (NO_ROOT) message(STATUS "manalyzer: ROOT support is disabled via NO_ROOT") unset(ROOT_FOUND) elseif (ROOT_FOUND) separate_arguments(ROOT_CXX_FLAGS UNIX_COMMAND "${ROOT_CXX_FLAGS}") message(STATUS "manalyzer: Using ROOT: flags: ${ROOT_CXX_FLAGS} and includes: ${ROOT_INCLUDE_DIRS}") elseif (DEFINED ENV{ROOTSYS}) message(STATUS "manalyzer: ROOTSYS is $ENV{ROOTSYS}") list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS}) find_package(ROOT REQUIRED COMPONENTS Gui # TG* objects RHTTP # THttpServer XMLIO XMLParser ) if(ROOT_FOUND) separate_arguments(ROOT_CXX_FLAGS UNIX_COMMAND "${ROOT_CXX_FLAGS}") message(STATUS "manalyzer: Found ROOT: flags: ${ROOT_CXX_FLAGS} and includes: ${ROOT_INCLUDE_DIRS}") else() unset(ROOT_FOUND) endif() else() message(STATUS "manalyzer: ROOT not found: ROOTSYS is not defined") endif() # # Find pthreads # set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) #target_link_libraries(my_app PRIVATE Threads::Threads) #list(APPEND XLIBS ${CMAKE_THREAD_LIBS_INIT}) # # Find gzip library # find_package(ZLIB REQUIRED) # # Define libraries # if(MIDAS_FOUND) set(manalyzer_objs) else() set(manalyzer_objs ${PROJECT_SOURCE_DIR}/../midasio/midasio.cxx ${PROJECT_SOURCE_DIR}/../midasio/lz4frame.cxx ${PROJECT_SOURCE_DIR}/../midasio/lz4.cxx ${PROJECT_SOURCE_DIR}/../midasio/lz4hc.cxx ${PROJECT_SOURCE_DIR}/../midasio/xxhash.cxx ${PROJECT_SOURCE_DIR}/../mvodb/mvodb.cxx ${PROJECT_SOURCE_DIR}/../mvodb/nullodb.cxx ${PROJECT_SOURCE_DIR}/../mvodb/mjsonodb.cxx ${PROJECT_SOURCE_DIR}/../mvodb/mxmlodb.cxx ${PROJECT_SOURCE_DIR}/../mjson/mjson.cxx ${PROJECT_SOURCE_DIR}/../mxml/mxml.cxx ) install(FILES ../midasio/midasio.h DESTINATION include) install(FILES ../mvodb/mvodb.h DESTINATION include) #install(FILES ../mjson/mjson.h DESTINATION include) #install(FILES ../mxml/mxml.h DESTINATION include) endif() add_library(manalyzer STATIC manalyzer.cxx ${manalyzer_objs}) add_library(manalyzer_main STATIC manalyzer_main.cxx) target_include_directories(manalyzer PUBLIC $ $ $) target_include_directories(manalyzer_main PUBLIC $) if(MIDAS_FOUND) target_compile_definitions(manalyzer PUBLIC -DHAVE_MIDAS -DHAVE_TMFE) target_compile_definitions(manalyzer_main PUBLIC -DHAVE_MIDAS -DHAVE_TMFE) target_link_libraries(manalyzer PUBLIC midas) target_link_libraries(manalyzer_main PUBLIC midas) target_include_directories(manalyzer PUBLIC $) target_include_directories(manalyzer_main PUBLIC $) else() target_include_directories(manalyzer PRIVATE ${PROJECT_SOURCE_DIR}/../midasio ${PROJECT_SOURCE_DIR}/../mvodb ${PROJECT_SOURCE_DIR}/../mjson ${PROJECT_SOURCE_DIR}/../mxml PUBLIC $) target_include_directories(manalyzer_main PUBLIC $ $ PUBLIC $) endif() if(ROOT_FOUND) target_include_directories(manalyzer PUBLIC ${ROOT_INCLUDE_DIRS}) target_include_directories(manalyzer_main PUBLIC ${ROOT_INCLUDE_DIRS}) target_compile_options(manalyzer PUBLIC ${ROOT_CXX_FLAGS} -DHAVE_ROOT) target_compile_options(manalyzer_main PUBLIC ${ROOT_CXX_FLAGS} -DHAVE_ROOT) #target_compile_definitions(manalyzer PUBLIC ${ROOT_CXX_FLAGS} -DHAVE_ROOT) #target_compile_definitions(manalyzer_main PUBLIC ${ROOT_CXX_FLAGS} -DHAVE_ROOT) else() target_compile_features(manalyzer PUBLIC cxx_std_11) target_compile_features(manalyzer_main PUBLIC cxx_std_11) endif() if(ROOT_http_FOUND) target_compile_definitions(manalyzer PUBLIC -DHAVE_ROOT_HTTP -DHAVE_THTTP_SERVER) target_compile_definitions(manalyzer_main PUBLIC -DHAVE_ROOT_HTTP -DHAVE_THTTP_SERVER) endif() target_include_directories(manalyzer PUBLIC ${ZLIB_INCLUDE_DIRS}) target_link_libraries(manalyzer PUBLIC ${ROOT_LIBRARIES}) target_link_libraries(manalyzer PUBLIC ${ZLIB_LIBRARIES}) target_link_libraries(manalyzer PUBLIC ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(manalyzer_main PUBLIC manalyzer) add_executable(manalyzer_test.exe manalyzer_main.cxx) target_link_libraries(manalyzer_test.exe manalyzer_main) add_executable(manalyzer_example_cxx.exe manalyzer_example_cxx.cxx) target_link_libraries(manalyzer_example_cxx.exe manalyzer_main) add_executable(manalyzer_example_flow.exe manalyzer_example_flow.cxx) target_link_libraries(manalyzer_example_flow.exe manalyzer_main) add_executable(manalyzer_example_flow_queue.exe manalyzer_example_flow_queue.cxx) target_link_libraries(manalyzer_example_flow_queue.exe manalyzer_main) if(MIDAS_FOUND) add_executable(manalyzer_example_frontend.exe manalyzer_example_frontend.cxx) target_link_libraries(manalyzer_example_frontend.exe manalyzer_main) endif() if(ROOT_FOUND) add_executable(manalyzer_example_root.exe manalyzer_example_root.cxx) target_link_libraries(manalyzer_example_root.exe manalyzer_main) add_executable(manalyzer_example_root_graphics.exe manalyzer_example_root_graphics.cxx) target_link_libraries(manalyzer_example_root_graphics.exe manalyzer_main) endif() if(MIDAS_NO_INSTALL_INCLUDE_FILES) target_include_directories(manalyzer INTERFACE ${PROJECT_SOURCE_DIR}) target_include_directories(manalyzer_main INTERFACE ${PROJECT_SOURCE_DIR}) else() install(FILES manalyzer.h DESTINATION include) endif() install(TARGETS manalyzer manalyzer_main DESTINATION lib EXPORT ${PROJECT_NAME}-targets) if(NOT MANALYZER_NO_INSTALL_EXAMPLES) install(TARGETS manalyzer_test.exe manalyzer_example_cxx.exe manalyzer_example_flow.exe manalyzer_example_flow_queue.exe DESTINATION bin) if(ROOT_FOUND) install(TARGETS manalyzer_example_root.exe manalyzer_example_root_graphics.exe DESTINATION bin) endif(ROOT_FOUND) if(MIDAS_FOUND) install(TARGETS manalyzer_example_frontend.exe DESTINATION bin) endif(MIDAS_FOUND) endif() install(EXPORT ${PROJECT_NAME}-targets DESTINATION lib) # # to use manalyzer-targets.cmake: # # include(.../manalyzer/lib/manalyzer-targets.cmake) # add_executable(myexe src1.c src2.c ) # target_link_libraries(myexe PRIVATE manalyzer_main manalyzer) # # end