Arrays and vectors with different numbers of elements are not equivalent.
[llvm.git] / tools / llvm-config / CMakeLists.txt
blob7a43dbafeb199c3ecc9f5972ac277e69ff0a0c51
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 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(ARCH "${LLVM_NATIVE_ARCH}")
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 foreach(c ${LLVM_TARGETS_TO_BUILD})
38   set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
39 endforeach(c)
40 set(TARGETS_TO_BUILD ${TARGETS_BUILT})
41 set(TARGET_HAS_JIT "1")  # TODO
43 # Avoids replacement at config-time:
44 set(LLVM_CPPFLAGS "@LLVM_CPPFLAGS@")
45 set(LLVM_CFLAGS "@LLVM_CFLAGS@")
46 set(LLVM_CXXFLAGS "@LLVM_CXXFLAGS@")
47 set(LLVM_LDFLAGS "@LLVM_LDFLAGS@")
48 set(LIBS "@LIBS@")
49 set(LLVM_BUILDMODE "@LLVM_BUILDMODE@")
51 configure_file(
52   ${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.in.in
53   ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in
54   @ONLY
57 set(LIBDEPS ${CMAKE_CURRENT_BINARY_DIR}/LibDeps.txt)
58 set(LIBDEPS_TMP ${CMAKE_CURRENT_BINARY_DIR}/LibDeps.txt.tmp)
59 set(FINAL_LIBDEPS ${CMAKE_CURRENT_BINARY_DIR}/FinalLibDeps.txt)
60 set(LLVM_CONFIG ${LLVM_TOOLS_BINARY_DIR}/llvm-config)
61 set(LLVM_CONFIG_IN ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in)
63 if( CMAKE_CROSSCOMPILING )
64   set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
65 endif()
67 find_program(NM_PATH nm PATH_SUFFIXES /bin)
69 if( NOT NM_PATH )
70   message(FATAL_ERROR "`nm' not found")
71 endif()
73 add_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}")
78 add_custom_command(OUTPUT ${LIBDEPS}
79   COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDEPS_TMP} ${LIBDEPS}
80   DEPENDS ${LIBDEPS_TMP}
81   COMMENT "Updated ${LIBDEPS} because dependencies changed")
83 add_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.")
88 set(C_FLGS "${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
89 set(CXX_FLGS "${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
90 set(CPP_FLGS "${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
92 add_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   )
108 add_custom_target(llvm-config.target ALL
109   DEPENDS ${LLVM_CONFIG})
111 add_dependencies(llvm-config.target ${llvm_lib_targets})
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:
117 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} llvm-config.target)
119 install(FILES ${LLVM_CONFIG}
120   PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
121   WORLD_READ WORLD_EXECUTE
122   DESTINATION bin)
125 # Regeneration of library dependencies.
127 # See the comments at the end of cmake/modules/LLVMConfig.cmake for
128 # notes and guidelines.
130 set(LLVMLibDeps ${LLVM_MAIN_SRC_DIR}/cmake/modules/LLVMLibDeps.cmake)
131 set(LLVMLibDeps_TMP ${CMAKE_CURRENT_BINARY_DIR}/LLVMLibDeps.cmake.tmp)
133 add_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   )
140 if( 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)
144 endif()
146 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)