cmake_minimum_required(VERSION 3.16)
project(synor_compute VERSION 0.1.0 LANGUAGES C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

# Options
option(BUILD_SHARED_LIBS "Build shared library" ON)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_EXAMPLES "Build examples" ON)

# Find dependencies
find_package(CURL REQUIRED)

# Library sources
set(SYNOR_SOURCES
    src/synor_compute.c
)

# Create library
add_library(synor_compute ${SYNOR_SOURCES})

target_include_directories(synor_compute
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)

target_link_libraries(synor_compute
    PRIVATE
        CURL::libcurl
        m
)

# Set library properties
set_target_properties(synor_compute PROPERTIES
    VERSION ${PROJECT_VERSION}
    SOVERSION ${PROJECT_VERSION_MAJOR}
    PUBLIC_HEADER include/synor_compute.h
)

# Installation
include(GNUInstallDirs)

install(TARGETS synor_compute
    EXPORT synor_compute-targets
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT synor_compute-targets
    FILE synor_compute-targets.cmake
    NAMESPACE synor::
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/synor_compute
)

# Tests
if(BUILD_TESTS)
    enable_testing()
    add_subdirectory(tests EXCLUDE_FROM_ALL)
endif()

# Examples
if(BUILD_EXAMPLES)
    add_subdirectory(examples EXCLUDE_FROM_ALL)
endif()
