1 # Check if this is a in tree build.
2 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
4 cmake_minimum_required(VERSION 2.8)
6 # Where is LLVM installed?
7 set(LLVM_INSTALL_ROOT "" CACHE PATH "Root of LLVM install.")
8 # Check if the LLVM_INSTALL_ROOT valid.
9 if( NOT EXISTS ${LLVM_INSTALL_ROOT}/include/llvm )
10 message(FATAL_ERROR "LLVM_INSTALL_ROOT (${LLVM_INSTALL_ROOT}) is not a valid LLVM installation.")
11 endif(NOT EXISTS ${LLVM_INSTALL_ROOT}/include/llvm)
12 #FileCheck is not install by default, warn the user to Copy FileCheck
13 if( NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/FileCheck
14 OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/not)
15 message(WARNING "FileCheck or not are required by running regress tests, "
16 "but they are not installed! Please copy it to "
17 "${LLVM_INSTALL_ROOT}/bin.")
18 endif(NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/FileCheck
19 OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/not)
20 # Add the llvm header path.
21 include_directories(${LLVM_INSTALL_ROOT}/include/)
23 # Get the system librarys that will link into LLVM.
24 function(get_system_libs return_var)
25 # Returns in `return_var' a list of system libraries used by LLVM.
28 set(system_libs ${system_libs} imagehlp psapi)
29 elseif( CMAKE_HOST_UNIX )
31 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
33 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
34 set(system_libs ${system_libs} pthread)
38 set(${return_var} ${system_libs} PARENT_SCOPE)
39 endfunction(get_system_libs)
41 # Now set the header paths.
42 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --includedir
43 OUTPUT_VARIABLE LLVM_INCLUDE_DIR
44 OUTPUT_STRIP_TRAILING_WHITESPACE)
45 include_directories( ${LLVM_INCLUDE_DIR} )
47 # Get the TARGET_TRIPLE
48 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --host-target
49 OUTPUT_VARIABLE TARGET_TRIPLE
50 OUTPUT_STRIP_TRAILING_WHITESPACE)
52 # And then set the cxx flags.
53 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --cxxflags
54 OUTPUT_VARIABLE LLVM_CXX_FLAGS
55 OUTPUT_STRIP_TRAILING_WHITESPACE)
56 set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS})
58 # Check LLVM_ENABLE_ASSERTIONS
59 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --assertion-mode
60 OUTPUT_VARIABLE LLVM_ENABLE_ASSERTIONS
61 OUTPUT_STRIP_TRAILING_WHITESPACE)
62 # Copied from LLVM's HandleLLVMOptions.cmake
63 if( LLVM_ENABLE_ASSERTIONS )
64 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
66 add_definitions( -D_DEBUG )
68 # On non-Debug builds cmake automatically defines NDEBUG, so we
69 # explicitly undefine it:
70 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
71 add_definitions( -UNDEBUG )
72 # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
73 foreach (flags_var_to_scrub
74 CMAKE_CXX_FLAGS_RELEASE
75 CMAKE_CXX_FLAGS_RELWITHDEBINFO
76 CMAKE_CXX_FLAGS_MINSIZEREL
78 CMAKE_C_FLAGS_RELWITHDEBINFO
79 CMAKE_C_FLAGS_MINSIZEREL)
80 string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
81 "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
86 # Make sure the isl c files are built as fPIC
87 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
88 endif(NOT DEFINED LLVM_MAIN_SRC_DIR)
90 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
91 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
93 # Add path for custom modules
96 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
99 include("polly_macros")
101 # Add appropriate flags for GCC
102 if (CMAKE_COMPILER_IS_GNUCXX)
103 # FIXME: Turn off exceptions, RTTI:
104 # -fno-exceptions -fno-rtti
105 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -fno-exceptions -fno-rtti")
107 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
108 add_definitions("-D_HAS_EXCEPTIONS=0")
110 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
113 # Add path for custom modules
114 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
116 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
118 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
119 if (POLLY_ENABLE_GPGPU_CODEGEN)
120 # Do not require CUDA, as GPU code generation test cases can be run without
123 set(GPU_CODEGEN TRUE)
124 endif(POLLY_ENABLE_GPGPU_CODEGEN)
126 # Support GPGPU code generation if the library is available.
128 INCLUDE_DIRECTORIES( ${CUDALIB_INCLUDE_DIR} )
133 ${CMAKE_CURRENT_SOURCE_DIR}/include
134 ${CMAKE_CURRENT_SOURCE_DIR}/lib/JSON/include
135 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
136 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
137 ${CMAKE_CURRENT_BINARY_DIR}/include
140 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
141 install(DIRECTORY include/
145 PATTERN ".svn" EXCLUDE
148 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
152 PATTERN "CMakeFiles" EXCLUDE
153 PATTERN ".svn" EXCLUDE
157 add_definitions( -D_GNU_SOURCE )
159 add_subdirectory(docs)
160 add_subdirectory(lib)
161 add_subdirectory(test)
162 add_subdirectory(tools)
166 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
167 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
169 # Add target to check formatting of polly files
170 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h)
171 file( GLOB_RECURSE jsonfiles lib/JSON/*.h lib/JSON/*.cpp)
172 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c)
173 list( REMOVE_ITEM files ${jsonfiles} ${external})
175 set(check_format_depends)
176 set(update_format_depends)
178 foreach (file IN LISTS files)
179 add_custom_command(OUTPUT polly-check-format${i}
180 COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
182 COMMENT "Checking format of ${file}..."
184 list(APPEND check_format_depends "polly-check-format${i}")
186 add_custom_command(OUTPUT polly-update-format${i}
187 COMMAND clang-format -sort-includes -i -style=llvm ${file}
189 COMMENT "Updating format of ${file}..."
191 list(APPEND update_format_depends "polly-update-format${i}")
196 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
197 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
199 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
200 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")
202 # Set the variable POLLY_LINK_LIBS in the llvm/tools/ dir.
203 set(POLLY_LINK_LIBS ${POLLY_LINK_LIBS} PARENT_SCOPE)