CMakeLists.txt 9.28 KB
Newer Older
1
2
3
4
5
#
# This is a CMake makefile.  You can find the cmake utility and
# information about it at http://www.cmake.org
#

6
# setting this makes CMake allow normal looking if else statements
7
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
8

9
cmake_minimum_required(VERSION 2.4)
10
11

# Suppress cmake warnings about changes in new versions.
12
13
14
if(COMMAND cmake_policy) 
   cmake_policy(SET CMP0003 NEW) 
endif()
15

16
17
18
19

# make macros that can add #define directives to the entire project.  Not just 
# to the dlib library itself.  I.e. to dlib and to any projects that depend
# on dlib.
20
macro ( add_global_define def_name )
21
22
23
24
25
   if (NOT CMAKE_CXX_FLAGS MATCHES "-D${def_name}")
      set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${def_name}" 
         CACHE STRING "Flags used by the compiler during all C++ builds." 
         FORCE)
   endif ()
26
27
endmacro()
macro ( remove_global_define def_name )
28
29
30
31
32
33
   if (CMAKE_CXX_FLAGS MATCHES " -D${def_name}")
      string (REGEX REPLACE " -D${def_name}" "" temp_var ${CMAKE_CXX_FLAGS}) 
      set (CMAKE_CXX_FLAGS "${temp_var}" 
         CACHE STRING "Flags used by the compiler during all C++ builds." 
         FORCE)
   endif ()
34
endmacro()
35
36
37
38
39
40
41
42
43
44
45
46
47


# Make sure ENABLE_ASSERTS is defined for debug builds
if (NOT CMAKE_CXX_FLAGS_DEBUG MATCHES "-DENABLE_ASSERTS")
   set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DENABLE_ASSERTS" 
      CACHE STRING "Flags used by the compiler during C++ debug builds." 
      FORCE)
endif ()

set (DLIB_ISO_CPP_ONLY_STR 
"Enable this if you don't want to compile any non-ISO C++ code (i.e. you don't use any of the API Wrappers)" )
set (DLIB_NO_GUI_SUPPORT_STR 
"Enable this if you don't want to compile any of the dlib GUI code" )
Davis King's avatar
Davis King committed
48
set (DLIB_ENABLE_STACK_TRACE_STR 
49
"Enable this if you want to turn on the DLIB_STACK_TRACE macros" )
Davis King's avatar
Davis King committed
50
set (DLIB_ENABLE_ASSERTS_STR 
51
"Enable this if you want to turn on the DLIB_ASSERT macro" )
52
53
set (DLIB_USE_BLAS_STR
"Disable this if you don't want to use a BLAS library" )
54
55
set (DLIB_USE_LAPACK_STR
"Disable this if you don't want to use a LAPACK library" )
56
57
set (DLIB_LINK_WITH_LIBPNG_STR
"Disable this if you don't want to link against libpng" )
58
59
set (DLIB_LINK_WITH_LIBJPEG_STR
"Disable this if you don't want to link against libjpeg" )
60
61
set (DLIB_LINK_WITH_SQLITE3_STR
"Disable this if you don't want to link against sqlite3" )
62

63
64
65
66
option(DLIB_ISO_CPP_ONLY ${DLIB_ISO_CPP_ONLY_STR} OFF)
option(DLIB_NO_GUI_SUPPORT ${DLIB_NO_GUI_SUPPORT_STR} OFF)
option(DLIB_ENABLE_STACK_TRACE ${DLIB_ENABLE_STACK_TRACE_STR} OFF)
option(DLIB_ENABLE_ASSERTS ${DLIB_ENABLE_ASSERTS_STR} OFF)
67
option(DLIB_USE_BLAS ${DLIB_USE_BLAS_STR} ON)
68
option(DLIB_USE_LAPACK ${DLIB_USE_LAPACK_STR} ON)
69
option(DLIB_LINK_WITH_LIBPNG ${DLIB_LINK_WITH_LIBPNG_STR} ON)
70
option(DLIB_LINK_WITH_LIBJPEG ${DLIB_LINK_WITH_LIBJPEG_STR} ON)
71
option(DLIB_LINK_WITH_SQLITE3 ${DLIB_LINK_WITH_SQLITE3_STR} ON)
72
73


Davis King's avatar
Davis King committed
74
add_library(dlib STATIC all/source.cpp )
75
76


