Skip to content

Commit

Permalink
config: check for libatomic. Fixes #90.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgates3 committed Dec 29, 2024
1 parent 8d59c13 commit 5955214
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set_property( CACHE gpu_backend PROPERTY STRINGS

# After color.
include( "cmake/util.cmake" )
include( "cmake/config.cmake" )

# Recognize CTest's BUILD_TESTING flag. (Quotes required.)
if (NOT "${BUILD_TESTING}" STREQUAL "")
Expand Down Expand Up @@ -357,7 +358,6 @@ endif()

#-------------------------------------------------------------------------------
# Clean stale defines.h from Makefile-based build.
message( "" )
file( REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/include/blas/defines.h" )

# Include directory.
Expand All @@ -371,6 +371,8 @@ target_include_directories(
)

# OpenMP support.
message( "" )
message( STATUS "${bold}Looking for OpenMP${not_bold}" )
set( openmp_lib "" )
set( blaspp_use_openmp false ) # output in blasppConfig.cmake.in
if (NOT use_openmp)
Expand All @@ -384,7 +386,15 @@ else()
endif()
endif()

# If -latomic is required, add as link library to blaspp.
message( "" )
check_libatomic()
if (libatomic_required)
target_link_libraries( blaspp PUBLIC "-latomic" )
endif()

# Get git commit id.
message( "" )
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
execute_process( COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
20 changes: 20 additions & 0 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,26 @@ def gpu_blas():
print_warn( 'No GPU BLAS library found' )
# end

#-------------------------------------------------------------------------------
def libatomic():
'''
Tests whether using `std::atomic` requires linking with `-latomic`
for 64-bit values, which is the case on some 32-bit systems.
'''
print_test( 'std::atomic links without -latomic' )
(rc, out, err) = compile_exe( 'config/std_atomic.cc' )
print_result( 'x', rc )
if (rc != 0):
print_test( 'std::atomic requires -latomic' )
env = {'LIBS': '-latomic'}
(rc, out, err) = compile_exe( 'config/std_atomic.cc', env )
print_result( 'x', rc )
if (rc == 0):
environ.merge( env )
else:
raise Error( 'cannot compile libatomic test' )
# end

#-------------------------------------------------------------------------------
def get_package( name, directories, repo_url, tar_url, tar_filename ):
'''
Expand Down
11 changes: 11 additions & 0 deletions config/std_atomic.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <atomic>
#include <cstdint>

int main( int argc, char** argv )
{
std::atomic<std::int64_t> x = 0;
for (int i = 1; i < argc; ++i) {
++x;
}
return x;
}
3 changes: 3 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def main():
#config.prog_cxx_flag( '-Wconversion' )
#config.prog_cxx_flag( '-Werror' )

print_header( 'Libraries' )
config.libatomic()

config.openmp()

config.lapack.blas()
Expand Down

0 comments on commit 5955214

Please sign in to comment.