cmake: make sure all DKS related libaries and include paths are properly set.

This commit is contained in:
suter_a 2018-06-04 11:16:45 +02:00
parent b2c8b9b72b
commit 58148581ba
2 changed files with 32 additions and 12 deletions

View File

@ -2,7 +2,8 @@
#
# This module defines:
# DKS_INCLUDE_DIR, where to find DKSBaseMuSR.h
# DKS_LIBRARY, shared library to be linked against if using DKS
# DKS_LIBS, shared library to be linked against if using DKS
# DKS_CFLAGS, compiler flags needed for DKS
#
# **as35** since I currently also maintaing the DKS library, it should add
# a DKSConfig.cmake which eventually will make this module obsolate. This
@ -25,6 +26,23 @@ find_library(DKS_LIBRARY dksshared
"$ENV{HOME}/Applications/DKS/exec/lib"
)
if (CUDA_FOUND)
set(DKS_CFLAGS -DDKS_OPENCL -DDKS_CUDA -I${DKS_INCLUDE_DIR} -I${CUDA_INCLUDE_DIRS})
set(DKS_LIBS ${CUDA_LIBRARIES} ${DKS_LIBRARY})
else (CUDA_FOUND)
if (OpenCL_FOUND)
if (APPLE)
set(DKS_CFLAGS -DDKS_OPENCL -I${DKS_INCLUDE_DIR} -I${OpenCL_INCLUDE_DIRS})
set(DKS_LIBS ${OpenCL_LIBRARY} ${DKS_LIBRARY})
else (APPLE)
set(DKS_CFLAGS -DDKS_OPENCL -I${DKS_INCLUDE_DIR} -I${OpenCL_INCLUDE_DIRS})
set(DKS_LIBS ${OpenCL_LIBRARY} ${DKS_LIBRARY})
endif (APPLE)
else (OpenCL_FOUND)
message(FATAL "neither CUDA nor OpenCL found when looking for DKS.")
endif (OpenCL_FOUND)
endif (CUDA_FOUND)
# as35 set here the DKS version explicitly. This is VERY ugly and should be fixed
# asap by using a package
set(DKS_VERSION "1.1.3")
@ -33,15 +51,17 @@ set(DKS_VERSION "1.1.3")
# all listed variables are TRUE
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(DKS
REQUIRED_VARS DKS_LIBRARY DKS_INCLUDE_DIR
REQUIRED_VARS DKS_CFLAGS DKS_LIBS DKS_INCLUDE_DIR
VERSION_VAR DKS_VERSION)
if (NOT DKS_FOUND)
unset(DKS_LIBRARY)
unset(DKS_CFLAGS)
unset(DKS_LIBS)
endif (NOT DKS_FOUND)
mark_as_advanced(
DKS_INCLUDE_DIR
DKS_LIBRARY
DKS_CFLAGS
DKS_LIBS
)

View File

@ -109,11 +109,17 @@ set_target_properties(PUserFcnBase
target_include_directories(
PUserFcnBase BEFORE PRIVATE $<BUILD_INTERFACE:${MUSRFIT_INC}>
)
#--- add OpenMP compile options if needed -------------------------------------
if (OpenMP_FOUND)
target_compile_options(PMusr PUBLIC ${OpenMP_CXX_FLAGS})
endif (OpenMP_FOUND)
#--- add DKS compiler flags if enabled ----------------------------------------
if (DKS_FOUND)
target_compile_options(PMusr PUBLIC ${DKS_CFLAGS})
endif (DKS_FOUND)
#--- add library dependencies -------------------------------------------------
set(DependOnLibs ${ROOT_LIBARIES})
set(DependOnLibs ${DependOnLibs} ${FFTW3_LIBRARY})
@ -134,13 +140,7 @@ if (OpenMP_FOUND)
endif (OpenMP_CXX_LIBRARIES)
endif (OpenMP_FOUND)
if (DKS_FOUND)
if (CUDA_FOUND)
set(DependOnLibs ${DependOnLibs} ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES})
endif (CUDA_FOUND)
if (NOT CUDA_FOUND AND OpenCL_FOUND)
set(DependOnLibs ${DependOnLibs} ${OpenCL_LIBRARIES})
endif (NOT CUDA_FOUND AND OpenCL_FOUND)
set(DependOnLibs ${DependOnLibs} ${DKS_LIBRARY})
set(DependOnLibs ${DependOnLibs} ${DKS_LIBS})
endif (DKS_FOUND)
target_link_libraries(PUserFcnBase ${ROOT_LIBRARIES})