• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1include(TestBigEndian)
2
3include(FindPerl)
4if( NOT PERL_FOUND )
5  message(FATAL_ERROR "Perl required but not found!")
6endif( NOT PERL_FOUND )
7
8set(PERL ${PERL_EXECUTABLE})
9set(VERSION PACKAGE_VERSION)
10set(PREFIX ${CMAKE_INSTALL_PREFIX})
11set(abs_top_srcdir ${LLVM_MAIN_SRC_DIR})
12set(abs_top_builddir ${LLVM_BINARY_DIR})
13execute_process(COMMAND date
14  OUTPUT_VARIABLE LLVM_CONFIGTIME
15  OUTPUT_STRIP_TRAILING_WHITESPACE)
16# LLVM_ON_UNIX and LLVM_ON_WIN32 already set.
17# those are set to blank by `autoconf' on MinGW, so it seems they are not required:
18#set(LLVMGCCDIR "")
19#set(LLVMGCC "")
20#set(LLVMGXX "")
21test_big_endian(IS_BIG_ENDIAN)
22if( IS_BIG_ENDIAN )
23  set(ENDIAN "big")
24else( IS_BIG_ENDIAN )
25  set(ENDIAN "little")
26endif( IS_BIG_ENDIAN )
27set(SHLIBEXT ${LTDL_SHLIB_EXT})
28#EXEEXT already set.
29set(OS "${CMAKE_SYSTEM}")
30set(target "${TARGET_TRIPLE}")
31set(ARCH "${LLVM_NATIVE_ARCH}")
32
33get_system_libs(LLVM_SYSTEM_LIBS_LIST)
34foreach(l ${LLVM_SYSTEM_LIBS_LIST})
35  set(LLVM_SYSTEM_LIBS ${LLVM_SYSTEM_LIBS} "-l${l}")
36endforeach()
37
38foreach(c ${LLVM_TARGETS_TO_BUILD})
39  set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
40endforeach(c)
41set(TARGETS_TO_BUILD ${TARGETS_BUILT})
42set(TARGET_HAS_JIT "1")  # TODO
43
44# Avoids replacement at config-time:
45set(LLVM_CPPFLAGS "@LLVM_CPPFLAGS@")
46set(LLVM_CFLAGS "@LLVM_CFLAGS@")
47set(LLVM_CXXFLAGS "@LLVM_CXXFLAGS@")
48set(LLVM_LDFLAGS "@LLVM_LDFLAGS@")
49set(LIBS "@LIBS@")
50set(LLVM_BUILDMODE "@LLVM_BUILDMODE@")
51
52configure_file(
53  ${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.in.in
54  ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in
55  @ONLY
56)
57
58set(LIBDEPS LibDeps.txt)
59set(LIBDEPS_TMP LibDeps.txt.tmp)
60set(FINAL_LIBDEPS FinalLibDeps.txt)
61set(LLVM_CONFIG ${LLVM_TOOLS_BINARY_DIR}/llvm-config)
62set(LLVM_CONFIG_IN ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in)
63
64if( CMAKE_CROSSCOMPILING )
65  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
66endif()
67
68find_program(NM_PATH nm PATH_SUFFIXES /bin)
69
70if( NOT NM_PATH )
71  message(FATAL_ERROR "`nm' not found")
72endif()
73
74get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS)
75
76add_custom_command(OUTPUT ${LIBDEPS_TMP}
77  COMMAND ${PERL_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/GenLibDeps.pl -flat ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} ${NM_PATH} > ${LIBDEPS_TMP}
78  DEPENDS ${llvm_libs}
79  COMMENT "Regenerating ${LIBDEPS_TMP}")
80
81add_custom_command(OUTPUT ${LIBDEPS}
82  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDEPS_TMP} ${LIBDEPS}
83  DEPENDS ${LIBDEPS_TMP}
84  COMMENT "Updating ${LIBDEPS} if necessary...")
85
86# This must stop the build if find-cycles.pl returns error:
87add_custom_command(OUTPUT ${FINAL_LIBDEPS}
88  COMMAND ${CMAKE_COMMAND} -E remove -f ${FINAL_LIBDEPS} ${FINAL_LIBDEPS}.tmp
89  COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/find-cycles.pl < ${LIBDEPS} > ${FINAL_LIBDEPS}.tmp
90  COMMAND ${CMAKE_COMMAND} -E copy ${FINAL_LIBDEPS}.tmp ${FINAL_LIBDEPS}
91  DEPENDS ${LIBDEPS}
92  COMMENT "Checking for cyclic dependencies between LLVM libraries.")
93
94set(C_FLGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
95set(CXX_FLGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
96set(CPP_FLGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
97
98# We don't want certain flags on the output of
99# llvm-config --cflags --cxxflags
100macro(remove_option_from_llvm_config option)
101  llvm_replace_compiler_option(C_FLGS "${option}" "")
102  llvm_replace_compiler_option(CXX_FLGS "${option}" "")
103  llvm_replace_compiler_option(CPP_FLGS "${option}" "")
104endmacro(remove_option_from_llvm_config)
105remove_option_from_llvm_config("-pedantic")
106remove_option_from_llvm_config("-Wall")
107remove_option_from_llvm_config("-W")
108
109add_custom_command(OUTPUT ${LLVM_CONFIG}
110  COMMAND echo s!@LLVM_CPPFLAGS@!${CPP_FLGS}! > temp.sed
111  COMMAND echo s!@LLVM_CFLAGS@!${C_FLGS}! >> temp.sed
112  COMMAND echo s!@LLVM_CXXFLAGS@!${CXX_FLGS}! >> temp.sed
113  # TODO: Use general flags for linking! not just for shared libs:
114  COMMAND echo s!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}! >> temp.sed
115  COMMAND echo s!@LIBS@!${LLVM_SYSTEM_LIBS}! >> temp.sed
116  COMMAND echo s!@LLVM_BUILDMODE@!${CMAKE_BUILD_TYPE}! >> temp.sed
117  COMMAND sed -f temp.sed < ${LLVM_CONFIG_IN} > ${LLVM_CONFIG}
118  COMMAND ${CMAKE_COMMAND} -E remove -f temp.sed
119  COMMAND cat ${FINAL_LIBDEPS} >> ${LLVM_CONFIG}
120  COMMAND chmod +x ${LLVM_CONFIG}
121  VERBATIM
122  DEPENDS ${FINAL_LIBDEPS} ${LLVM_CONFIG_IN}
123  COMMENT "Building llvm-config script."
124  )
125
126add_custom_target(llvm-config.target ALL
127  DEPENDS ${LLVM_CONFIG})
128
129add_dependencies( llvm-config.target ${llvm_libs} )
130
131# Make sure that llvm-config builds before the llvm tools, so we have
132# LibDeps.txt and can use it for updating the hard-coded library
133# dependencies on cmake/modules/LLVMLibDeps.cmake when the tools'
134# build fail due to outdated dependencies:
135set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} llvm-config.target)
136
137install(FILES ${LLVM_CONFIG}
138  PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
139  WORLD_READ WORLD_EXECUTE
140  DESTINATION bin)
141
142
143# Regeneration of library dependencies.
144
145# See the comments at the end of cmake/modules/LLVM-Config.cmake for
146# notes and guidelines.
147
148set(LLVMLibDeps ${LLVM_MAIN_SRC_DIR}/cmake/modules/LLVMLibDeps.cmake)
149set(LLVMLibDeps_TMP ${CMAKE_CURRENT_BINARY_DIR}/LLVMLibDeps.cmake.tmp)
150
151add_custom_command(OUTPUT ${LLVMLibDeps_TMP}
152  COMMAND sed -e s'@\\.a@@g' -e s'@\\.so@@g' -e 's@libLLVM@LLVM@g' -e 's@: @ @' -e 's@\\\(.*\\\)@set\(MSVC_LIB_DEPS_\\1\)@' ${FINAL_LIBDEPS} > ${LLVMLibDeps_TMP}
153  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LLVMLibDeps_TMP} ${LLVMLibDeps}
154  DEPENDS ${FINAL_LIBDEPS}
155  COMMENT "Updating cmake library dependencies file ${LLVMLibDeps}"
156  )
157
158if( LLVM_TARGETS_TO_BUILD STREQUAL LLVM_ALL_TARGETS )
159  add_custom_target(llvmlibdeps.target ALL DEPENDS ${LLVMLibDeps_TMP})
160  add_dependencies(llvmlibdeps.target llvm-config.target)
161  set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} llvmlibdeps.target)
162endif()
163
164set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
165