Skip to content

Commit

Permalink
Merge pull request #112 from trws/protect-exports
Browse files Browse the repository at this point in the history
Protect exports
  • Loading branch information
trws authored Jul 28, 2022
2 parents 98c21d3 + df75279 commit 3a7486e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
56 changes: 39 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,33 @@ set(camp_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(camp_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(camp_VERSION_PATCH ${PROJECT_VERSION_PATCH})

# Default to C++11 if not set so GTest/GMock can build
if (NOT BLT_CXX_STD)
set(BLT_CXX_STD "c++14" CACHE STRING "")
else()
set(_unsupported_cxx "c++98" "c++11")
if (BLT_CXX_STD IN_LIST _unsupported_cxx)
message(FATAL_ERROR "CAMP and the RAJA framework no longer support c++11, select a c++ standard of 14 or higher")
include(CheckCXXCompilerFlag)
if(NOT DEFINED BLT_CXX_STD)
set(CXX_VERSIONS 17 14)
foreach(cxxver ${CXX_VERSIONS})
if("cxx_std_${cxxver}" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
if (ENABLE_CUDA AND (NOT DEFINED CMAKE_CUDA_COMPILE_FEATURES OR (NOT "cuda_std_${cxxver}" IN_LIST CMAKE_CUDA_COMPILE_FEATURES)))
continue()
endif()
set(CAMP_CXX_STD ${cxxver})
break()
endif()
endif()
endforeach()
if(NOT DEFINED CAMP_CXX_STD)
set(CAMP_CXX_STD 14)
endif()
set(BLT_CXX_STD c++${CAMP_CXX_STD} CACHE STRING "Version of C++
standard")
message("Using C++ standard: ${BLT_CXX_STD}")
else() #check BLT_CXX_STD is high enough by disallowing the only invalid option
set(_unsupported_cxx "c++98" "c++11")
if (BLT_CXX_STD IN_LIST _unsupported_cxx)
message(FATAL_ERROR "CAMP and the RAJA framework no
longer support ${_unsupported_cxx}, select a c++
standard of 14 or higher")
endif()
endif(NOT DEFINED BLT_CXX_STD)
set(CMAKE_CXX_EXTENSIONS OFF)

include(cmake/load_blt.cmake)

Expand Down Expand Up @@ -56,12 +74,16 @@ set (camp_runtime_backends cuda hip)

foreach (backend ${camp_backends})
string(TOUPPER "${backend}" suffix)
# NOTE: can't do this because of the lack of sycl support and usage upstream
# in blt
# cmake_dependent_option("CAMP_ENABLE_${suffix}" "Enable ${backend}
# backend" On "ENABLE_${suffix}" Off)
if ("${ENABLE_${suffix}}")
set ("CAMP_ENABLE_${suffix}" On)
endif()
if (${CAMP_ENABLE_${suffix}})
if (backend IN_LIST camp_runtime_backends)
set (backend ${backend}_runtime)
set (backend ${backend}_runtime)
endif()
if (TARGET blt::${backend})
set (backend blt::${backend})
Expand All @@ -70,11 +92,8 @@ foreach (backend ${camp_backends})
endif()
endforeach()

if (CAMP_ENABLE_TARGET_OPENMP)
if (NOT CAMP_ENABLE_OPENMP)
message(FATAL_ERROR "OpenMP must be enabled if TARGET_OPENMP is enabled")
endif ()
endif ()
cmake_dependent_option(CAMP_ENABLE_TARGET_OPENMP "Enable OpenMP offload as
device runtime" Off "CAMP_ENABLE_OPENMP" Off)

if (ENABLE_CUDA)
if("${CUDA_VERSION_STRING}" VERSION_LESS "10.1")
Expand All @@ -98,14 +117,17 @@ endif ()

# Configure the config header file to allow config time options
configure_file(${PROJECT_SOURCE_DIR}/include/camp/config.in.hpp
${PROJECT_BINARY_DIR}/include/camp/config.hpp)
${PROJECT_BINARY_DIR}/include/camp/config.hpp)

blt_add_library (
NAME camp
HEADERS ${camp_headers}
SOURCES ./src/errors.cpp
DEPENDS_ON ${camp_depends}
)
if(cxx_std_${CAMP_CXX_STD} IN_LIST CMAKE_CXX_COMPILE_FEATURES)
target_compile_features(camp PUBLIC cxx_std_${CAMP_CXX_STD})
endif()

if (COMPILER_FAMILY_IS_MSVC)
if (NOT BUILD_SHARED_LIBS)
Expand Down Expand Up @@ -164,7 +186,7 @@ install(FILES
include/camp)

if(CAMP_ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
enable_testing()
add_subdirectory(test)
endif()

6 changes: 5 additions & 1 deletion cmake/campConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
@PACKAGE_INIT@

set(camp_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" CACHE FILEPATH "camp install prefix path")

set(BLT_TGTS "${CMAKE_CURRENT_LIST_DIR}/bltTargets.cmake")
if(EXISTS "${BLT_TGTS}")
include("${BLT_TGTS}")
endif()
unset(BLT_TGTS)
include("${CMAKE_CURRENT_LIST_DIR}/campTargets.cmake")
check_required_components("@PROJECT_NAME@")

11 changes: 10 additions & 1 deletion cmake/load_blt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ if (NOT BLT_LOADED)
include(${BLT_SOURCE_DIR}/SetupBLT.cmake)
endif()

blt_export_tpl_targets(EXPORT campTargets NAMESPACE camp)
if (NOT BLT_EXPORTED)
set(BLT_EXPORTED On CACHE BOOL "" FORCE)
blt_import_library(NAME blt_stub EXPORTABLE On)
set_target_properties(blt_stub PROPERTIES EXPORT_NAME blt::blt_stub)
install(TARGETS blt_stub
EXPORT bltTargets)
blt_export_tpl_targets(EXPORT bltTargets NAMESPACE blt)
install(EXPORT bltTargets
DESTINATION lib/cmake/camp)
endif()

0 comments on commit 3a7486e

Please sign in to comment.