77
if (NOT DLIB_ISO_CPP_ONLY)
78
   # we want to link to the right stuff depending on our platform.  
79
   if (WIN32 AND NOT CYGWIN) ###############################################################################
80
81
82
      if (DLIB_NO_GUI_SUPPORT)
         set (dlib_needed_libraries ws2_32)
      else()
83
         set (dlib_needed_libraries ws2_32 comctl32 gdi32 imm32)
84
      endif()
85
86
   elseif(APPLE) ############################################################################
      find_library(pthreadlib pthread)
87
88
89
      set (dlib_needed_libraries ${pthreadlib})

      if (NOT DLIB_NO_GUI_SUPPORT)
90
         find_library(xlib X11)
91
         # make sure X11 is in the include path
92
         find_path(xlib_path Xlib.h
93
94
95
96
97
            PATHS 
            /Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include
            PATH_SUFFIXES X11
            )
         if (xlib AND xlib_path)
98
99
            get_filename_component(x11_path ${xlib_path} PATH CACHE)
            include_directories(${x11_path})
100
101
102
103
104
105
106
107
108
109
            set(dlib_needed_libraries ${dlib_needed_libraries} ${xlib} )
         else()
            message(" ***********************************************************************************")
            message(" ****** DLIB GUI SUPPORT DISABLED BECAUSE X11 DEVELOPMENT LIBRARIES NOT FOUND ******")
            message(" ****** Make sure libx11-dev is installed if you want GUI support             ******")
            message(" ***********************************************************************************")
            set(DLIB_NO_GUI_SUPPORT ON CACHE STRING ${DLIB_NO_GUI_SUPPORT_STR} FORCE )
         endif()
      endif()

110
111
112
      mark_as_advanced(pthreadlib xlib xlib_path x11_path)
   else () ##################################################################################
      find_library(pthreadlib pthread)
113
114
115
      set (dlib_needed_libraries ${pthreadlib})

      # link to the nsl library if it exists.  this is something you need sometimes 
116
      find_library(nsllib nsl)
117
118
119
120
121
      if (nsllib)
         set (dlib_needed_libraries ${dlib_needed_libraries} ${nsllib})
      endif ()

      # link to the socket library if it exists.  this is something you need on solaris
122
      find_library(socketlib socket)
123
124
125
126
127
      if (socketlib)
         set (dlib_needed_libraries ${dlib_needed_libraries} ${socketlib})
      endif ()

      if (NOT DLIB_NO_GUI_SUPPORT)
128
         include(FindX11)
129
         if (X11_FOUND)
130
            include_directories(${X11_INCLUDE_DIR})
131
132
133
134
135
136
137
138
139
140
            set (dlib_needed_libraries ${dlib_needed_libraries} ${X11_LIBRARIES})
         else()
            message(" ***********************************************************************************")
            message(" ****** DLIB GUI SUPPORT DISABLED BECAUSE X11 DEVELOPMENT LIBRARIES NOT FOUND ******")
            message(" ****** Make sure libx11-dev is installed if you want GUI support             ******")
            message(" ***********************************************************************************")
            set(DLIB_NO_GUI_SUPPORT ON CACHE STRING ${DLIB_NO_GUI_SUPPORT_STR} FORCE )
         endif()
      endif()

141
      mark_as_advanced(nsllib pthreadlib socketlib)
Davis King's avatar
Davis King committed
142
   endif () ##################################################################################
143
144


145

146
147
148
149
150
151
   if (DLIB_LINK_WITH_LIBPNG)
      # try to find libpng 
      set(ZLIB_FIND_QUIETLY ON)
      set(PNG_FIND_QUIETLY ON)
      include(FindPNG)
      if (PNG_FOUND)
152
         include_directories(${PNG_INCLUDE_DIR})
153
154
155
156
         set (dlib_needed_libraries ${dlib_needed_libraries} ${PNG_LIBRARY})
      else()
         set(DLIB_LINK_WITH_LIBPNG OFF CACHE STRING ${DLIB_LINK_WITH_LIBPNG_STR} FORCE )
      endif()
157
158
   endif()

