-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
130 lines (111 loc) · 4.2 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
cmake_minimum_required(VERSION 3.9)
project(Openbps C CXX)
set(CMAKE_CXX_STANDARD 17)
# Setup output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Set module path
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
#===============================================================================
# Command line options
#===============================================================================
option(optimize "Turn on O3 flag" OFF)
option(openmp "Enable shared-memory parallelism with OpenMP" ON)
option(test "Build test with google test package" ON)
#===============================================================================
# Include source directories
#===============================================================================
include_directories(include/openbps)
include_directories(src)
include_directories(test)
include_directories(build)
include_directories(extern)
#===============================================================================
# Update git submodules as needed
#===============================================================================
find_package(Git)
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL 0)
message(FATAL_ERROR "git submodule update --init failed with \
${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
if(GIT_SUBMOD_RESULT EQUAL 0)
message(STATUS "Eigen processing..")
execute_process(COMMAND cmake ${CMAKE_CURRENT_SOURCE_DIR}/extern/eigen)
endif()
endif()
endif()
#===============================================================================
# Include extern packages
#===============================================================================
add_subdirectory(extern/xtl)
add_subdirectory(extern/xtensor)
target_link_libraries(xtensor INTERFACE xtl)
add_subdirectory(lib/googletest)
add_definitions(-DHAVE_CBLAS=1)
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
#Binary build
#===============================================================================
# Compiler options
#===============================================================================
#Check compiler options
if(optimize)
list(APPEND cxxflags -O3)
endif()
if(openmp)
# Requires CMake 3.1+
find_package(OpenMP)
if(OPENMP_FOUND)
list(APPEND cxxflags ${OpenMP_CXX_FLAGS})
list(APPEND ldflags ${OpenMP_CXX_FLAGS})
endif()
endif()
# Show flags being used
message(STATUS "C++ flags: ${cxxflags}")
#===============================================================================
# Setup process
#===============================================================================
list(APPEND lib_SOURCES
"src/chain.cpp"
"src/configure.cpp"
"src/executer.cpp"
"src/filter.cpp"
"src/functionals.cpp"
"src/materials.cpp"
"src/matrix.cpp"
"src/nuclide.cpp"
"src/parse.cpp"
"src/reactions.cpp"
"extern/pugiData/pugixml.cpp")
add_library(openbps_lib STATIC ${lib_SOURCES})
# Includes
target_include_directories(openbps_lib
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
# Set compile flags
target_compile_options(openbps_lib PRIVATE ${cxxflags})
# Link library
target_link_libraries(openbps_lib Eigen3::Eigen xtensor)
add_executable(openbps "../src/main.cpp" )
# Set compile flags
target_compile_options(openbps PRIVATE ${cxxflags})
# Link executable
target_link_libraries(openbps PUBLIC openbps_lib)
#Test build
if(test)
add_executable(o_tst "../test/test.cpp"
"../test/main_test.cpp"
"../lib/googletest/googletest/include/gtest/gtest.h"
${lib_SOURCES})
add_test(NAME o_tst COMMAND o_tst)
target_link_libraries(o_tst PUBLIC openbps_lib gtest)
endif()