cmake_minimum_required(VERSION 3.5) project( viabLabLib ) # To build ViabLab as a library, set the variable BUILD_LIB to ON option(BUILD_LIB "Builds ViabLab as Library" OFF) # Set Boost root path ## Substitute the text within the parentheses with your Boost library path set(BOOST_ROOT "/opt/homebrew/Cellar/boost/1.88.0") # Find Boost library find_package(Boost REQUIRED) IF(CMAKE_SYSTEM_NAME STREQUAL Darwin) ## Substitute the text within the parentheses with your gcc and g++ path set(CMAKE_C_COMPILER "/opt/homebrew/bin/gcc-14") set(CMAKE_CXX_COMPILER "/opt/homebrew/bin/g++-14") set(OPTION "-std=c++17") message(".. OPTIONS: ${OPTION}") message("-- [-O3] MODE.") # <--- O3 MODE set(CMAKE_CXX_FLAGS "${OPTION} -fopenmp -Wall -Wextra -O3 -Wno-deprecated -Wno-unused") set(CMAKE_LINKER_FLAGS "-flto") # Linking time optimizations ELSE() ## Substitute the text within the parentheses with your gcc and g++ path set(CMAKE_C_COMPILER "/opt/homebrew/bin/gcc-14") set(CMAKE_CXX_COMPILER "/opt/homebrew/bin/g++-14") set(OPTION "-std=c++17") message(".. OPTIONS: ${OPTION}") message("-- [-O3] MODE.") # <--- O3 MODE set(CMAKE_CXX_FLAGS "${OPTION} -fopenmp -Wall -Wextra -O3 -Wno-deprecated -Wno-unused") set(CMAKE_LINKER_FLAGS "-flto") # Linking time optimizations ENDIF() # Uniformity for any system set(CMAKE_SHARED_LIBRARY_PREFIX_CXX "") set(CMAKE_SHARED_LIBRARY_SUFFIX_CXX ".so") # SPDLOG include directory set(SPDLOG_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/spdlog/include") message("-- SPD LOG DIR : ${SPDLOG_INCLUDE_DIR} ") include_directories(${SPDLOG_INCLUDE_DIR}) add_subdirectory("${CMAKE_SOURCE_DIR}/spdlog") # Include Boost headers message("-- BOOST INCLUDE DIR : ${Boost_INCLUDE_DIRS}") include_directories(${Boost_INCLUDE_DIRS}) # Include source/include directory for headers like ViabiMicroMacroTrajectoryHelper.h ## Substitute the text within the parentheses with your VIABLAB path include_directories("VIABLAB/source/include") # Search for header and source files file(GLOB_RECURSE Viab_HEADERS ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS data/*.h ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/*.h ) file(GLOB_RECURSE Viab_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp) message(STATUS "Viab_SOURCES content: ${Viab_SOURCES}") # Find all CPP files in the data directory file(GLOB MODEL_FILES "data/*.cpp") # Build core library from shared sources add_library(viabLabLib STATIC ${Viab_SOURCES}) target_compile_options(viabLabLib PRIVATE -fPIC) # For each model, compile only its .cpp and link to the core library foreach(MODEL_FILE ${MODEL_FILES}) get_filename_component(LIB_NAME ${MODEL_FILE} NAME_WE) message("Found model : ${MODEL_FILE}") add_library(${LIB_NAME} SHARED ${MODEL_FILE}) target_compile_options(${LIB_NAME} PRIVATE -fPIC) # Link to core library and other dependencies target_link_libraries(${LIB_NAME} viabLabLib ${Boost_LIBRARIES} spdlog::spdlog_header_only ${CMAKE_DL_LIBS} ) endforeach() if(BUILD_LIB) message("Building ViabLab as library") ADD_LIBRARY(viabLabLib STATIC ${Viab_SOURCES} ${Viab_HEADERS}) # Create static library else() message("Building ViabLab as executable") ADD_EXECUTABLE(viabLabExe ${Viab_SOURCES} ${Viab_HEADERS}) # Create executable target_link_libraries(viabLabExe PRIVATE viabLabLib) # Set output directory for shared libraries set_target_properties(${LIB_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) endif(BUILD_LIB) unset(BUILD_LIB CACHE)