Skip to content

Commit

Permalink
Refactor CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Sep 14, 2023
1 parent 07c4ca9 commit 8021310
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ endif()

project(search LANGUAGES CXX)

# Check if we can compile CUDA on this system and, if so, enable the options.
# Check if we can compile CUDA on this system.
include(CheckLanguage)
check_language(CUDA)

Expand All @@ -21,42 +21,20 @@ check_ipo_supported(RESULT ipo_supported)
find_package( PythonInterp )
find_package( PythonLibs )

find_library(CFITSIO_LIBRARY
find_library(CFITSIO_LIBRARY
NAMES fitsio cfitsio libcfitsio
HINTS lib/
)

add_subdirectory(lib/pybind11)

set(CMAKE_CXX_STANDARD 11) # set(PYBIND11_CPP_STANDARD -std=c++11)
set(CMAKE_CXX_STANDARD 11)

include_directories(
include/
)

# Create the library with the CUDA files. Note that we need to include at
# least one cpp file in here so that the cmake knows which language to use.
add_library(searchcu STATIC
src/kbmod/search/RawImage.h
src/kbmod/search/RawImage.cpp
src/kbmod/search/image_kernels.cu
src/kbmod/search/kernels.cu
)
set_target_properties(searchcu PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)

set_target_properties(searchcu PROPERTIES
POSITION_INDEPENDENT_CODE ON
CUDA_VISIBILITY_PRESET "hidden"
PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}"
)

if(ipo_supported)
set_property(TARGET searchcu PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()


# Create the python module via pybind11.
pybind11_add_module(search MODULE
src/kbmod/search/bindings.cpp
)
Expand All @@ -72,15 +50,38 @@ if(ipo_supported)
set_property(TARGET search PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()


target_compile_options(search PRIVATE $<$<COMPILE_LANGUAGE:CXX>:
-O3
-fvisibility=hidden
-fopenmp
>)

target_link_libraries(search PRIVATE
searchcu
${CFITSIO_LIBRARY}
-lgomp
${CFITSIO_LIBRARY}
-lgomp
)

# If we have CUDA, build the kernel libraries and link them in as well.
if(HAVE_CUDA)
message(STATUS "Building CUDA Libraries")
add_library(searchcu STATIC
src/kbmod/search/image_kernels.cu
src/kbmod/search/kernels.cu
)

set_target_properties(searchcu PROPERTIES
POSITION_INDEPENDENT_CODE ON
CUDA_VISIBILITY_PRESET "hidden"
CUDA_SEPARABLE_COMPILATION ON
CUDA_RESOLVE_DEVICE_SYMBOLS ON
PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}"
)
if(ipo_supported)
set_property(TARGET searchcu PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

target_link_libraries(search PRIVATE searchcu)
else()
message(STATUS "Skipping CUDA Libraries")
endif()

0 comments on commit 8021310

Please sign in to comment.