fde628f75a107a972331c8b34e790eecab03c168
[lldb.git] / parallel-libs / streamexecutor / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.1)
2
3 option(STREAM_EXECUTOR_UNIT_TESTS "enable unit tests" ON)
4 option(STREAM_EXECUTOR_ENABLE_DOXYGEN "enable StreamExecutor doxygen" ON)
5 option(STREAM_EXECUTOR_ENABLE_CONFIG_TOOL "enable building streamexecutor-config tool" ON)
6
7 # First find includes relative to the streamexecutor top-level source path.
8 include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include)
9
10 # If we are not building as part of LLVM, build StreamExecutor as a standalone
11 # project using LLVM as an external library:
12 string(
13     COMPARE
14     EQUAL
15     "${CMAKE_SOURCE_DIR}"
16     "${CMAKE_CURRENT_SOURCE_DIR}"
17     STREAM_EXECUTOR_STANDALONE)
18
19 if(STREAM_EXECUTOR_STANDALONE)
20     project(StreamExecutor)
21
22     find_package(LLVM REQUIRED CONFIG)
23     message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
24     message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
25
26     include_directories(${LLVM_INCLUDE_DIRS})
27     add_definitions(${LLVM_DEFINITIONS})
28
29     # Get the LLVM cxxflags by using llvm-config.
30     #
31     # This is necessary to get -fno-rtti if LLVM is compiled that way.
32     execute_process(
33         COMMAND
34         "${LLVM_BINARY_DIR}/bin/llvm-config"
35         --cxxflags
36         OUTPUT_VARIABLE
37         LLVM_CXXFLAGS
38         OUTPUT_STRIP_TRAILING_WHITESPACE)
39     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXXFLAGS}")
40
41     # Find the libraries that correspond to the LLVM components
42     # that we wish to use
43     llvm_map_components_to_libnames(llvm_libs support symbolize)
44
45     if(STREAM_EXECUTOR_UNIT_TESTS)
46         enable_testing()
47         find_package(GTest REQUIRED)
48         include_directories(${GTEST_INCLUDE_DIRS})
49         find_package(Threads REQUIRED)
50     endif()
51 else(NOT STREAM_EXECUTOR_STANDALONE)
52     if(STREAM_EXECUTOR_UNIT_TESTS)
53         include_directories(
54             "${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include")
55     endif()
56 endif(STREAM_EXECUTOR_STANDALONE)
57
58 # Insist on C++ 11 features.
59 set(CMAKE_CXX_STANDARD 11)
60 set(CMAKE_CXX_STANDARD_REQUIRED ON)
61
62 # Add warning flags.
63 set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
64
65 add_subdirectory(lib)
66 add_subdirectory(examples)
67
68 if(STREAM_EXECUTOR_ENABLE_CONFIG_TOOL )
69     add_subdirectory(tools/streamexecutor-config)
70 endif(STREAM_EXECUTOR_ENABLE_CONFIG_TOOL )
71
72 install(DIRECTORY include/ DESTINATION include)
73
74 if (STREAM_EXECUTOR_ENABLE_DOXYGEN)
75     find_package(Doxygen REQUIRED)
76     configure_file(Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
77     add_custom_target(
78         doc
79         ${DOXYGEN_EXECUTABLE}
80         ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
81         WORKING_DIRECTORY
82         ${CMAKE_CURRENT_BINARY_DIR}
83         COMMENT
84         "Generating API documentation with Doxygen"
85         VERBATIM)
86 endif(STREAM_EXECUTOR_ENABLE_DOXYGEN)