CMakeLists.txt revision 05a484b909935b26533ffe81f6cb426085ff78a8
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@") 51set(LLVM_OBJ_SUFFIX "@LLVM_OBJ_SUFFIX@") 52 53configure_file( 54 ${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.in.in 55 ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in 56 @ONLY 57) 58 59set(LIBDEPS LibDeps.txt) 60set(LIBDEPS_TMP LibDeps.txt.tmp) 61set(FINAL_LIBDEPS FinalLibDeps.txt) 62set(LLVM_CONFIG ${LLVM_TOOLS_BINARY_DIR}/llvm-config) 63set(LLVM_CONFIG_IN ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in) 64 65if( CMAKE_CROSSCOMPILING ) 66 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) 67endif() 68 69find_program(NM_PATH nm PATH_SUFFIXES /bin) 70 71if( NOT NM_PATH ) 72 message(FATAL_ERROR "`nm' not found") 73endif() 74 75get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS) 76 77add_custom_command(OUTPUT ${LIBDEPS_TMP} 78 COMMAND ${PERL_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/GenLibDeps.pl -flat ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} ${NM_PATH} > ${LIBDEPS_TMP} 79 DEPENDS ${llvm_libs} 80 COMMENT "Regenerating ${LIBDEPS_TMP}") 81 82add_custom_command(OUTPUT ${LIBDEPS} 83 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDEPS_TMP} ${LIBDEPS} 84 DEPENDS ${LIBDEPS_TMP} 85 COMMENT "Updating ${LIBDEPS} if necessary...") 86 87# This must stop the build if find-cycles.pl returns error: 88add_custom_command(OUTPUT ${FINAL_LIBDEPS} 89 COMMAND ${CMAKE_COMMAND} -E remove -f ${FINAL_LIBDEPS} ${FINAL_LIBDEPS}.tmp 90 COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/find-cycles.pl < ${LIBDEPS} > ${FINAL_LIBDEPS}.tmp 91 COMMAND ${CMAKE_COMMAND} -E copy ${FINAL_LIBDEPS}.tmp ${FINAL_LIBDEPS} 92 DEPENDS ${LIBDEPS} 93 COMMENT "Checking for cyclic dependencies between LLVM libraries.") 94 95set(C_FLGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 96set(CXX_FLGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 97set(CPP_FLGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 98 99# We don't want certain flags on the output of 100# llvm-config --cflags --cxxflags 101macro(remove_option_from_llvm_config option) 102 llvm_replace_compiler_option(C_FLGS "${option}" "") 103 llvm_replace_compiler_option(CXX_FLGS "${option}" "") 104 llvm_replace_compiler_option(CPP_FLGS "${option}" "") 105endmacro(remove_option_from_llvm_config) 106remove_option_from_llvm_config("-pedantic") 107remove_option_from_llvm_config("-Wall") 108remove_option_from_llvm_config("-W") 109 110add_custom_command(OUTPUT ${LLVM_CONFIG} 111 COMMAND echo s!@LLVM_CPPFLAGS@!${CPP_FLGS}! > temp.sed 112 COMMAND echo s!@LLVM_CFLAGS@!${C_FLGS}! >> temp.sed 113 COMMAND echo s!@LLVM_CXXFLAGS@!${CXX_FLGS}! >> temp.sed 114 # TODO: Use general flags for linking! not just for shared libs: 115 COMMAND echo s!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}! >> temp.sed 116 COMMAND echo s!@LIBS@!${LLVM_SYSTEM_LIBS}! >> temp.sed 117 COMMAND echo s!@LLVM_BUILDMODE@!${CMAKE_BUILD_TYPE}! >> temp.sed 118 COMMAND echo s!@LLVM_OBJ_SUFFIX@!! >> temp.sed 119 COMMAND sed -f temp.sed < ${LLVM_CONFIG_IN} > ${LLVM_CONFIG} 120 COMMAND ${CMAKE_COMMAND} -E remove -f temp.sed 121 COMMAND cat ${FINAL_LIBDEPS} >> ${LLVM_CONFIG} 122 COMMAND chmod +x ${LLVM_CONFIG} 123 VERBATIM 124 DEPENDS ${FINAL_LIBDEPS} ${LLVM_CONFIG_IN} 125 COMMENT "Building llvm-config script." 126 ) 127 128add_custom_target(llvm-config.target ALL 129 DEPENDS ${LLVM_CONFIG}) 130 131# Ensure we build llvm-config after we build all of the libraries so that we 132# have their full dependencies. 133add_dependencies(llvm-config.target ${llvm_libs}) 134 135install(FILES ${LLVM_CONFIG} 136 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE 137 WORLD_READ WORLD_EXECUTE 138 DESTINATION bin) 139