Skip to content

Commit a229b3c

Browse files
author
Oscar Fuentes
committed
Initial support for the CMake build system.
llvm-svn: 56419
1 parent 91ef8fc commit a229b3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2276
-0
lines changed

llvm/CMakeLists.txt

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
cmake_minimum_required(VERSION 2.6.1)
2+
3+
set(PACKAGE_NAME llvm)
4+
set(PACKAGE_VERSION svn)
5+
set(PACKAGE_BUGREPORT "ofv@wanadoo.es")
6+
#set(PACKAGE_BUGREPORT "llvmbugs@cs.uiuc.edu")
7+
8+
include(FindPerl)
9+
10+
set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
11+
set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include/llvm)
12+
set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
13+
set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
14+
set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
15+
16+
# TODO: Support user-specified targets:
17+
set(LLVM_TARGETS_TO_BUILD X86)
18+
19+
if( NOT MSVC )
20+
set(CMAKE_CXX_LINK_EXECUTABLE "sh -c \"${CMAKE_CXX_LINK_EXECUTABLE}\"")
21+
endif( NOT MSVC )
22+
23+
# TODO: Eliminate?
24+
get_filename_component(llvm_include_path ${LLVM_MAIN_SRC_DIR}/include ABSOLUTE)
25+
26+
#get_filename_component(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm ABSOLUTE)
27+
set(llvm_builded_incs_dir ${LLVM_BINARY_DIR}/include/llvm)
28+
29+
# Add path for custom modules
30+
set(CMAKE_MODULE_PATH
31+
${CMAKE_MODULE_PATH}
32+
"${LLVM_MAIN_SRC_DIR}/cmake"
33+
"${LLVM_MAIN_SRC_DIR}/cmake/modules"
34+
)
35+
36+
if(WIN32)
37+
set(LLVM_ON_WIN32 1)
38+
set(LLVM_ON_UNIX 0)
39+
set(LTDL_SHLIB_EXT ".dll")
40+
set(EXEEXT ".exe")
41+
# Maximum path length is 160 for non-unicode paths
42+
set(MAXPATHLEN 160)
43+
else(WIN32)
44+
if(UNIX)
45+
set(LLVM_ON_WIN32 0)
46+
set(LLVM_ON_UNIX 1)
47+
set(LTDL_SHLIB_EXT ".so")
48+
set(EXEEXT "")
49+
# FIXME: Maximum path length is currently set to 'safe' fixed value
50+
set(MAXPATHLEN 2024)
51+
else(UNIX)
52+
MESSAGE(SEND_ERROR "Unable to determine platform")
53+
endif(UNIX)
54+
endif(WIN32)
55+
56+
if( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
57+
set(HAVE_LLVM_CONFIG 1)
58+
endif( EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-config )
59+
# find_file(HAVE_LLVM_CONFIG llvm-config ${LLVM_TOOLS_BINARY_DIR})
60+
# message(STATUS ${HAVE_LLVM_CONFIG})
61+
62+
if( MSVC )
63+
message(STATUS "Configuring using MSVC hack.")
64+
include(config-w32)
65+
else( MSVC )
66+
message(STATUS "Configuring traditional style.")
67+
include(config-ix)
68+
endif( MSVC )
69+
70+
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR} )
71+
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
72+
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib )
73+
74+
# set(CMAKE_VERBOSE_MAKEFILE true)
75+
76+
add_definitions( -D__STDC_LIMIT_MACROS )
77+
78+
if( LLVM_ON_UNIX )
79+
add_definitions( -DLLVM_ON_UNIX )
80+
else( LLVM_ON_UNIX )
81+
add_definitions( -DLLVM_ON_WIN32 )
82+
endif( LLVM_ON_UNIX )
83+
84+
if( MSVC )
85+
add_definitions( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS )
86+
add_definitions( -D_SCL_SECURE_NO_WARNINGS -DCRT_NONSTDC_NO_WARNINGS )
87+
add_definitions( -D_SCL_SECURE_NO_DEPRECATE )
88+
endif( MSVC )
89+
90+
include_directories( ${LLVM_BINARY_DIR}/include ${llvm_include_path})
91+
#link_directories( d:/dev/lib )
92+
93+
#add_subdirectory(lib)
94+
95+
include(AddLLVM)
96+
include(AddPartiallyLinkedObject)
97+
98+
add_subdirectory(lib/Support)
99+
add_subdirectory(lib/System)
100+
add_subdirectory(utils/TableGen)
101+
102+
add_custom_command(OUTPUT ${llvm_builded_incs_dir}/Intrinsics.gen
103+
COMMAND tblgen -gen-intrinsic -I ${llvm_include_path} ${llvm_include_path}/llvm/Intrinsics.td -o ${llvm_builded_incs_dir}/Intrinsics.gen
104+
DEPENDS tblgen
105+
COMMENT "Building intrinsics.gen...")
106+
107+
add_custom_target(intrinsics_gen ALL
108+
DEPENDS ${llvm_builded_incs_dir}/Intrinsics.gen)
109+
110+
add_subdirectory(lib/VMCore)
111+
add_subdirectory(lib/CodeGen)
112+
add_subdirectory(lib/CodeGen/SelectionDAG)
113+
add_subdirectory(lib/CodeGen/AsmPrinter)
114+
add_subdirectory(lib/Bitcode/Reader)
115+
add_subdirectory(lib/Bitcode/Writer)
116+
add_subdirectory(lib/Transforms/Utils)
117+
add_subdirectory(lib/Transforms/Instrumentation)
118+
add_subdirectory(lib/Transforms/Scalar)
119+
add_subdirectory(lib/Transforms/IPO)
120+
add_subdirectory(lib/Transforms/Hello)
121+
add_subdirectory(lib/Linker)
122+
add_subdirectory(lib/Analysis)
123+
add_subdirectory(lib/Analysis/IPA)
124+
add_subdirectory(lib/Target/X86)
125+
add_subdirectory(lib/Target/X86/AsmPrinter)
126+
add_subdirectory(lib/ExecutionEngine)
127+
add_subdirectory(lib/ExecutionEngine/Interpreter)
128+
add_subdirectory(lib/ExecutionEngine/JIT)
129+
add_subdirectory(lib/Target)
130+
add_subdirectory(lib/AsmParser)
131+
add_subdirectory(lib/Debugger)
132+
# TODO: lib/Target/CBackEnd
133+
add_subdirectory(lib/Archive)
134+
135+
add_subdirectory(tools)
136+
137+
add_subdirectory(examples)

