cmake_minimum_required(VERSION 3.30)

project(FESA VERSION 0.1.0 LANGUAGES CXX)

if(NOT MSVC)
    message(FATAL_ERROR "FESA requires the Microsoft Visual C++ compiler (MSVC v145).")
endif()

if(NOT CMAKE_VS_PLATFORM_TOOLSET STREQUAL "v145")
    message(
        FATAL_ERROR
        "FESA requires the v145 platform toolset; configured toolset is "
        "'${CMAKE_VS_PLATFORM_TOOLSET}'."
    )
endif()

if(NOT CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
    message(FATAL_ERROR "FESA requires the x64 generator platform.")
endif()

if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
    message(FATAL_ERROR "FESA requires a 64-bit target.")
endif()

include(CTest)
include(cmake/FesaDependencies.cmake)

add_library(fesa_core STATIC
    src/fesa/analysis/linear_static_analysis.cpp
    src/fesa/analysis/run_solver.cpp
    src/fesa/assembly/contribution.cpp
    src/fesa/assembly/parallel_assembler.cpp
    src/fesa/assembly/serial_assembler.cpp
    src/fesa/constraints/essential_bc.cpp
    src/fesa/core/version.cpp
    src/fesa/elements/beam/beam3d2.cpp
    src/fesa/fem/beam_frame.cpp
    src/fesa/fem/dof_manager.cpp
    src/fesa/fem/gauss_rule.cpp
    src/fesa/fem/line2_shape.cpp
    src/fesa/io/abaqus/active_input.cpp
    src/fesa/io/abaqus/parser.cpp
    src/fesa/io/abaqus/semantic_mapper.cpp
    src/fesa/io/abaqus/set_resolver.cpp
    src/fesa/io/hdf5/writer.cpp
    src/fesa/model/domain.cpp
    src/fesa/model/domain_builder.cpp
    src/fesa/results/result_database.cpp
    src/fesa/solvers/linear/pardiso_linear_solver.cpp
)

target_include_directories(fesa_core
    PUBLIC
        "${CMAKE_CURRENT_SOURCE_DIR}/include"
)

target_compile_features(fesa_core PUBLIC cxx_std_20)
target_compile_options(fesa_core PRIVATE /W4 /permissive- /EHsc)
target_link_libraries(fesa_core PRIVATE MKL::MKL TBB::tbb HDF5::HDF5)

add_executable(fesa
    src/fesa/cli/main.cpp
)

target_link_libraries(fesa PRIVATE fesa_core)
target_compile_features(fesa PRIVATE cxx_std_20)
target_compile_options(fesa PRIVATE /W4 /permissive- /EHsc)

if(BUILD_TESTING)
    add_subdirectory(tests)
endif()
