
cmake_minimum_required(VERSION 3.18)
project (SeparateCompilation CXX HIP)

#Goal for this example:
#Build a static library that defines multiple methods and kernels that
#use each other.
#After that confirm that we can call those methods from dynamic libraries
#and executables.

set(CMAKE_HIP_SEPARABLE_COMPILATION ON)
set(CMAKE_HIP_ARCHITECTURES "gfx900")

add_library(HIPSeparateLibA STATIC file1.cu file2.cu file3.cu)
set_source_files_properties(file1.cu file2.cu file3.cu PROPERTIES LANGUAGE HIP)
target_compile_features(HIPSeparateLibA PRIVATE cxx_std_14)

add_library(HIPSeparateLibB SHARED file4.cxx file5.cxx)
set_source_files_properties(file4.cxx file5.cxx PROPERTIES LANGUAGE HIP)
target_compile_features(HIPSeparateLibB PRIVATE hip_std_14)
target_link_libraries(HIPSeparateLibB PRIVATE HIPSeparateLibA)

add_executable(HipSeparateCompilation main.hip)
target_link_libraries(HipSeparateCompilation
                      PRIVATE HIPSeparateLibB)
set_target_properties(HipSeparateCompilation PROPERTIES HIP_STANDARD 14)
set_target_properties(HipSeparateCompilation PROPERTIES HIP_STANDARD_REQUIRED TRUE)

set_target_properties(HIPSeparateLibA
                      HIPSeparateLibB
                      PROPERTIES POSITION_INDEPENDENT_CODE ON)