llvm/cmake/config-ix.cmake

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
# include checks
3+
include(CheckIncludeFile)
4+
check_include_file(argz.h HAVE_ARGZ_H)
5+
check_include_file(assert.h HAVE_ASSERT_H)
6+
check_include_file(dirent.h HAVE_DIRENT_H)
7+
check_include_file(dl.h HAVE_DL_H)
8+
check_include_file(dld.h HAVE_DLD_H)
9+
check_include_file(dlfcn.h HAVE_DLFCN_H)
10+
check_include_file(errno.h HAVE_ERRNO_H)
11+
check_include_file(execinfo.h HAVE_EXECINFO_H)
12+
check_include_file(fcntl.h HAVE_FCNTL_H)
13+
check_include_file(inttypes.h HAVE_INTTYPES_H)
14+
check_include_file(limits.h HAVE_LIMITS_H)
15+
check_include_file(link.h HAVE_LINK_H)
16+
check_include_file(malloc.h HAVE_MALLOC_H)
17+
check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
18+
check_include_file(memory.h HAVE_MEMORY_H)
19+
check_include_file(ndir.h HAVE_NDIR_H)
20+
check_include_file(pthread.h HAVE_PTHREAD_H)
21+
check_include_file(setjmp.h HAVE_SETJMP_H)
22+
check_include_file(signal.h HAVE_SIGNAL_H)
23+
check_include_file(stdint.h HAVE_STDINT_H)
24+
check_include_file(stdio.h HAVE_STDIO_H)
25+
check_include_file(stdlib.h HAVE_STDLIB_H)
26+
check_include_file(sys/dir.h HAVE_SYS_DIR_H)
27+
check_include_file(sys/dl.h HAVE_SYS_DL_H)
28+
check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
29+
check_include_file(sys/ndir.h HAVE_SYS_NDIR_H)
30+
check_include_file(sys/param.h HAVE_SYS_PARAM_H)
31+
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
32+
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
33+
check_include_file(sys/time.h HAVE_SYS_TIME_H)
34+
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
35+
check_include_file(unistd.h HAVE_UNISTD_H)
36+
check_include_file(utime.h HAVE_UTIME_H)
37+
38+
# function checks
39+
include(CheckSymbolExists)
40+
check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
41+
check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
42+
check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
43+
check_symbol_exists(isinf cmath HAVE_ISINF_IN_CMATH)
44+
check_symbol_exists(isinf math.h HAVE_ISINF_IN_MATH_H)
45+
check_symbol_exists(isnan cmath HAVE_ISNAN_IN_CMATH)
46+
check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H)
47+
check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO)
48+
check_symbol_exists(pthread_mutex_lock pthread.h HAVE_PTHREAD_MUTEX_LOCK)
49+
50+
if( MINGW )
51+
# tbi: Comprobar que existen las librerias:
52+
set(HAVE_LIBIMAGEHLP 1)
53+
set(HAVE_LIBPSAPI 1)
54+
# include(CheckLibraryExists)
55+
# CHECK_LIBRARY_EXISTS(imagehlp ??? . HAVE_LIBIMAGEHLP)
56+
endif( MINGW )
57+
58+
# Classes
59+
include(CheckCxxHashmap)
60+
include(CheckCxxHashset)
61+
check_hashmap()
62+
check_hashset()
63+
64+
# FIXME: Signal handler return type, currently hardcoded to 'void'
65+
set(RETSIGTYPE void)
66+
67+
# Disable multithreading for now
68+
set(ENABLE_THREADS 0)
69+
70+
configure_file(
71+
${LLVM_MAIN_INCLUDE_DIR}/Config/config.h.cmake
72+
${LLVM_BINARY_DIR}/include/llvm/Config/config.h
73+
)
74+
75+
configure_file(
76+
${LLVM_MAIN_INCLUDE_DIR}/ADT/iterator.cmake
77+
${LLVM_BINARY_DIR}/include/llvm/ADT/iterator.h
78+
)
79+
80+
configure_file(
81+
${LLVM_MAIN_INCLUDE_DIR}/Support/DataTypes.h.cmake
82+
${LLVM_BINARY_DIR}/include/llvm/Support/DataTypes.h
83+
)
84+
85+
configure_file(
86+
${LLVM_MAIN_INCLUDE_DIR}/ADT/hash_map.cmake
87+
${LLVM_BINARY_DIR}/include/llvm/ADT/hash_map.h
88+
)
89+
90+
configure_file(
91+
${LLVM_MAIN_INCLUDE_DIR}/ADT/hash_set.cmake
92+
${LLVM_BINARY_DIR}/include/llvm/ADT/hash_set.h
93+
)

