Plugin to add Pijul support to the Nix package manager
cmake_minimum_required(VERSION 3.23)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 17)

file(STRINGS VERSION _version)
project(nix-plugin-pijul VERSION ${_version})

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_SHARED_MODULE_PREFIX)

include(CTest)
include(GNUInstallDirs)

find_package(PkgConfig REQUIRED)
find_package(Boost REQUIRED)
find_package(date REQUIRED)
find_package(nlohmann_json REQUIRED)

pkg_check_modules(Nix REQUIRED IMPORTED_TARGET nix-main nix-store)
find_library(nixfetchers_LIBRARY nixfetchers REQUIRED)
target_link_libraries(PkgConfig::Nix INTERFACE ${nixfetchers_LIBRARY})

set(Nix_VERSION ${Nix_nix-main_VERSION})
string(REPLACE "." ";" VERSION_LIST ${Nix_VERSION})
list(GET VERSION_LIST 0 Nix_MAJOR_VERSION)
list(GET VERSION_LIST 1 Nix_MINOR_VERSION)
list(GET VERSION_LIST 2 Nix_PATCH_VERSION)
target_compile_definitions(PkgConfig::Nix
        INTERFACE
        "NIX_MAJOR_VERSION=(${Nix_MAJOR_VERSION})"
        "NIX_MINOR_VERSION=(${Nix_MINOR_VERSION})"
        "NIX_PATCH_VERSION=(${Nix_PATCH_VERSION})"
        "NIX_VERSION=(((0x${Nix_MAJOR_VERSION})<<16) | ((0x${Nix_MINOR_VERSION})<<8) | (0x${Nix_PATCH_VERSION}))"
        SYSTEM="")
target_link_libraries(PkgConfig::Nix
        INTERFACE
        Boost::headers
        date::date
        nlohmann_json)

add_compile_options(-Wall -Werror)

add_subdirectory(autotests)
add_subdirectory(src)