-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
73 lines (60 loc) · 2.36 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
cmake_minimum_required(VERSION 3.2)
project(VSL)
find_package(LLVM 6.0.0 REQUIRED CONFIG)
find_package(Doxygen)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# compiler options
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_compile_options(-Wall -pedantic -Wextra -Wno-unused-parameter
-fno-exceptions -fno-rtti)
# vsl specific directories
set(VSL_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
set(VSL_DOCS_DIR ${PROJECT_SOURCE_DIR}/docs)
set(VSL_TEST_DIR ${PROJECT_SOURCE_DIR}/test)
set(VSL_EXT_PROJECTS_DIR ${PROJECT_SOURCE_DIR}/ext)
option(VSL_BUILD_DOCS "Build documentation using Doxygen" ${DOXYGEN_FOUND})
option(VSL_INCLUDE_TESTS "Allow building the test code through the check target"
OFF)
if(VSL_BUILD_DOCS)
# make sure doxygen is there
if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()
set(doxyfile ${PROJECT_SOURCE_DIR}/Doxyfile)
# add the docs target
add_custom_target(docs
COMMAND ${CMAKE_COMMAND} -E make_directory ${VSL_DOCS_DIR}
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Building documentation using Doxygen"
VERBATIM)
endif()
# set the default build type to debug
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
# config so the compiler knows what files are where
include_directories(${VSL_SOURCE_DIR} ${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
set(VSL_MAIN_CPP ${VSL_SOURCE_DIR}/main.cpp)
file(GLOB_RECURSE SOURCES ${VSL_SOURCE_DIR}/*.cpp)
list(REMOVE_ITEM SOURCES ${VSL_MAIN_CPP})
# used for other parts of vsl that don't use src/main.cpp, e.g. the test code
add_library(libvsl STATIC ${SOURCES})
set_target_properties(libvsl PROPERTIES PREFIX "") # so we don't get liblibvsl.a
# link all the llvm libraries
llvm_map_components_to_libnames(LLVM_LIBS ${LLVM_TARGETS_TO_BUILD})
target_link_libraries(libvsl ${LLVM_LIBS})
# include `make check` target if requested
if(VSL_INCLUDE_TESTS)
add_subdirectory(${VSL_EXT_PROJECTS_DIR}/gtest)
add_subdirectory(${VSL_TEST_DIR})
endif()
# build the executable (with main.cpp)
add_executable(vsl ${VSL_MAIN_CPP})
# link the executable with the required libraries
add_dependencies(vsl libvsl)
target_link_libraries(vsl libvsl)