forked from tiny-dnn/tiny-dnn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
155 lines (125 loc) · 6.55 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#Command line options
#-DUSE_TBB=ON/OFF (default off)
#-DUSE_OMP=ON/OFF (default off)
#-DUSE_SSE=ON/OFF (default on)
#-DUSE_AVX=ON/OFF (default on)
# ----------------------------------------------------------------------------
# Basic Configuration
# ----------------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(tiny_cnn)
set(PROJECT_VERSION "0.0.1")
string(REGEX MATCHALL "[0-9]" PROJECT_VERSION_PARTS "${PROJECT_VERSION}")
list(GET PROJECT_VERSION_PARTS 0 PROJECT_VERSION_MAJOR)
list(GET PROJECT_VERSION_PARTS 1 PROJECT_VERSION_MINOR)
list(GET PROJECT_VERSION_PARTS 2 PROJECT_VERSION_PATCH)
set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
#------------------------------------------------------
# Build type
#------------------------------------------------------
IF(NOT CMAKE_BUILD_TYPE )
SET( CMAKE_BUILD_TYPE "Release" )
ENDIF()
#------------------------------------------------------
# Lib Names and Dirs
#------------------------------------------------------
if(WIN32)
# Postfix of DLLs:
SET(PROJECT_DLLVERSION "${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}${PROJECT_VERSION_PATCH}")
SET(RUNTIME_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Directory for dlls and binaries")
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Directory for binaries")
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Directory for dlls")
else()
# Postfix of so's:
set(PROJECT_DLLVERSION)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_INSTALL_PREFIX}/lib/cmake/ /usr/lib/cmake)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}")
OPTION(USE_TBB "Set to ON to use boost" OFF)
OPTION(USE_OMP "Set to ON to use boost" OFF)
OPTION(USE_SSE "Set to ON to use sse" ON)
OPTION(USE_AVX "Set to ON to use avx" ON)
# ----------------------------------------------------------------------------
# Find Dependencies
# ----------------------------------------------------------------------------
IF(USE_TBB)
find_package(TBB REQUIRED)
add_definitions(-DCNN_USE_TBB)
include_directories(${TBB_INCLUDE_DIRS})
link_directories(${TBB_LIBRARY_DIRS})
SET(REQUIRED_LIBRARIES ${REQUIRED_LIBRARIES} ${TBB_LIBRARIES} )
ELSEIF(USE_OMP)
find_package(OpenMP REQUIRED)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
add_definitions( -DCNN_USE_OMP)
ENDIF()
# ----------------------------------------------------------------------------
# COMPILER OPTIONS
# ----------------------------------------------------------------------------
if (MSVC)
IF(USE_SSE )
add_definitions(-DCNN_USE_SSE)
SET(EXTRA_C_FLAGS " ${EXTRA_C_FLAGS} /arch:SSE2 ")
ENDIF()
IF(USE_AVX )
add_definitions(-DCNN_USE_AVX)
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} /arch:AVX ")
ENDIF()
ELSE()#MSVC
SET(EXTRA_C_FLAGS_RELEASE " /Ox ")
IF(USE_SSE)
add_definitions(-DCNN_USE_SSE)
SET(EXTRA_C_FLAGS " ${EXTRA_C_FLAGS} -msse3 ")
ENDIF()
IF(USE_AVX)
add_definitions(-DCNN_USE_AVX)
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -mavx ")
ENDIF()
SET(EXTRA_C_FLAGS " ${EXTRA_C_FLAGS} -std=c++11 ")
SET(EXTRA_C_FLAGS_RELEASE " -O3 ")
SET(EXTRA_C_FLAGS_DEBUG " -g3 ")
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE}")
SET(CMAKE_CXX_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_EXE_LINKER_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${EXTRA_EXE_LINKER_FLAGS_RELEASE}")
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${EXTRA_EXE_LINKER_FLAGS_DEBUG}")
#------------------------------------------------
# TARGETS
#------------------------------------------------
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/tiny_cnn )
LINK_LIBRARIES(${REQUIRED_LIBRARIES} )
SET( tiny_cnn_hrds tiny_cnn/activation_function.h tiny_cnn/cifar10_parser.h tiny_cnn/convolutional_layer.h tiny_cnn/display.h tiny_cnn/fully_connected_dropout_layer.h tiny_cnn/image.h tiny_cnn/layer.h tiny_cnn/loss_function.h tiny_cnn/mnist_parser.h tiny_cnn/optimizer.h tiny_cnn/product.h tiny_cnn/util.h
tiny_cnn/average_pooling_layer.h tiny_cnn/config.h tiny_cnn/deform.h tiny_cnn/dropout.h tiny_cnn/fully_connected_layer.h tiny_cnn/input_layer.h tiny_cnn/layers.h tiny_cnn/max_pooling_layer.h tiny_cnn/network.h tiny_cnn/partial_connected_layer.h tiny_cnn/tiny_cnn.h tiny_cnn/weight_init.h)
ADD_EXECUTABLE(sample_train example/sample_train.cpp ${tiny_cnn_hrds})
ADD_EXECUTABLE(sample_test example/sample_test.cpp ${tiny_cnn_hrds})
ADD_EXECUTABLE(unitary_test test/test.cpp ${tiny_cnn_hrds})
# ----------------------------------------------------------------------------
# display status message for important variables
# ----------------------------------------------------------------------------
message( STATUS )
MESSAGE( STATUS "-------------------------------------------------------------------------------" )
message( STATUS "General configuration for ${PROJECT_NAME} ${PROJECT_VERSION}")
MESSAGE( STATUS "-------------------------------------------------------------------------------" )
message( STATUS "USE_TBB=${USE_TBB} USE_OMP=${USE_OMP} USE_SSE=${USE_SSE} USE_AVX=${USE_AVX}")
MESSAGE( STATUS "-------------------------------------------------------------------------------" )
message( STATUS )
message(" Built as dynamic libs?:" ${BUILD_SHARED_LIBS})
message(" Compiler:" "${CMAKE_COMPILER}" "${CMAKE_CXX_COMPILER}")
message( STATUS "C++ flags (Release): ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
message( STATUS "C++ flags (Debug): ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
message( STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message( STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
MESSAGE( STATUS )
MESSAGE( STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}" )
MESSAGE( STATUS "REQUIRED_LIBRARIES = ${REQUIRED_LIBRARIES}" )
MESSAGE( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" )
MESSAGE( STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}" )
MESSAGE( STATUS "CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}" )
MESSAGE( STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}")
MESSAGE( STATUS )
MESSAGE( STATUS )
MESSAGE( STATUS "Change a value with: cmake -D<Variable>=<Value>" )
MESSAGE( STATUS )