CMakeLists.txt revision 3a210e2d302758101ac06946e86027b327c7d0f3
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 ${LLVM_BINARY_DIR}) # TODO: Root for `make install'. 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(ARCH "${LLVM_NATIVE_ARCH}") 31 32get_system_libs(LLVM_SYSTEM_LIBS_LIST) 33foreach(l ${LLVM_SYSTEM_LIBS_LIST}) 34 set(LLVM_SYSTEM_LIBS ${LLVM_SYSTEM_LIBS} "-l${l}") 35endforeach() 36 37foreach(c ${LLVM_TARGETS_TO_BUILD}) 38 set(TARGETS_BUILT "${TARGETS_BUILT} ${c}") 39endforeach(c) 40set(TARGETS_TO_BUILD ${TARGETS_BUILT}) 41set(TARGET_HAS_JIT "1") # TODO 42 43# Avoids replacement at config-time: 44set(LLVM_CPPFLAGS "@LLVM_CPPFLAGS@") 45set(LLVM_CFLAGS "@LLVM_CFLAGS@") 46set(LLVM_CXXFLAGS "@LLVM_CXXFLAGS@") 47set(LLVM_LDFLAGS "@LLVM_LDFLAGS@") 48set(LIBS "@LIBS@") 49set(LLVM_BUILDMODE "@LLVM_BUILDMODE@") 50 51configure_file( 52 ${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.in.in 53 ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in 54 @ONLY 55) 56 57set(LIBDEPS ${CMAKE_CURRENT_BINARY_DIR}/LibDeps.txt) 58set(LIBDEPS_TMP ${CMAKE_CURRENT_BINARY_DIR}/LibDeps.txt.tmp) 59set(FINAL_LIBDEPS ${CMAKE_CURRENT_BINARY_DIR}/FinalLibDeps.txt) 60set(LLVM_CONFIG ${LLVM_TOOLS_BINARY_DIR}/llvm-config) 61set(LLVM_CONFIG_IN ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in) 62 63if( CMAKE_CROSSCOMPILING ) 64 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) 65endif() 66 67find_program(NM_PATH nm PATH_SUFFIXES /bin) 68 69if( NOT NM_PATH ) 70 message(FATAL_ERROR "`nm' not found") 71endif() 72 73add_custom_command(OUTPUT ${LIBDEPS_TMP} 74 COMMAND ${PERL_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/GenLibDeps.pl -flat ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} ${NM_PATH} > ${LIBDEPS_TMP} 75 DEPENDS ${llvm_libs} 76 COMMENT "Regenerating ${LIBDEPS_TMP}") 77 78add_custom_command(OUTPUT ${LIBDEPS} 79 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDEPS_TMP} ${LIBDEPS} 80 DEPENDS ${LIBDEPS_TMP} 81 COMMENT "Updating ${LIBDEPS} if necessary...") 82 83add_custom_command(OUTPUT ${FINAL_LIBDEPS} 84 COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/find-cycles.pl < ${LIBDEPS} > ${FINAL_LIBDEPS} || ${CMAKE_COMMAND} -E remove -f ${FINAL_LIBDEPS} 85 DEPENDS ${LIBDEPS} 86 COMMENT "Checking for cyclic dependencies between LLVM libraries.") 87 88set(C_FLGS "${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 89set(CXX_FLGS "${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 90set(CPP_FLGS "${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 91 92add_custom_command(OUTPUT ${LLVM_CONFIG} 93 COMMAND echo 's!@LLVM_CPPFLAGS@!${CPP_FLGS}!' > temp.sed 94 COMMAND echo 's!@LLVM_CFLAGS@!${C_FLGS}!' >> temp.sed 95 COMMAND echo 's!@LLVM_CXXFLAGS@!${CXX_FLGS}!' >> temp.sed 96 # TODO: Use general flags for linking! not just for shared libs: 97 COMMAND echo 's!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}!' >> temp.sed 98 COMMAND echo 's!@LIBS@!${LLVM_SYSTEM_LIBS}!' >> temp.sed 99 COMMAND echo 's!@LLVM_BUILDMODE@!${CMAKE_BUILD_TYPE}!' >> temp.sed 100 COMMAND sed -f temp.sed < ${LLVM_CONFIG_IN} > ${LLVM_CONFIG} 101 COMMAND ${CMAKE_COMMAND} -E remove -f temp.sed 102 COMMAND cat ${FINAL_LIBDEPS} >> ${LLVM_CONFIG} 103 COMMAND chmod +x ${LLVM_CONFIG} 104 DEPENDS ${FINAL_LIBDEPS} ${LLVM_CONFIG_IN} 105 COMMENT "Building llvm-config script." 106 ) 107 108add_custom_target(llvm-config.target ALL 109 DEPENDS ${LLVM_CONFIG}) 110 111add_dependencies(llvm-config.target ${llvm_lib_targets}) 112 113# Make sure that llvm-config builds before the llvm tools, so we have 114# LibDeps.txt and can use it for updating the hard-coded library 115# dependencies on cmake/modules/LLVMLibDeps.cmake when the tools' 116# build fail due to outdated dependencies: 117set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} llvm-config.target) 118 119install(FILES ${LLVM_CONFIG} 120 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE 121 WORLD_READ WORLD_EXECUTE 122 DESTINATION bin) 123 124 125# Regeneration of library dependencies. 126 127# See the comments at the end of cmake/modules/LLVMConfig.cmake for 128# notes and guidelines. 129 130set(LLVMLibDeps ${LLVM_MAIN_SRC_DIR}/cmake/modules/LLVMLibDeps.cmake) 131set(LLVMLibDeps_TMP ${CMAKE_CURRENT_BINARY_DIR}/LLVMLibDeps.cmake.tmp) 132 133add_custom_command(OUTPUT ${LLVMLibDeps_TMP} 134 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} 135 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LLVMLibDeps_TMP} ${LLVMLibDeps} 136 DEPENDS ${FINAL_LIBDEPS} 137 COMMENT "Updating cmake library dependencies file ${LLVMLibDeps}" 138 ) 139 140if( LLVM_TARGETS_TO_BUILD STREQUAL LLVM_ALL_TARGETS ) 141 add_custom_target(llvmlibdeps.target ALL DEPENDS ${LLVMLibDeps_TMP}) 142 add_dependencies(llvmlibdeps.target llvm-config.target) 143 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} llvmlibdeps.target) 144endif() 145 146set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE) 147