Skip to content

Commit

Permalink
build: Link against libatomic unconditionally
Browse files Browse the repository at this point in the history
A previous commit (a44cedf) made
Seastar unconditonally link against `atomic`, since this was
necessary on some platforms.

The new build system restores the link to `atomic`, but with two small
changes.

The first is that `atomic` is a private (non-transitive) dependency of
Seastar.

The second is that CMake unconditionally includes `-latomic` when this
flag works on an empty stub file. Otherwise, no explicit linker
arguments are added.

Fixes scylladb#568

Signed-off-by: Jesse Haber-Kucharsky <[email protected]>
Message-Id: <60608d050bbd7b64c40d8ad2365db0e845a0e275.1547000745.git.jhaberku@scylladb.com>
  • Loading branch information
Jesse Haber-Kucharsky authored and avikivity committed Jan 9, 2019
1 parent 5cefd04 commit c9d6e20
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ find_package (GnuTLS 3.3.26 REQUIRED)
find_package (LinuxMembarrier)
find_package (Protobuf 2.5.0 REQUIRED)
find_package (Sanitizers REQUIRED)
find_package (StdAtomic REQUIRED)
find_package (StdFilesystem REQUIRED)
find_package (hwloc 1.11.2)
# No version information published.
Expand Down Expand Up @@ -587,6 +588,7 @@ target_link_libraries (seastar
${CMAKE_DL_LIBS}
Boost::filesystem
GnuTLS::gnutls
StdAtomic::atomic
StdFilesystem::filesystem
lksctp-tools::lksctp-tools
protobuf::libprotobuf
Expand Down Expand Up @@ -891,6 +893,7 @@ if (Seastar_INSTALL)
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLinuxMembarrier.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindProtobuf.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindSanitizers.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindStdAtomic.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindStdFilesystem.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findc-ares.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findcryptopp.cmake
Expand Down
51 changes: 51 additions & 0 deletions cmake/FindStdAtomic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# This file is open source software, licensed to you under the terms
# of the Apache License, Version 2.0 (the "License"). See the NOTICE file
# distributed with this work for additional information regarding copyright
# ownership. You may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

#
# Copyright (C) 2019 Scylladb, Ltd.
#

function (_stdatomic_can_link var)
include (CheckCXXSourceCompiles)
set (test_code "int main() {}")
set (CMAKE_REQUIRED_LIBRARIES -latomic)
check_cxx_source_compiles ("${test_code}" ${var})
endfunction ()

_stdatomic_can_link (StdAtomic_EXPLICIT_LINK)

#
# If linking against `-latomic` is successful, then do it unconditionally.
#

if (StdAtomic_EXPLICIT_LINK)
set (StdAtomic_LIBRARY_NAME atomic)
set (StdAtomic_LIBRARIES -l${StdAtomic_LIBRARY_NAME})
include (FindPackageHandleStandardArgs)

find_package_handle_standard_args (StdAtomic
REQUIRED_VARS StdAtomic_LIBRARIES)
endif ()

if (NOT (TARGET StdAtomic::atomic))
add_library (StdAtomic::atomic INTERFACE IMPORTED)

set_target_properties (StdAtomic::atomic
PROPERTIES
INTERFACE_LINK_LIBRARIES "${StdAtomic_LIBRARIES}")
endif ()
1 change: 1 addition & 0 deletions cmake/SeastarConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ find_package (GnuTLS 3.5.18 REQUIRED)
find_package (LinuxMembarrier)
find_package (Protobuf 3.3.0 REQUIRED)
find_package (Sanitizers REQUIRED)
find_package (StdAtomic REQUIRED)
find_package (StdFilesystem REQUIRED)
find_package (hwloc 1.11.5)
find_package (lksctp-tools)
Expand Down
3 changes: 2 additions & 1 deletion pkgconfig/seastar.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Description: Advanced C++ framework for high-performance server applications on
Version: @PROJECT_VERSION@

# Platform dependencies.
stdatomic_libs=$<JOIN:@StdAtomic_LIBRARIES@, >
stdfilesystem_libs=$<JOIN:@StdFilesystem_LIBRARIES@, >
dl_libs=-l$<JOIN:@CMAKE_DL_LIBS@,-l>
rt_libs=$<JOIN:@rt_LIBRARIES@, >
Expand Down Expand Up @@ -43,4 +44,4 @@ Requires.private: gnutls >= 3.5.18, protobuf >= 3.3.0, hwloc >= 1.11.5, yaml-cpp
Conflicts:
Cflags: ${boost_cflags} ${c_ares_cflags} ${cryptopp_cflags} ${fmt_cflags} ${lksctp_tools_cflags} ${numactl_cflags} ${sanitizers_cflags} ${seastar_cflags}
Libs: ${boost_program_options_libs} ${boost_thread_libs} ${c_ares_libs} ${cryptopp_libs} ${fmt_libs} ${seastar_libs}
Libs.private: ${dl_libs} ${rt_libs} ${boost_filesystem_libs} ${boost_thread_libs} ${dpdk_libs} ${lksctp_tools_libs} ${numactl_libs} ${stdfilesystem_libs}
Libs.private: ${dl_libs} ${rt_libs} ${boost_filesystem_libs} ${boost_thread_libs} ${dpdk_libs} ${lksctp_tools_libs} ${numactl_libs} ${stdatomic_libs} ${stdfilesystem_libs}

0 comments on commit c9d6e20

Please sign in to comment.