Skip to content
Snippets Groups Projects
CMakeLists.txt 2.69 KiB
Newer Older
  • Learn to ignore specific revisions
  • cmake_minimum_required(VERSION 3.16)
    
    Ian Bell's avatar
    Ian Bell committed
    project(teqp)
    
    Ian Bell's avatar
    Ian Bell committed
    enable_testing()
    
    Ian Bell's avatar
    Ian Bell committed
    
    
    Ian Bell's avatar
    Ian Bell committed
    ####  SETUP
    
    set(CMAKE_CXX_STANDARD 17)
    
    Ian Bell's avatar
    Ian Bell committed
    include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
    
    include_directories("${CMAKE_CURRENT_SOURCE_DIR}/externals/mcx/pymcx/include")
    
    include_directories("${CMAKE_CURRENT_SOURCE_DIR}/externals/Eigen")
    
    include_directories("${CMAKE_CURRENT_SOURCE_DIR}/externals/nlohmann_json")
    
    set(BUILD_TESTING FALSE CACHE BOOL "Turn off Eigen tests")
    set(Eigen3_DIR "${CMAKE_CURRENT_SOURCE_DIR}/externals/Eigen" CACHE INTERNAL "Path to Eigen, for autodiff")
    
    Ian Bell's avatar
    Ian Bell committed
    
    set(AUTODIFF_BUILD_TESTS FALSE CACHE BOOL "No autodiff tests")
    set(AUTODIFF_BUILD_PYTHON FALSE CACHE BOOL "No autodiff python")
    set(AUTODIFF_BUILD_EXAMPLES FALSE CACHE BOOL "No autodiff examples")
    
    
    # Turn on more useful diagnostic messages in nlohmann::json, for instance if you are accessing a field that doesn't exist
    set(JSON_Diagnostics TRUE CACHE BOOL "Turn on more helpful diagnostics in nlohmann::json")
    
    
    add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/externals/Eigen")
    add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/externals/autodiff")
    
    Ian Bell's avatar
    Ian Bell committed
    set(TEQP_NO_PYTHON false)
    
    if (NOT TEQP_NO_PYTHON)
    
    Ian Bell's avatar
    Ian Bell committed
        add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/externals/pybind11" "pybind11")
    
        file(GLOB_RECURSE pybind11_files "${CMAKE_CURRENT_SOURCE_DIR}/interface/*.cpp")
        pybind11_add_module(teqp "${pybind11_files}")
    
        target_include_directories(teqp PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/externals/pybind11_json/include")
    
    Ian Bell's avatar
    Ian Bell committed
        target_link_libraries(teqp PRIVATE autodiff)
    
    Ian Bell's avatar
    Ian Bell committed
    add_executable(catch_tests "${CMAKE_CURRENT_SOURCE_DIR}/src/tests/catch_tests.cxx" "${CMAKE_CURRENT_SOURCE_DIR}/src/tests/catch_test_mutant.cxx")
    
        target_sources(catch_tests PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/externals/Eigen/debug/msvc/eigen.natvis")
    
    Ian Bell's avatar
    Ian Bell committed
    endif()
    
    target_link_libraries(catch_tests autodiff)
    
    Ian Bell's avatar
    Ian Bell committed
    add_test(catch catch_tests)
    
    ### TARGETS from src folder
    if (TEQP_SNIPPETS)
      # Collect all the snippets
      file(GLOB_RECURSE snippets "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
    
      message(STATUS "snippets found = ${snippets}")
      foreach (snippet ${snippets})
    
        get_filename_component(snippet_name ${snippet} NAME)
        get_filename_component(snippet_exe ${snippet} NAME_WE)
        message(STATUS "snippet_name = ${snippet_name}")
    
        add_executable(${snippet_exe} ${snippet})
        if (MSVC)
    
    Ian Bell's avatar
    Ian Bell committed
          target_sources(${snippet_exe} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/externals/Eigen/debug/msvc/eigen.natvis")
        endif()
    
    Ian Bell's avatar
    Ian Bell committed
        target_link_libraries(${snippet_exe} autodiff)
    
    Ian Bell's avatar
    Ian Bell committed
        if(UNIX)
          target_link_libraries (${snippet_exe} ${CMAKE_DL_LIBS})
        endif()
    
    else()
      message(STATUS "No snippets will be compiled, pass -DTEQP_SNIPPETS=ON to build them")