-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
131 lines (102 loc) · 4.08 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
130
131
cmake_minimum_required(VERSION 2.8)
project(dnn C CXX)
set(DNN_MAJOR_VERSION 0)
set(DNN_MINOR_VERSION 1)
set(DNN_PATCH_VERSION 0)
set(DNN_VERSION
${DNN_MAJOR_VERSION}.${DNN_MINOR_VERSION}.${DNN_PATCH_VERSION})
# First, define all the compilation options.
# We default to debugging mode for developers.
option(DEBUG "Compile with debugging information" OFF)
option(PROFILE "Compile with profiling information" OFF)
option(PROTOBUF_PREFIX "Destination of installed protobuf" "")
# Set the CFLAGS and CXXFLAGS depending on the options the user specified.
# Only GCC-like compilers support -Wextra, and other compilers give tons of
# output for -Wall, so only -Wall and -Wextra on GCC.
#if(CMAKE_COMPILER_IS_GNUCC)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
#endif(CMAKE_COMPILER_IS_GNUCC)
if (PROTOBUF_PREFIX)
set(PROTOBUF_LIBRARIES "${PROTOBUF_PREFIX}/lib")
set(PROTOBUF_INCLUDE_DIR "${PROTOBUF_PREFIX}/include")
set(PROTOBUF_PROTOC_EXECUTABLE "${PROTOBUF_PREFIX}/bin/protoc")
endif(PROTOBUF_PREFIX)
include(cmake/FindProtobuf.cmake)
find_package(Threads REQUIRED)
# Debugging CFLAGS. Turn optimizations off; turn debugging symbols on.
if(DEBUG)
add_definitions(-DDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -g -O0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -g -O0")
elseif(PROFILE)
add_definitions(-DNDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pg")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pg")
else()
add_definitions(-DNDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -std=c++14 -g -O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math -std=gnu99 -g -O3")
endif(DEBUG)
if(PERF)
add_definitions(-DPERF)
endif(PERF)
# Profiling CFLAGS. Turn profiling information on.
#if(PROFILE)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
#endif(PROFILE)
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)
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_BINARY_DIR})
set(LIBLIST libdnnpb libdnn libspikeworkpb libground libgroundpb)
macro(PATCH_APPLE DST)
if (APPLE)
foreach(LIB ${LIBLIST})
install(CODE
"EXECUTE_PROCESS(COMMAND install_name_tool -change ${LIB}.dylib ${CMAKE_INSTALL_PREFIX}/lib/${LIB}.dylib ${CMAKE_INSTALL_PREFIX}/${DST})"
)
endforeach(LIB)
endif()
endmacro()
macro(DEFINE_MODEL BIN CPP)
add_executable(${BIN}
${CPP}
)
include_directories(${PROTOBUF_INCLUDE_DIR})
target_link_libraries(${BIN} ${PROTOBUF_LIBRARY} dnn m)
get_filename_component(model_bn ${CMAKE_CURRENT_SOURCE_DIR} NAME_WE)
install(TARGETS ${BIN} RUNTIME DESTINATION models/${model_bn})
file(GLOB ConfigFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.pb.txt")
foreach(ConfigFile ${ConfigFiles})
install(CODE
"EXECUTE_PROCESS(COMMAND ln -sf ${ConfigFile} ${CMAKE_INSTALL_PREFIX}/models/${model_bn})"
)
endforeach(ConfigFile)
file(GLOB RScripts "${CMAKE_CURRENT_SOURCE_DIR}/*.R")
foreach(RScript ${RScripts})
install(CODE
"EXECUTE_PROCESS(COMMAND ln -sf ${RScript} ${CMAKE_INSTALL_PREFIX}/models/${model_bn})"
)
endforeach(RScript)
PATCH_APPLE(models/${model_bn}/${BIN})
if (APPLE)
foreach(LIB libdnnpb libdnn libspikeworkpb libground libgroundpb)
install(CODE
"EXECUTE_PROCESS(COMMAND install_name_tool -change ${LIB}.dylib ${CMAKE_INSTALL_PREFIX}/lib/${LIB}.dylib ${CMAKE_INSTALL_PREFIX}/models/${model_bn}/${BIN} )"
)
endforeach(LIB)
endif()
endmacro()
FILE(GLOB RESULT "${CMAKE_SOURCE_DIR}/ground/*")
LIST(LENGTH RESULT RES_LEN)
IF(RES_LEN EQUAL 0)
MESSAGE(FATAL_ERROR "Module ground not found, need to do this command:\ncd ${CMAKE_SOURCE_DIR}/ground\ngit submodule init && git submodule update")
ENDIF()
add_subdirectory(ground)
add_subdirectory(dnn)
add_subdirectory(tools)
add_subdirectory(models)