Skip to content
Snippets Groups Projects
CMakeLists.txt 1.69 KiB
Newer Older
cmake_minimum_required(VERSION 3.16)
project(ojl_bimap VERSION 0.0.1 LANGUAGES CXX)
include(GNUInstallDirs)

# Define target
add_library(ojl::bimap ALIAS bimap)
target_include_directories(bimap
    INTERFACE
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_compile_features(bimap
    INTERFACE
    cxx_std_20
)

# The above is not enough, because it let's some compilers through that don't support all of C++ 20...
target_compile_options(bimap
    INTERFACE
    -std=c++20
)

#TODO: set the header files here as a list, so there's only one place where they are defined

if(${CMAKE_VERSION} VERSION_LESS "3.23.0") 
else()
target_sources(bimap
    INTERFACE FILE_SET HEADERS
    BASE_DIRS ${PROJECT_SOURCE_DIR}/include/ojl
    FILES ${PROJECT_SOURCE_DIR}/include/ojl/bimap.hpp
)
endif()
Oskar Lappi's avatar
Oskar Lappi committed
option(OJL_BIMAP_BUILD_TESTS "Build tests" ON)
Oskar Lappi's avatar
Oskar Lappi committed
option(OJL_BIMAP_DOWNLOAD_DEPS "Download unsatisfied dependencies using FetchContent" ON)
Oskar Lappi's avatar
Oskar Lappi committed
if (OJL_BIMAP_BUILD_TESTS)

    #TODO: Only checks the initially set compiler? Have to run twice if you change the compiler (maybe this is just how it works, idk)
    include(CheckCXXCompilerFlag)
    check_cxx_compiler_flag(-std=c++20 CXX_20_SUPPORT)

    if (NOT CXX_20_SUPPORT)
        message(FATAL_ERROR "The C++ compiler does not support the -std=c++20 flag")
        message(FATAL_ERROR "Use a compiler that supports C++ 20, like clang++ >= 10")
Oskar Lappi's avatar
Oskar Lappi committed
    if (OJL_BIMAP_DOWNLOAD_DEPS)
        include(cmake/fetch_catch2.cmake)
    endif()
    enable_testing()
    add_subdirectory(test)
endif()
# Install 
include(cmake/install_bimap.cmake)