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