cmake_minimum_required(VERSION 3.20)

project(qrack_device)

if (NOT MSVC)
    set(CMAKE_CXX_STANDARD 20)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)

    option(ENABLE_OPENCL "Use OpenCL optimizations" ON)
    find_package(OpenCL)
    if ((NOT OpenCL_FOUND) OR (APPLE AND NOT ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "^amd") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86_64"))))
        set (ENABLE_OPENCL OFF)
    endif ((NOT OpenCL_FOUND) OR (APPLE AND NOT ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "^amd") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86_64"))))
    add_library(qrack_device SHARED pennylane_qrack/qrack_device.cpp)
    target_link_directories(qrack_device PUBLIC ${CMAKE_SOURCE_DIR}/catalyst/runtime/include ${CMAKE_SOURCE_DIR}/qrack/build)
    target_include_directories(qrack_device PUBLIC ${CMAKE_SOURCE_DIR}/catalyst/runtime/include ${CMAKE_SOURCE_DIR}/_qrack_include)
    if (ENABLE_OPENCL)
        if (APPLE)
            target_include_directories(qrack_device PUBLIC ${CMAKE_SOURCE_DIR}/qrack/build/_deps/opencl-headers-src/ ${CMAKE_SOURCE_DIR}/qrack/build/_deps/opencl-clhpp-src/include/)
            target_link_libraries(qrack_device PUBLIC qrack "-framework OpenCL")
        else (APPLE)
            target_link_libraries(qrack_device PUBLIC qrack OpenCL)
        endif (APPLE)
    else (ENABLE_OPENCL)
        target_link_libraries(qrack_device PUBLIC qrack)
    endif (ENABLE_OPENCL)
    set_property(TARGET qrack_device PROPERTY POSITION_INDEPENDENT_CODE ON)
    install(TARGETS qrack_device LIBRARY DESTINATION pennylane_qrack)
endif (NOT MSVC)
