1 include(CMakeParseArguments)
2 include(CompilerRTUtils)
4 function(get_aix_libatomic_default_link_flags link_flags export_list)
7 -Wl,-T512 -Wl,-bhalt:4 -Wl,-bernotok
8 -Wl,-bnoentry -Wl,-bexport:${export_list}
9 -Wl,-bmodtype:SRE -Wl,-lc)
10 # Add `-Wl,-G`. Quoted from release notes of cmake-3.16.0
11 # > On AIX, runtime linking is no longer enabled by default.
12 # See https://cmake.org/cmake/help/latest/release/3.16.html
13 set(linkopts -Wl,-G ${linkopts})
14 set(${link_flags} ${linkopts} PARENT_SCOPE)
17 function(get_aix_libatomic_type type)
18 set(${type} MODULE PARENT_SCOPE)
21 macro(archive_aix_libatomic name libname)
22 cmake_parse_arguments(LIB
27 set(objects_to_archive "")
28 foreach (arch ${LIB_ARCHS})
29 if(CAN_TARGET_${arch})
30 set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/${libname}-${arch}.dir")
31 # FIXME: Target name should be kept consistent with definition
32 # in AddCompilerRT.cmake added by
33 # add_compiler_rt_runtime(<name> SHARED ...)
34 set(target ${name}-dynamic-${arch})
36 file(MAKE_DIRECTORY ${output_dir})
37 add_custom_command(OUTPUT "${output_dir}/libatomic.so.1"
39 COMMAND ${CMAKE_COMMAND} -E
40 copy "$<TARGET_FILE:${target}>"
41 "${output_dir}/libatomic.so.1"
42 # If built with MODULE, F_LOADONLY is set.
43 # We have to remove this flag at POST_BUILD.
44 COMMAND ${CMAKE_STRIP} -X32_64 -E
45 "${output_dir}/libatomic.so.1"
47 list(APPEND objects_to_archive "${output_dir}/libatomic.so.1")
51 if(objects_to_archive)
54 # If LLVM defines top level library directory, we want to deliver
55 # libatomic.a at top level. See `llvm/cmake/modules/AddLLVM.cmake'
56 # setting _install_rpath on AIX for reference.
57 if(LLVM_LIBRARY_OUTPUT_INTDIR AND CMAKE_INSTALL_PREFIX)
58 set(output_dir "${LLVM_LIBRARY_OUTPUT_INTDIR}")
59 set(install_dir "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
61 get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir)
62 get_compiler_rt_install_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} install_dir)
64 add_custom_command(OUTPUT "${output_dir}/${libname}.a"
65 COMMAND ${CMAKE_AR} -X32_64 r "${output_dir}/${libname}.a"
67 DEPENDS ${objects_to_archive})
68 install(FILES "${output_dir}/${libname}.a"
69 DESTINATION ${install_dir})
70 add_custom_target(aix-${libname}
71 DEPENDS "${output_dir}/${libname}.a")
72 add_dependencies(${LIB_PARENT_TARGET} aix-${libname})