# Copyright (c) 2022 Ultimaker B.V.
# pynest2d is released under the terms of the LGPLv3 or higher.

project(pynest2d)
cmake_minimum_required(VERSION 3.20)  # Lowest version it's been tested with.
include(cmake/StandardProjectSettings.cmake)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

if(APPLE)
    set(Python_FIND_FRAMEWORK NEVER)
endif()
find_package(Python REQUIRED COMPONENTS Interpreter Development)
set(ENV{PYTHONPATH} ${Python_SITEARCH})
message(STATUS "Linking and building ${project_name} against Python ${Python_VERSION}")

find_package(SIP REQUIRED 6.5.0)

find_package(Libnest2D REQUIRED)  # The library we're creating bindings for.

add_library(pynest2d INTERFACE)
set_project_standards(pynest2d)
use_threads(pynest2d)
if(NOT CMAKE_SKIP_RPATH)
    set_rpath(TARGETS
                pynest2d
            PATHS
                "$<$<PLATFORM_ID:Linux>:usr/bin>"
                "$<$<PLATFORM_ID:Linux>:usr/bin/lib>"
                "$<$<PLATFORM_ID:Darwin>:../lib>"
                "$<$<PLATFORM_ID:Darwin>:../Resources/lib>"
                "../../"  # In distributions of Cura, the libnest2d dependency is 2 directories up from where pynest2d gets installed.
            RELATIVE)
endif()

target_include_directories(pynest2d
        INTERFACE
        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
        $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/pynest2d/>
        )

find_package(Threads)
target_link_libraries(pynest2d INTERFACE Libnest2D::libnest2d_headeronly Python::Python Threads::Threads)

add_sip_module(pynest2d)
if(Python_SITELIB_LOCAL)
    install_sip_module(pynest2d ${Python_SITELIB_LOCAL})
else()
    install_sip_module(pynest2d)
endif()