llvm/cmake/config-w32.cmake

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# tbi: Configurar ficheros.
2+
configure_file(${llvm_include_path}/llvm/ADT/hash_map.h.in ${llvm_builded_incs_dir}/ADT/hash_map.h)
3+
configure_file(${llvm_include_path}/llvm/ADT/hash_set.h.in ${llvm_builded_incs_dir}/ADT/hash_set.h)
4+
configure_file(${llvm_include_path}/llvm/ADT/iterator.h.in ${llvm_builded_incs_dir}/ADT/iterator.h)
5+
configure_file(${llvm_include_path}/llvm/Support/DataTypes.h.in ${llvm_builded_incs_dir}/Support/DataTypes.h)
6+
configure_file(${llvm_include_path}/llvm/Config/config.h.in ${llvm_builded_incs_dir}/Config/config.h)
7+
8+
file(READ ${llvm_include_path}/../win32/config.h vc_config_text)
9+
file(APPEND ${llvm_builded_incs_dir}/Config/config.h ${vc_config_text})

llvm/cmake/modules/AddLLVM.cmake

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
include(LLVMConfig)
2+
3+
macro(add_llvm_library name)
4+
add_library( ${name} ${ARGN} )
5+
set( llvm_libs ${llvm_libs} ${name} PARENT_SCOPE)
6+
endmacro(add_llvm_library name)
7+
8+
9+
macro(add_llvm_executable name)
10+
add_executable(${name} ${ARGN})
11+
if( LLVM_LINK_COMPONENTS )
12+
llvm_config(${name} ${LLVM_LINK_COMPONENTS})
13+
endif( LLVM_LINK_COMPONENTS )
14+
if( MSVC )
15+
target_link_libraries(${name} ${llvm_libs})
16+
else( MSVC )
17+
add_dependencies(${name} llvm-config.target)
18+
set_target_properties(${name}
19+
PROPERTIES
20+
LINK_FLAGS "-L ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")
21+
if( MINGW )
22+
target_link_libraries(${name} DbgHelp psapi)
23+
elseif( CMAKE_HOST_UNIX )
24+
target_link_libraries(${name} dl)
25+
endif( MINGW )
26+
endif( MSVC )
27+
endmacro(add_llvm_executable name)
28+
29+
30+
macro(add_llvm_tool name)
31+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
32+
add_llvm_executable(${name} ${ARGN})
33+
endmacro(add_llvm_tool name)
34+
35+
36+
macro(add_llvm_example name)
37+
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
38+
add_llvm_executable(${name} ${ARGN})
39+
endmacro(add_llvm_example name)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
macro(add_partially_linked_object lib)
3+
if( MSVC )
4+
add_llvm_library( ${lib} ${ARGN})
5+
else( MSVC )
6+
set(pll ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${lib}.o)
7+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib)
8+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib)
9+
add_library( ${lib} STATIC ${ARGN})
10+
add_custom_command(OUTPUT ${pll}
11+
MESSAGE "Building ${lib}.o..."
12+
DEPENDS ${lib}
13+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib
14+
COMMAND ar x ${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}
15+
COMMAND ld -r *${CMAKE_CXX_OUTPUT_EXTENSION} -o ${pll}
16+
COMMAND rm -f *${CMAKE_CXX_OUTPUT_EXTENSION}
17+
)
18+
add_custom_target(${lib}_pll ALL DEPENDS ${pll})
19+
set( llvm_libs ${llvm_libs} ${pll} PARENT_SCOPE)
20+
endif( MSVC )
21+
endmacro(add_partially_linked_object lib)
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# - Check if for hash_map.
2+
# CHECK_HASHMAP ()
3+
#
4+
5+
include(CheckCXXSourceCompiles)
6+
7+
macro(CHECK_HASHMAP)
8+
message(STATUS "Checking for C++ hash_map implementation...")
9+
check_cxx_source_compiles("
10+
#include <ext/hash_map>
11+
int main() {
12+
__gnu_cxx::hash_map<int, int> t;
13+
}
14+
"
15+
HAVE_GNU_EXT_HASH_MAP
16+
)
17+
if(HAVE_GNU_EXT_HASH_MAP)
18+
message(STATUS "C++ hash_map found in 'ext' dir in namespace __gnu_cxx::")
19+
endif(HAVE_GNU_EXT_HASH_MAP)
20+
21+
check_cxx_source_compiles("
22+
#include <ext/hash_map>
23+
int main() {
24+
std::hash_map<int, int> t;
25+
}
26+
"
27+
HAVE_STD_EXT_HASH_MAP
28+
)
29+
if(HAVE_STD_EXT_HASH_MAP)
30+
message(STATUS "C++ hash_map found in 'ext' dir in namespace std::")
31+
endif(HAVE_STD_EXT_HASH_MAP)
32+
33+
check_cxx_source_compiles("
34+
#include <hash_map>
35+
int main() {
36+
hash_map<int, int> t;
37+
}
38+
"
39+
HAVE_GLOBAL_HASH_MAP
40+
)
41+
if(HAVE_GLOBAL_HASH_MAP)
42+
message(STATUS "C++ hash_map found in global namespace")
43+
endif(HAVE_GLOBAL_HASH_MAP)
44+
45+
if(NOT HAVE_GNU_EXT_HASH_MAP)
46+
if(NOT HAVE_STD_EXT_HASH_MAP)
47+
if(NOT HAVE_GLOBAL_HASH_MAP)
48+
message(STATUS "C++ hash_map not found")
49+
endif(NOT HAVE_GLOBAL_HASH_MAP)
50+
endif(NOT HAVE_STD_EXT_HASH_MAP)
51+
endif(NOT HAVE_GNU_EXT_HASH_MAP)
52+
53+
endmacro(CHECK_HASHMAP)

0 commit comments

Comments
 (0)