Fix PR4948 (and a leak): by not destroying the DwarfException
[llvm/avr.git] / tools / llvm-config / CMakeLists.txt
blobb02966301131dfe54130964c2582e181f09c7729
1 include(TestBigEndian)
3 include(FindPerl)
4 if( NOT PERL_FOUND )
5   message(FATAL_ERROR "Perl required but not found!")
6 endif( NOT PERL_FOUND )
8 set(PERL ${PERL_EXECUTABLE})
9 set(VERSION PACKAGE_VERSION)
10 set(PREFIX ${LLVM_BINARY_DIR}) # TODO: Root for `make install'.
11 execute_process(COMMAND date
12   OUTPUT_VARIABLE LLVM_CONFIGTIME
13   OUTPUT_STRIP_TRAILING_WHITESPACE)
14 # LLVM_ON_UNIX and LLVM_ON_WIN32 already set.
15 # those are set to blank by `autoconf' on MinGW, so it seems they are not required:
16 #set(LLVMGCCDIR "")
17 #set(LLVMGCC "")
18 #set(LLVMGXX "")
19 #set(LLVMGCC_VERSION "")
20 #set(LLVMGCC_MAJVERS "")
21 test_big_endian(IS_BIG_ENDIAN)
22 if( IS_BIG_ENDIAN )
23   set(ENDIAN "big")
24 else( IS_BIG_ENDIAN )
25   set(ENDIAN "little")
26 endif( IS_BIG_ENDIAN )
27 set(SHLIBEXT ${LTDL_SHLIB_EXT})
28 #EXEEXT already set.
29 set(OS "${CMAKE_SYSTEM}")
30 set(ARCH "X86") # TODO: This gives "i686" in Linux: "${CMAKE_SYSTEM_PROCESSOR}")
32 get_system_libs(LLVM_SYSTEM_LIBS_LIST)
33 foreach(l ${LLVM_SYSTEM_LIBS_LIST})
34   set(LLVM_SYSTEM_LIBS ${LLVM_SYSTEM_LIBS} "-l${l}")
35 endforeach()
37 include(GetTargetTriple)
38 get_target_triple(target)
40 foreach(c ${LLVM_TARGETS_TO_BUILD})
41   set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
42 endforeach(c)
43 set(TARGETS_TO_BUILD ${TARGETS_BUILT})
44 set(TARGET_HAS_JIT "1")  # TODO
46 # Avoids replacement at config-time:
47 set(LLVM_CPPFLAGS "@LLVM_CPPFLAGS@")
48 set(LLVM_CFLAGS "@LLVM_CFLAGS@")
49 set(LLVM_CXXFLAGS "@LLVM_CXXFLAGS@")
50 set(LLVM_LDFLAGS "@LLVM_LDFLAGS@")
51 set(LIBS "@LIBS@")
52 set(LLVM_BUILDMODE "@LLVM_BUILDMODE@")
54 configure_file(
55   ${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.in.in
56   ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in
57   @ONLY
60 set(LIBDEPS ${CMAKE_CURRENT_BINARY_DIR}/LibDeps.txt)
61 set(LIBDEPS_TMP ${CMAKE_CURRENT_BINARY_DIR}/LibDeps.txt.tmp)
62 set(FINAL_LIBDEPS ${CMAKE_CURRENT_BINARY_DIR}/FinalLibDeps.txt)
63 set(LLVM_CONFIG ${LLVM_TOOLS_BINARY_DIR}/llvm-config)
64 set(LLVM_CONFIG_IN ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in)
66 if( CMAKE_CROSSCOMPILING )
67   set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
68 endif()
70 find_program(NM_PATH nm PATH_SUFFIXES /bin)
72 if( NOT NM_PATH )
73   message(FATAL_ERROR "`nm' not found")
74 endif()
76 add_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}")
81 add_custom_command(OUTPUT ${LIBDEPS}
82   COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDEPS_TMP} ${LIBDEPS}
83   DEPENDS ${LIBDEPS_TMP}
84   COMMENT "Updated ${LIBDEPS} because dependencies changed")
86 add_custom_command(OUTPUT ${FINAL_LIBDEPS}
87   COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/find-cycles.pl < ${LIBDEPS} > ${FINAL_LIBDEPS} || ${CMAKE_COMMAND} -E remove -f ${FINAL_LIBDEPS}
88   DEPENDS ${LIBDEPS}
89   COMMENT "Checking for cyclic dependencies between LLVM libraries.")
91 set(C_FLGS "${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
92 set(CXX_FLGS "${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
93 set(CPP_FLGS "${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
95 add_custom_command(OUTPUT ${LLVM_CONFIG}
96   COMMAND echo 's!@LLVM_CPPFLAGS@!${CPP_FLGS}!' > temp.sed
97   COMMAND echo 's!@LLVM_CFLAGS@!${C_FLGS}!' >> temp.sed
98   COMMAND echo 's!@LLVM_CXXFLAGS@!${CXX_FLGS}!' >> temp.sed
99   # TODO: Use general flags for linking! not just for shared libs:
100   COMMAND echo 's!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}!' >> temp.sed
101   COMMAND echo 's!@LIBS@!${LLVM_SYSTEM_LIBS}!' >> temp.sed
102   COMMAND echo 's!@LLVM_BUILDMODE@!${CMAKE_BUILD_TYPE}!' >> temp.sed
103   COMMAND sed -f temp.sed < ${LLVM_CONFIG_IN} > ${LLVM_CONFIG}
104   COMMAND ${CMAKE_COMMAND} -E remove -f temp.sed
105   COMMAND cat ${FINAL_LIBDEPS} >> ${LLVM_CONFIG}
106   COMMAND chmod +x ${LLVM_CONFIG}
107   DEPENDS ${FINAL_LIBDEPS} ${LLVM_CONFIG_IN}
108   COMMENT "Building llvm-config script."
109   )
111 add_custom_target(llvm-config.target ALL
112   DEPENDS ${LLVM_CONFIG})
114 add_dependencies(llvm-config.target ${llvm_lib_targets})
116 # Make sure that llvm-config builds before the llvm tools, so we have
117 # LibDeps.txt and can use it for updating the hard-coded library
118 # dependencies on cmake/modules/LLVMLibDeps.cmake when the tools'
119 # build fail due to outdated dependencies:
120 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} llvm-config.target)
122 install(FILES ${LLVM_CONFIG}
123   PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
124   WORLD_READ WORLD_EXECUTE
125   DESTINATION bin)
128 # Regeneration of library dependencies.
130 # See the comments at the end of cmake/modules/LLVMConfig.cmake for
131 # notes and guidelines.
133 set(LLVMLibDeps ${LLVM_MAIN_SRC_DIR}/cmake/modules/LLVMLibDeps.cmake)
134 set(LLVMLibDeps_TMP ${CMAKE_CURRENT_BINARY_DIR}/LLVMLibDeps.cmake.tmp)
136 add_custom_command(OUTPUT ${LLVMLibDeps_TMP}
137   COMMAND sed -e s'@\\.a@@g' -e 's@libLLVM@LLVM@g' -e 's@: @ @' -e 's@\\\(.*\\\)@set\(MSVC_LIB_DEPS_\\1\)@' ${FINAL_LIBDEPS} > ${LLVMLibDeps_TMP}
138   COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LLVMLibDeps_TMP} ${LLVMLibDeps}
139   DEPENDS ${FINAL_LIBDEPS}
140   COMMENT "Updating cmake library dependencies file ${LLVMLibDeps}"
141   )
143 if( LLVM_TARGETS_TO_BUILD STREQUAL LLVM_ALL_TARGETS )
144   add_custom_target(llvmlibdeps.target ALL DEPENDS ${LLVMLibDeps_TMP})
145   add_dependencies(llvmlibdeps.target llvm-config.target)
146   set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} llvmlibdeps.target)
147 endif()
149 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)