-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
63 lines (49 loc) · 1.85 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
cmake_minimum_required(VERSION 3.1)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(SHARPlib CXX)
include(GNUInstallDirs)
include(CTest)
## Useful macro for setting the CXX standard
macro(use_cxx17)
if (CMAKE_VERSION VERSION_LESS "3.1")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else ()
set (CMAKE_CXX_STANDARD 17)
endif ()
endmacro(use_cxx17)
## This is where we set the CXX standard
use_cxx17()
## Bring the headers into the project
include_directories(include)
include_directories(external/fmt/include)
## add all CPP files as sources
file(GLOB SOURCES "src/SHARPlib/*.cpp" "src/SHARPlib/params/*.cpp")
## Add the library build command
## The library target is SHARP, we are building a static lib,
## and the sources are proviced
add_library(SHARPlib STATIC ${SOURCES})
## We are telling the build process that the SHARP library
## should use the C++ linker, and setting compile options
set_target_properties(SHARPlib PROPERTIES LINKER_LANGUAGE CXX)
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
## Check if the build type is set and default to
## release, and then set the compiler flags
## for release and debug
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g -O3 -ftree-vectorize -funroll-loops")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ftree-vectorize -funroll-loops")
## used for passing custom build options
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(LOCAL_PREFIX "${CMAKE_SOURCE_DIR}")
set(CMAKE_INSTALL_PREFIX "${LOCAL_PREFIX}")
## install it to the PROJECT_ROOT/lib directory
install(TARGETS SHARPlib DESTINATION lib)
## This ensures that tests arent unintentionally added or built
## by other CMake projects that link to this library
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(tests/unit)
add_subdirectory(tests/benchmark)
endif ()
enable_testing()