link with libatomic (#387)

* link with libatomic when available
* Use --as-needed flag to avoid libatomic reference where not required
This commit is contained in:
Code7R 2017-08-20 08:37:52 +02:00 committed by Valient Gough
parent d4273b0331
commit 636766e620

View File

@ -93,6 +93,23 @@ check_cxx_source_compiles ("#include <sys/types.h>
int main() { getxattr(0,0,0,0,0,0); return 1; } int main() { getxattr(0,0,0,0,0,0); return 1; }
" XATTR_ADD_OPT) " XATTR_ADD_OPT)
# If awailable on current architecture (typically embedded 32-bit), link with it explicitly;
# GCC autodetection is faulty, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358 and
# find_libray is no great help here since it is sometimes(!) not in standard paths.
set(CMAKE_REQUIRED_FLAGS "-latomic")
CHECK_CXX_SOURCE_COMPILES("int main() {return 0;}" COMPILER_NEEDS_LATOMIC)
if(COMPILER_NEEDS_LATOMIC)
set(ATOMIC_LIBRARY atomic)
endif()
# compensate the effect of extra linking of libatomic on platforms where intrinsics are used
set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed")
CHECK_CXX_SOURCE_COMPILES("int main() {return 0;}" LINKER_SUPPORTS_WLASNEEDED)
if(LINKER_SUPPORTS_WLASNEEDED)
list(APPEND EXTRA_LINKER_FLAGS "-Wl,--as-needed")
endif()
set(CMAKE_REQUIRED_FLAGS)
# Check if we have some standard functions. # Check if we have some standard functions.
include (CheckFuncs) include (CheckFuncs)
check_function_exists_glibc (lchmod HAVE_LCHMOD) check_function_exists_glibc (lchmod HAVE_LCHMOD)
@ -214,12 +231,14 @@ set_target_properties(encfs PROPERTIES
VERSION ${ENCFS_VERSION} VERSION ${ENCFS_VERSION}
SOVERSION ${ENCFS_SOVERSION}) SOVERSION ${ENCFS_SOVERSION})
target_link_libraries(encfs target_link_libraries(encfs
${EXTRA_LINKER_FLAGS}
${FUSE_LIBRARIES} ${FUSE_LIBRARIES}
${OPENSSL_LIBRARIES} ${OPENSSL_LIBRARIES}
${TINYXML_LIBRARIES} ${TINYXML_LIBRARIES}
${EASYLOGGING_LIBRARIES} ${EASYLOGGING_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${Intl_LIBRARIES} ${Intl_LIBRARIES}
${ATOMIC_LIBRARY}
) )
if (INSTALL_LIBENCFS) if (INSTALL_LIBENCFS)
install (TARGETS encfs DESTINATION ${LIB_INSTALL_DIR}) install (TARGETS encfs DESTINATION ${LIB_INSTALL_DIR})