1 include(TestBigEndian) 2 3 include(FindPerl) 4 if( NOT PERL_FOUND ) 5 message(FATAL_ERROR "Perl required but not found!") 6 endif( NOT PERL_FOUND ) 7 8 set(PERL ${PERL_EXECUTABLE}) 9 set(VERSION PACKAGE_VERSION) 10 set(PREFIX ${CMAKE_INSTALL_PREFIX}) 11 set(abs_top_srcdir ${LLVM_MAIN_SRC_DIR}) 12 set(abs_top_builddir ${LLVM_BINARY_DIR}) 13 execute_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 "") 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(target "${TARGET_TRIPLE}") 31 set(ARCH "${LLVM_NATIVE_ARCH}") 32 33 get_system_libs(LLVM_SYSTEM_LIBS_LIST) 34 foreach(l ${LLVM_SYSTEM_LIBS_LIST}) 35 set(LLVM_SYSTEM_LIBS ${LLVM_SYSTEM_LIBS} "-l${l}") 36 endforeach() 37 38 foreach(c ${LLVM_TARGETS_TO_BUILD}) 39 set(TARGETS_BUILT "${TARGETS_BUILT} ${c}") 40 endforeach(c) 41 set(TARGETS_TO_BUILD ${TARGETS_BUILT}) 42 set(TARGET_HAS_JIT "1") # TODO 43 44 # Avoids replacement at config-time: 45 set(LLVM_CPPFLAGS "@LLVM_CPPFLAGS@") 46 set(LLVM_CFLAGS "@LLVM_CFLAGS@") 47 set(LLVM_CXXFLAGS "@LLVM_CXXFLAGS@") 48 set(LLVM_LDFLAGS "@LLVM_LDFLAGS@") 49 set(LIBS "@LIBS@") 50 set(LLVM_BUILDMODE "@LLVM_BUILDMODE@") 51 52 configure_file( 53 ${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.in.in 54 ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in 55 @ONLY 56 ) 57 58 set(LIBDEPS LibDeps.txt) 59 set(LIBDEPS_TMP LibDeps.txt.tmp) 60 set(FINAL_LIBDEPS FinalLibDeps.txt) 61 set(LLVM_CONFIG ${LLVM_TOOLS_BINARY_DIR}/llvm-config) 62 set(LLVM_CONFIG_IN ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in) 63 64 if( CMAKE_CROSSCOMPILING ) 65 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) 66 endif() 67 68 find_program(NM_PATH nm PATH_SUFFIXES /bin) 69 70 if( NOT NM_PATH ) 71 message(FATAL_ERROR "`nm' not found") 72 endif() 73 74 get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS) 75 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}") 80 81 add_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: 87 add_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 94 set(C_FLGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 95 set(CXX_FLGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 96 set(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 100 macro(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}" "") 104 endmacro(remove_option_from_llvm_config) 105 remove_option_from_llvm_config("-pedantic") 106 remove_option_from_llvm_config("-Wall") 107 remove_option_from_llvm_config("-W") 108 109 add_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 126 add_custom_target(llvm-config.target ALL 127 DEPENDS ${LLVM_CONFIG}) 128 129 add_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: 135 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} llvm-config.target) 136 137 install(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 148 set(LLVMLibDeps ${LLVM_MAIN_SRC_DIR}/cmake/modules/LLVMLibDeps.cmake) 149 set(LLVMLibDeps_TMP ${CMAKE_CURRENT_BINARY_DIR}/LLVMLibDeps.cmake.tmp) 150 151 add_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 158 if( 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) 162 endif() 163 164 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE) 165