CMakeLists.txt revision 81a875585c23ddc914e2f2955d87d1bf84696aa1
1include(TestBigEndian)
2
3if( NOT PERL_FOUND )
4  message(FATAL_ERROR "Perl required but not found!")
5endif( NOT PERL_FOUND )
6
7set(PERL ${PERL_EXECUTABLE})
8set(VERSION PACKAGE_VERSION)
9set(PREFIX ${LLVM_BINARY_DIR}) # TODO: Root for `make install'.
10execute_process(COMMAND date
11  OUTPUT_VARIABLE LLVM_CONFIGTIME
12  OUTPUT_STRIP_TRAILING_WHITESPACE)
13# LLVM_ON_UNIX and LLVM_ON_WIN32 already set.
14# those are set to blank by `autoconf' on MinGW, so it seems they are not required:
15#set(LLVMGCCDIR "")
16#set(LLVMGCC "")
17#set(LLVMGXX "")
18#set(LLVMGCC_VERSION "")
19#set(LLVMGCC_MAJVERS "")
20test_big_endian(IS_BIG_ENDIAN)
21if( IS_BIG_ENDIAN )
22  set(ENDIAN "big")
23else( IS_BIG_ENDIAN )
24  set(ENDIAN "little")
25endif( IS_BIG_ENDIAN )
26set(SHLIBEXT ${LTDL_SHLIB_EXT})
27#EXEEXT already set.
28set(OS "${CMAKE_SYSTEM}")
29set(ARCH "X86") # TODO: This gives "i686" in Linux: "${CMAKE_SYSTEM_PROCESSOR}")
30
31get_system_libs(LLVM_SYSTEM_LIBS_LIST)
32foreach(l ${LLVM_SYSTEM_LIBS_LIST})
33  set(LLVM_SYSTEM_LIBS ${LLVM_SYSTEM_LIBS} "-l${l}")
34endforeach()
35
36include(GetTargetTriple)
37get_target_triple(target)
38
39foreach(c ${LLVM_TARGETS_TO_BUILD})
40  set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
41endforeach(c)
42set(TARGETS_TO_BUILD ${TARGETS_BUILT})
43set(TARGET_HAS_JIT "1")  # TODO
44
45# Avoids replacement at config-time:
46set(LLVM_CPPFLAGS "@LLVM_CPPFLAGS@")
47set(LLVM_CFLAGS "@LLVM_CFLAGS@")
48set(LLVM_CXXFLAGS "@LLVM_CXXFLAGS@")
49set(LLVM_LDFLAGS "@LLVM_LDFLAGS@")
50set(LIBS "@LIBS@")
51set(LLVM_BUILDMODE "@LLVM_BUILDMODE@")
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 ${CMAKE_CURRENT_BINARY_DIR}/LibDeps.txt)
60set(LIBDEPS_TMP ${CMAKE_CURRENT_BINARY_DIR}/LibDeps.txt.tmp)
61set(FINAL_LIBDEPS ${CMAKE_CURRENT_BINARY_DIR}/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
75add_custom_command(OUTPUT ${LIBDEPS_TMP}
76  COMMAND ${PERL_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/GenLibDeps.pl -flat ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} ${NM_PATH} > ${LIBDEPS_TMP}
77  DEPENDS ${llvm_libs}
78  COMMENT "Regenerating ${LIBDEPS_TMP}")
79
80add_custom_command(OUTPUT ${LIBDEPS}
81  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDEPS_TMP} ${LIBDEPS}
82  DEPENDS ${LIBDEPS_TMP}
83  COMMENT "Updated ${LIBDEPS} because dependencies changed")
84
85add_custom_command(OUTPUT ${FINAL_LIBDEPS}
86  COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/find-cycles.pl < ${LIBDEPS} > ${FINAL_LIBDEPS} || ${CMAKE_COMMAND} -E remove -f ${FINAL_LIBDEPS}
87  DEPENDS ${LIBDEPS}
88  COMMENT "Checking for cyclic dependencies between LLVM libraries.")
89
90set(C_FLGS "${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
91set(CXX_FLGS "${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
92set(CPP_FLGS "${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
93
94add_custom_command(OUTPUT ${LLVM_CONFIG}
95  COMMAND echo 's!@LLVM_CPPFLAGS@!${CPP_FLGS}!' > temp.sed
96  COMMAND echo 's!@LLVM_CFLAGS@!${C_FLGS}!' >> temp.sed
97  COMMAND echo 's!@LLVM_CXXFLAGS@!${CXX_FLGS}!' >> temp.sed
98  # TODO: Use general flags for linking! not just for shared libs:
99  COMMAND echo 's!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}!' >> temp.sed
100  COMMAND echo 's!@LIBS@!${LLVM_SYSTEM_LIBS}!' >> temp.sed
101  COMMAND echo 's!@LLVM_BUILDMODE@!${CMAKE_BUILD_TYPE}!' >> temp.sed
102  COMMAND sed -f temp.sed < ${LLVM_CONFIG_IN} > ${LLVM_CONFIG}
103  COMMAND ${CMAKE_COMMAND} -E remove -f temp.sed
104  COMMAND cat ${FINAL_LIBDEPS} >> ${LLVM_CONFIG}
105  COMMAND chmod +x ${LLVM_CONFIG}
106  COMMAND cd ${CMAKE_BINARY_DIR} && ${CMAKE_COMMAND} -U HAVE_LLVM_CONFIG -D LLVM_BINARY_DIR="${LLVM_BINARY_DIR}" ${CMAKE_SOURCE_DIR}
107  DEPENDS ${FINAL_LIBDEPS} ${LLVM_CONFIG_IN}
108  COMMENT "Building llvm-config script."
109  )
110
111add_custom_target(llvm-config.target ALL
112  DEPENDS ${LLVM_CONFIG})
113
114add_dependencies(llvm-config.target ${llvm_lib_targets})
115
116install(FILES ${LLVM_CONFIG}
117  PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
118  WORLD_READ WORLD_EXECUTE
119  DESTINATION bin)
120