cmake_minimum_required(VERSION 3.16)
project(bimap CXX)
set(PROJECT_VERSION 0.0.1)
#TODO: does this project require C++ 20? Then that should be part of the compile features of the targets
set(CMAKE_CXX_STANDARD 20)

include(GNUInstallDirs)

# Define target
add_library(bimap INTERFACE)
add_library(ojl::bimap ALIAS bimap)
target_include_directories(bimap
    INTERFACE
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_sources(bimap
    INTERFACE FILE_SET HEADERS
    BASE_DIRS ${PROJECT_SOURCE_DIR}/include/ojl
    FILES ${PROJECT_SOURCE_DIR}/include/ojl/bimap.hpp
)

#target_include_directories(bimap INTERFACE include)

#REMEMBER, usually we would do target_include_directories(bimap PUBLIC $<BUILD_INTERFACE:${bimap_SOURCE_DIR}/include> $<BUILD_INTERFACE:${bimap_BINARY_DIR}/include> $<INSTALL_INTERFACE:include>)
#But we just need the one in this case, since include is in the cmake root dir

add_subdirectory(samples)

option(DOWNLOAD_DEPS "Download unsatisfied dependencies using FetchContent" ON)

option(BUILD_TESTS "Build tests" ON)

if (BUILD_TESTS)
    if (DOWNLOAD_DEPS)
        include(cmake/fetch_catch2.cmake)
    endif()
    enable_testing()
    add_subdirectory(test)
endif()

# Define export set bimapTargets, install headers (but this doesn't actually install them...)
install(TARGETS bimap
    EXPORT bimapTargets
    FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ojl
)
# Install the headers at the install location

# Export the targets (?) what I don't get is how the bimapTargets.cmake differs from bimapConfig.cmake, why do we need both?
# This still only installs a target named "bimap", not ojl::bimap ??? Even though it says NAMESPACE ojl here
install(EXPORT bimapTargets
    FILE bimapTargets.cmake
    NAMESPACE ojl::
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bimap
)

#TODO: generate a file that checks the version number using CMakePackageConfigHelpers (write_basic_package_version_file)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
    "bimapConfigVersion.cmake"
    VERSION ${bimap_VERSION}
    COMPATIBILITY SameMajorVersion
)

install(FILES "bimapConfig.cmake" "${CMAKE_BINARY_DIR}/bimapConfigVersion.cmake"
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bimap
)

### SEPARATE FILE TO BE INSTALLED ? ###
# find dependencies if needed
# include("${CMAKE_CURRENT_LIST_DIR}/bimapTargets.cmake}")