# Set minimum required version of CMake
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

# Project name and the languages it will use (C++ and CUDA)
project(user-material-models LANGUAGES CXX CUDA)

# Optionally set the C++ standard and CUDA standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 11)

# Set the output directory for the shared library
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Find the CUDA toolkit
find_package(CUDAToolkit)

# Add the CUDA headers (CUDAToolkit_INCLUDE_DIRS includes the correct path)
include_directories(${CUDAToolkit_INCLUDE_DIRS})

file(GLOB CPP_FILES user-material/*.cpp user-material/*.h user-material/*.cu)
set(SOURCES ${CPP_FILES})

# Specify CUDA compiler options (optional)
# Set your specific CUDA architecture if needed
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_52,code=sm_52")

# Create a shared library (dll/so) from the source files
add_library(user-material-models SHARED ${SOURCES})

# Optionally, link libraries to the shared library (if needed)
# target_link_libraries(user-material-models some_other_library)

# Optionally, set properties like the output name of the library
set_target_properties(user-material-models PROPERTIES
    CUDA_SEPARABLE_COMPILATION ON  # Enables separable compilation for CUDA
    POSITION_INDEPENDENT_CODE ON   # Necessary for building shared libraries
)

if(WIN32)
    add_definitions(-DWIN64)
endif()

# Print a message to confirm the build type (optional)
message(STATUS "Building user-material-models as a shared library with C++ and CUDA")
