set(_STATIC_LIB_SUFFIX
    "_static"
    CACHE INTERNAL "" FORCE
)
set(_SHARED_LIB_SUFFIX
    "_shared"
    CACHE INTERNAL "" FORCE
)


set(targetname
    {% if info.device != "gpu" -%}
    naunet_constants
    naunet_physics
    naunet_ode
    {% endif -%}
    naunet
)

{% if info.device == "gpu" -%}
set(cuda_targetname
    naunet_constants
    naunet_physics
    naunet_ode
)
{% endif %}

set(_libtypes "")
if(MAKE_STATIC)
    set(_libtypes "STATIC")
endif()

if(MAKE_SHARED)
    set(_libtypes "${_libtypes};SHARED")
endif()

foreach(_libtype ${_libtypes})

    # library suffix
    if(${_libtype} MATCHES "STATIC")
        set(_lib_suffix "${_STATIC_LIB_SUFFIX}")
    else()
        set(_lib_suffix "${_SHARED_LIB_SUFFIX}")
    endif()

    set(compiled_target "")
    {% if info.device == "gpu" -%}
    foreach(name ${cuda_targetname})
        set(lib_target ${name}${_lib_suffix})
        add_library(${lib_target} ${_libtype} name.cu)
        set_target_properties(${lib_target} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
        target_include_directories(${lib_target} PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
        target_include_directories(${lib_target} PUBLIC ${CMAKE_SOURCE_DIR}/include)
        target_link_libraries(${lib_target} ${SUNDIALSLIB})
        target_link_libraries(${lib_target} ${compiled_target})
        set(compiled_target "${compiled_target};${lib_target}")
        set_target_properties(${lib_target} PROPERTIES OUTPUT_NAME ${name})
    endforeach()
    {% endif -%}

    foreach(name ${targetname})
        set(lib_target ${name}${_lib_suffix})
        add_library(${lib_target} ${_libtype} ${name}.cpp)
        target_include_directories(${lib_target} PUBLIC ${CMAKE_SOURCE_DIR}/include)
        target_link_libraries(${lib_target} ${SUNDIALSLIB})
        target_link_libraries(${lib_target} ${compiled_target})
        set(compiled_target "${compiled_target};${lib_target}")
        set_target_properties(${lib_target} PROPERTIES OUTPUT_NAME ${name})
    endforeach()

    # set(lib_target naunet_constants${_lib_suffix})
    # {% if info.device == "gpu" -%}
    # add_library(${lib_target} ${_libtype} naunet_constants.cu)
    # set_target_properties(${lib_target} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
    # target_include_directories(${lib_target} PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
    # {% else -%}
    # add_library(${lib_target} ${_libtype} naunet_constants.cpp)
    # {% endif -%}
    # target_include_directories(${lib_target} PUBLIC ${CMAKE_SOURCE_DIR}/include)

    # set(lib_target naunet_ode${_lib_suffix})
    # {% if info.device == "gpu" -%}
    # add_library(${lib_target} ${_libtype} naunet_ode.cu)
    # set_target_properties(${lib_target} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
    # target_include_directories(${lib_target} PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
    # {% else -%}
    # add_library(${lib_target} ${_libtype} naunet_ode.cpp)
    # {% endif -%}
    # target_include_directories(${lib_target} PUBLIC ${CMAKE_SOURCE_DIR}/include)
    # target_link_libraries(${lib_target} ${SUNDIALSLIB})

    # set(lib_target naunet_physics${_lib_suffix})
    # {% if info.device == "gpu" -%}
    # add_library(${lib_target} ${_libtype} naunet_physics.cu)
    # set_target_properties(${lib_target} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
    # target_include_directories(${lib_target} PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
    # {% else -%}
    # add_library(${lib_target} ${_libtype} naunet_physics.cpp)
    # {% endif -%}
    # target_include_directories(${lib_target} PUBLIC ${CMAKE_SOURCE_DIR}/include)
    # target_link_libraries(${lib_target} naunet_constants${_lib_suffix})

    # set(lib_target naunet${_lib_suffix})
    # add_library(${lib_target} ${_libtype} naunet.cpp)
    # {% if info.device == "gpu" -%}
    # set_target_properties(${lib_target} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
    # target_include_directories(${lib_target} PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
    # {% endif -%}
    # target_include_directories(${lib_target} PUBLIC ${CMAKE_SOURCE_DIR}/include)
    # target_link_libraries(${lib_target} ${SUNDIALSLIB})

endforeach()


if(MAKE_SHARED)
    set(NAUNETLIB_SHARED
        naunet${_SHARED_LIB_SUFFIX}
        naunet_constants${_SHARED_LIB_SUFFIX}
        naunet_ode${_SHARED_LIB_SUFFIX}
        naunet_physics${_SHARED_LIB_SUFFIX}
        CACHE INTERNAL ""
    )
    install(TARGETS ${NAUNETLIB_SHARED}
        LIBRARY DESTINATION lib
    )
endif()

if(MAKE_STATIC)
    set(NAUNETLIB_STATIC
        naunet${_STATIC_LIB_SUFFIX}
        naunet_constants${_STATIC_LIB_SUFFIX}
        naunet_ode${_STATIC_LIB_SUFFIX}
        naunet_physics${_STATIC_LIB_SUFFIX}
        CACHE INTERNAL ""
    )
    install(TARGETS ${NAUNETLIB_STATIC}
        LIBRARY DESTINATION lib
    )
endif()


install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
    DESTINATION include)
