Fix processing of gold.exports.
[oota-llvm.git] / tools / gold / CMakeLists.txt
1 set(LLVM_BINUTILS_INCDIR "/usr/include" CACHE PATH
2   "PATH to binutils/include containing plugin-api.h for gold plugin.")
3
4 if( NOT EXISTS "${LLVM_BINUTILS_INCDIR}/plugin-api.h" )
5   message(STATUS "plugin-api.h not found. gold plugin excluded from the build.")
6 else()
7   include_directories( ${LLVM_BINUTILS_INCDIR} )
8
9   # Because off_t is used in the public API, the largefile parts are required for
10   # ABI compatibility.
11   add_definitions( -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 )
12
13   set(LLVM_LINK_COMPONENTS support)
14
15   add_llvm_loadable_module(LLVMgold
16     gold-plugin.cpp
17     )
18
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
28     DEPENDS ${srcexp}
29     VERBATIM
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)
34
35   target_link_libraries(LLVMgold LTO -Wl,--version-script,exportsfile)
36   add_dependencies(LLVMgold gold_exports)
37 endif()