1 set(LLVM_BINUTILS_INCDIR "/usr/include" CACHE PATH
2 "PATH to binutils/include containing plugin-api.h for gold plugin.")
4 if( NOT EXISTS "${LLVM_BINUTILS_INCDIR}/plugin-api.h" )
5 message(STATUS "plugin-api.h not found. gold plugin excluded from the build.")
7 include_directories( ${LLVM_BINUTILS_INCDIR} )
9 # Because off_t is used in the public API, the largefile parts are required for
11 add_definitions( -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 )
13 set(LLVM_LINK_COMPONENTS support)
15 add_llvm_loadable_module(LLVMgold
19 # Makefile.rules contains a special cases for OpenBSD, Darwin and
20 # Windows. We restrict ourselves to Linux for the time being.
21 set(srcexp ${CMAKE_CURRENT_SOURCE_DIR}/gold.exports)
22 add_custom_command(OUTPUT exportsfile
23 COMMAND echo "{" > exportsfile
24 COMMAND grep -q "\\<" ${srcexp} && echo " global:" >> exportsfile || :
25 COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${srcexp} >> exportsfile
26 COMMAND echo " local: *;" >> exportsfile
27 COMMAND echo "};" >> exportsfile
30 COMMENT "Creating export file for gold plugin")
31 add_custom_target(gold_exports DEPENDS exportsfile)
32 set_property(DIRECTORY APPEND
33 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES exportsfile)
35 # Force re-linking when the exports file changes. Actually, it
36 # forces recompilation of gold-plugin.cpp. The LINK_DEPENDS target
37 # property only works for makefile-based generators.
38 set_property(SOURCE gold-plugin.cpp APPEND PROPERTY
39 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/exportsfile)
41 target_link_libraries(LLVMgold LTO -Wl,--version-script,exportsfile)
42 add_dependencies(LLVMgold gold_exports)