159
160
161
162
163
164
165
166
167
168
169
   if (DLIB_LINK_WITH_LIBJPEG)
      # try to find libjpeg 
      include(FindJPEG)
      if (JPEG_FOUND)
         include_directories(${JPEG_INCLUDE_DIR})
         set (dlib_needed_libraries ${dlib_needed_libraries} ${JPEG_LIBRARY})
      else()
         set(DLIB_LINK_WITH_LIBJPEG OFF CACHE STRING ${DLIB_LINK_WITH_LIBJPEG_STR} FORCE )
      endif()
   endif()

170

171
172
   if (DLIB_USE_BLAS OR DLIB_USE_LAPACK)
      # Try to find BLAS and LAPACK 
173
      include(cmake_find_blas.txt)
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

      if (DLIB_USE_BLAS)
         if (blas_found)
            set (dlib_needed_libraries ${dlib_needed_libraries} ${blas_libraries})
         else()
            set(DLIB_USE_BLAS OFF CACHE STRING ${DLIB_USE_BLAS_STR} FORCE )
         endif()
      endif()

      if (DLIB_USE_LAPACK)
         if (lapack_found)
            set (dlib_needed_libraries ${dlib_needed_libraries} ${lapack_libraries})
         else()
            set(DLIB_USE_LAPACK OFF CACHE STRING ${DLIB_USE_LAPACK_STR} FORCE )
         endif()
189
190
191
192
      endif()
   endif()


193

194
195
196
197
198
199
200
201
   if (DLIB_LINK_WITH_SQLITE3)
      find_library(sqlite sqlite3)
      # make sure sqlite3.h is in the include path
      find_path(sqlite_path sqlite3.h)
      if (sqlite AND sqlite_path)
         get_filename_component(sqlite_path2 ${sqlite_path} PATH CACHE)
         include_directories(${sqlite_path2})
         set(dlib_needed_libraries ${dlib_needed_libraries} ${sqlite} )
202
203
      else()
         set(DLIB_LINK_WITH_SQLITE3 OFF CACHE STRING ${DLIB_LINK_WITH_SQLITE3_STR} FORCE )
204
205
206
207
208
      endif()
      mark_as_advanced(sqlite sqlite_path sqlite_path2)
   endif()


209
   target_link_libraries(dlib ${dlib_needed_libraries} )
210

Davis King's avatar
Davis King committed
211
endif ()  ##### end of if NOT DLIB_ISO_CPP_ONLY ##########################################################
212
213
214


#test for some things that really should be true about the compiler
215
216
include(TestForSTDNamespace)
include(TestForANSIStreamHeaders)
217
218


219
if (DLIB_LINK_WITH_LIBPNG AND NOT DLIB_ISO_CPP_ONLY)
220
221
222
223
224
   add_global_define(DLIB_PNG_SUPPORT)
else()
   remove_global_define(DLIB_PNG_SUPPORT)
endif()

225
if (DLIB_LINK_WITH_LIBJPEG AND NOT DLIB_ISO_CPP_ONLY)
226
227
228
229
230
   add_global_define(DLIB_JPEG_SUPPORT)
else()
   remove_global_define(DLIB_JPEG_SUPPORT)
endif()

231

232
233
234
235
236
237
if (DLIB_USE_BLAS AND blas_found)
   add_global_define(DLIB_USE_BLAS)
else()
   remove_global_define(DLIB_USE_BLAS)
endif()

238
239
240
241
242
243
if (DLIB_USE_LAPACK AND lapack_found)
   add_global_define(DLIB_USE_LAPACK)
else()
   remove_global_define(DLIB_USE_LAPACK)
endif()

244

245
246
247
248
249
250
251
252
253
254
255
256
if (DLIB_ISO_CPP_ONLY)
   add_global_define(DLIB_ISO_CPP_ONLY)
else()
   remove_global_define(DLIB_ISO_CPP_ONLY)
endif()


if (DLIB_NO_GUI_SUPPORT)
   add_global_define(DLIB_NO_GUI_SUPPORT)
else()
   remove_global_define(DLIB_NO_GUI_SUPPORT)
endif()
257
258
259
260
261
262

if (DLIB_ENABLE_STACK_TRACE)
   add_global_define(DLIB_ENABLE_STACK_TRACE)
else()
   remove_global_define(DLIB_ENABLE_STACK_TRACE)
endif()
263
264
265


if (DLIB_ENABLE_ASSERTS)
266
   add_global_define(ENABLE_ASSERTS)
267
else()
268
   remove_global_define(ENABLE_ASSERTS)
269
270
endif()