[arc] Remove unittesting from arcconfig
[polly-mirror.git] / CMakeLists.txt
blobaf0263b7810e6d8c7c4ae6f6279b16597db00425
1 # Check if this is a in tree build.
2 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
3   project(Polly)
4   cmake_minimum_required(VERSION 3.4.3)
6   # Where is LLVM installed?
7   find_package(LLVM CONFIG REQUIRED)
8   set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
9   include(HandleLLVMOptions)
10   include(AddLLVM)
12   # Add the llvm header path.
13   include_directories(${LLVM_INCLUDE_DIRS})
15   # Sources available, too?
16   if (LLVM_BUILD_MAIN_SRC_DIR)
17     set(LLVM_SOURCE_ROOT ${LLVM_BUILD_MAIN_SRC_DIR} CACHE PATH
18       "Path to LLVM source tree")
19   else()
20     execute_process(COMMAND "${LLVM_TOOLS_BINARY_DIR}/llvm-config" --src-root
21       OUTPUT_VARIABLE MAIN_SRC_DIR
22       OUTPUT_STRIP_TRAILING_WHITESPACE)
23     set(LLVM_SOURCE_ROOT ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
24   endif()
26   # Enable unit tests if available.
27   set(POLLY_GTEST_AVAIL 0)
28   set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest)
29   if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
30     # The build tree already exports the gtest target, which we can reuse
31     if (TARGET gtest)
32       # LLVM Doesn't export gtest's include directorys, so do that here
33       set_target_properties(gtest
34         PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
35         "${UNITTEST_DIR}/googletest/include;${UNITTEST_DIR}/googlemock/include"
36         )
37       set(POLLY_GTEST_AVAIL 1)
38     else()
39       add_library(gtest
40         ${UNITTEST_DIR}/googletest/src/gtest-all.cc
41         ${UNITTEST_DIR}/googlemock/src/gmock-all.cc
42         )
43       target_include_directories(gtest
44         PUBLIC
45         "${UNITTEST_DIR}/googletest/include"
46         "${UNITTEST_DIR}/googlemock/include"
48         PRIVATE
49         "${UNITTEST_DIR}/googletest"
50         "${UNITTEST_DIR}/googlemock"
51         )
52       target_link_libraries(gtest PUBLIC -lpthread)
54       add_library(gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp)
55       target_link_libraries(gtest_main PUBLIC gtest)
57       set(POLLY_GTEST_AVAIL 1)
58     endif()
59   endif()
61   # Make sure the isl c files are built as fPIC
62   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
64   # Set directory for polly-isl-test.
65   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
66 else ()
67   set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
68   set(POLLY_GTEST_AVAIL 1)
69 endif ()
71 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
72 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
74 # Add path for custom modules
75 set(CMAKE_MODULE_PATH
76   ${CMAKE_MODULE_PATH}
77   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
78   )
80 include("polly_macros")
82 # Add appropriate flags for GCC
83 if (CMAKE_COMPILER_IS_GNUCXX)
84   # FIXME: Turn off exceptions, RTTI:
85   # -fno-exceptions -fno-rtti
86   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")
87 elseif (MSVC)
88   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
89   add_definitions("-D_HAS_EXCEPTIONS=0")
90 else ()
91   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
92 endif ()
94 # Add path for custom modules
95 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
97 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
99 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
100 if (POLLY_ENABLE_GPGPU_CODEGEN)
101   # Do not require CUDA/OpenCL, as GPU code generation test cases can be run
102   # without a CUDA/OpenCL library.
103   FIND_PACKAGE(CUDA)
104   FIND_PACKAGE(OpenCL)
105   set(GPU_CODEGEN TRUE)
106 else(POLLY_ENABLE_GPGPU_CODEGEN)
107   set(GPU_CODEGEN FALSE)
108 endif(POLLY_ENABLE_GPGPU_CODEGEN)
111 # Support GPGPU code generation if the library is available.
112 if (CUDA_FOUND)
113   add_definitions(-DHAS_LIBCUDART)
114   INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} )
115 endif(CUDA_FOUND)
116 if (OpenCL_FOUND)
117   add_definitions(-DHAS_LIBOPENCL)
118   INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
119 endif(OpenCL_FOUND)
121 option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
122 if (NOT POLLY_BUNDLED_ISL)
123   find_package(ISL MODULE REQUIRED)
124   message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
125   set(ISL_TARGET ISL)
126 else()
127   set(ISL_INCLUDE_DIRS
128     ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
129     ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
130   )
131   set(ISL_TARGET PollyISL)
132 endif()
134 option(POLLY_BUNDLED_JSONCPP "Use the bundled version of jsoncpp included in Polly" ON)
135 if (POLLY_BUNDLED_JSONCPP)
136   set(JSONCPP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib/External/JSON/include")
137   set(JSONCPP_LIBRARIES)
138   set(POLLY_JSON_FILES
139     External/JSON/json_reader.cpp
140     External/JSON/json_value.cpp
141     External/JSON/json_writer.cpp
142   )
143 else ()
144   find_package(Jsoncpp REQUIRED)
145   set(POLLY_JSON_FILES)
146 endif ()
148 include_directories(
149   BEFORE
150   ${CMAKE_CURRENT_SOURCE_DIR}/include
151   ${ISL_INCLUDE_DIRS}
152   ${JSONCPP_INCLUDE_DIRS}
153   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
154   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
155   ${CMAKE_CURRENT_BINARY_DIR}/include
156   )
158 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
159   install(DIRECTORY include/
160     DESTINATION include
161     FILES_MATCHING
162     PATTERN "*.h"
163     PATTERN ".svn" EXCLUDE
164     )
166   install(DIRECTORY ${POLLY_BINARY_DIR}/include/
167     DESTINATION include
168     FILES_MATCHING
169     PATTERN "*.h"
170     PATTERN "CMakeFiles" EXCLUDE
171     PATTERN ".svn" EXCLUDE
172     )
173 endif()
175 add_definitions( -D_GNU_SOURCE )
177 add_subdirectory(docs)
178 add_subdirectory(lib)
179 add_subdirectory(test)
180 if (POLLY_GTEST_AVAIL)
181   add_subdirectory(unittests)
182 endif ()
183 add_subdirectory(tools)
184 add_subdirectory(cmake)
185 # TODO: docs.
188 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
189                 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
191 # Add target to check formatting of polly files
192 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
193 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
194 list( REMOVE_ITEM files ${external})
196 set(check_format_depends)
197 set(update_format_depends)
198 set(i 0)
199 foreach (file IN LISTS files)
200   add_custom_command(OUTPUT polly-check-format${i}
201     COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
202     VERBATIM
203     COMMENT "Checking format of ${file}..."
204   )
205   list(APPEND check_format_depends "polly-check-format${i}")
207   add_custom_command(OUTPUT polly-update-format${i}
208     COMMAND clang-format -sort-includes -i -style=llvm ${file}
209     VERBATIM
210     COMMENT "Updating format of ${file}..."
211   )
212   list(APPEND update_format_depends "polly-update-format${i}")
214   math(EXPR i ${i}+1)
215 endforeach ()
217 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
218 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
220 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
221 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")