Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ endif()
include(GNUInstallDirs)

find_package( jwt-cpp REQUIRED )
find_package( Atomic REQUIRED )
find_package( CURL REQUIRED )
find_package( UUID REQUIRED )

Expand Down Expand Up @@ -51,7 +52,7 @@ target_include_directories(SciTokens PUBLIC ${JWT_CPP_INCLUDES} "${PROJECT_SOURC
# Find threading library
find_package(Threads REQUIRED)

target_link_libraries(SciTokens PUBLIC ${OPENSSL_LIBRARIES} ${LIBCRYPTO_LIBRARIES} ${CURL_LIBRARIES} ${SQLITE_LIBRARIES} ${UUID_LIBRARIES} Threads::Threads)
target_link_libraries(SciTokens PUBLIC ${OPENSSL_LIBRARIES} ${LIBCRYPTO_LIBRARIES} ${CURL_LIBRARIES} ${SQLITE_LIBRARIES} ${UUID_LIBRARIES} Threads::Threads std::atomic)
if (UNIX)
# pkg_check_modules fails to return an absolute path on RHEL7. Set the
# link directories accordingly.
Expand Down
42 changes: 42 additions & 0 deletions cmake/FindAtomic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
include(CheckCXXSourceCompiles)

function( check_working_cxx_atomics varname )
CHECK_CXX_SOURCE_COMPILES("
#include <cstdlib>
#include <atomic>
#include <cstdint>

int main() {
std::atomic<uint8_t> a1;
std::atomic<uint16_t> a2;
std::atomic<uint32_t> a3;
std::atomic<uint64_t> a4;
return a1++ + a2++ + a3++ + a4++;
}" ${varname}
)
endfunction( check_working_cxx_atomics varname )

set( _found FALSE )
check_working_cxx_atomics( CXX_ATOMIC_NO_LINK_NEEDED )
if( CXX_ATOMIC_NO_LINK_NEEDED )
set( _found TRUE )
else()
set( OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} )
list( APPEND CMAKE_REQUIRED_LIBRARIES "atomic" )
check_working_cxx_atomics( HAVE_CXX_ATOMICS_WITH_LIB )
set( CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES} )
if( HAVE_CXX_ATOMICS_WITH_LIB )
set( _found TRUE )
endif()
endif()

add_library( std::atomic INTERFACE IMPORTED GLOBAL )

if( HAVE_CXX_ATOMICS_WITH_LIB )
set_property( TARGET std::atomic APPEND PROPERTY INTERFACE_LINK_LIBRARIES atomic )
endif()

set( Atomic_FOUND ${_found} CACHE BOOL "TRUE if we can run a program using std::atomic" FORCE )
if( Atomic_FIND_REQUIRED AND NOT Atomic_FOUND )
message( FATAL_ERROR "Cannot run simple program using std::atomic" )
endif()
Loading