Commit 8c9d6c12 authored by Davis King's avatar Davis King

Adding Steven Van Ingelgem's cmake patch to clean things up and add

shared builds.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402735
parent 818086a4
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# information about it at http://www.cmake.org # information about it at http://www.cmake.org
# #
# setting this makes CMake allow normal looking IF ELSE statements # setting this makes CMake allow normal looking if else statements
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
cmake_minimum_required(VERSION 2.4) cmake_minimum_required(VERSION 2.4)
if(COMMAND cmake_policy) if(COMMAND cmake_policy)
...@@ -14,21 +14,21 @@ endif() ...@@ -14,21 +14,21 @@ endif()
# make macros that can add #define directives to the entire project. Not just # 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 # to the dlib library itself. I.e. to dlib and to any projects that depend
# on dlib. # on dlib.
MACRO ( add_global_define def_name ) macro ( add_global_define def_name )
if (NOT CMAKE_CXX_FLAGS MATCHES "-D${def_name}") if (NOT CMAKE_CXX_FLAGS MATCHES "-D${def_name}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${def_name}" set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${def_name}"
CACHE STRING "Flags used by the compiler during all C++ builds." CACHE STRING "Flags used by the compiler during all C++ builds."
FORCE) FORCE)
endif () endif ()
ENDMACRO() endmacro()
MACRO ( remove_global_define def_name ) macro ( remove_global_define def_name )
if (CMAKE_CXX_FLAGS MATCHES " -D${def_name}") if (CMAKE_CXX_FLAGS MATCHES " -D${def_name}")
string (REGEX REPLACE " -D${def_name}" "" temp_var ${CMAKE_CXX_FLAGS}) string (REGEX REPLACE " -D${def_name}" "" temp_var ${CMAKE_CXX_FLAGS})
set (CMAKE_CXX_FLAGS "${temp_var}" set (CMAKE_CXX_FLAGS "${temp_var}"
CACHE STRING "Flags used by the compiler during all C++ builds." CACHE STRING "Flags used by the compiler during all C++ builds."
FORCE) FORCE)
endif () endif ()
ENDMACRO() endmacro()
# Make sure ENABLE_ASSERTS is defined for debug builds # Make sure ENABLE_ASSERTS is defined for debug builds
...@@ -46,39 +46,46 @@ set (DLIB_ENABLE_STACK_TRACE_STR ...@@ -46,39 +46,46 @@ set (DLIB_ENABLE_STACK_TRACE_STR
"Enable this if you want to turn on the DLIB_STACK_TRACE macros" ) "Enable this if you want to turn on the DLIB_STACK_TRACE macros" )
set (DLIB_ENABLE_ASSERTS_STR set (DLIB_ENABLE_ASSERTS_STR
"Enable this if you want to turn on the DLIB_ASSERT macro" ) "Enable this if you want to turn on the DLIB_ASSERT macro" )
set (DLIB_ENABLE_SHARED_BUILD_STR
"Enable this if you want to create a shared dlib library (.dll, .so)" )
OPTION(DLIB_ISO_CPP_ONLY ${DLIB_ISO_CPP_ONLY_STR} OFF) option(DLIB_ISO_CPP_ONLY ${DLIB_ISO_CPP_ONLY_STR} OFF)
OPTION(DLIB_NO_GUI_SUPPORT ${DLIB_NO_GUI_SUPPORT_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_STACK_TRACE ${DLIB_ENABLE_STACK_TRACE_STR} OFF)
OPTION(DLIB_ENABLE_ASSERTS ${DLIB_ENABLE_ASSERTS_STR} OFF) option(DLIB_ENABLE_ASSERTS ${DLIB_ENABLE_ASSERTS_STR} OFF)
option(DLIB_ENABLE_SHARED_BUILD ${DLIB_ENABLE_SHARED_BUILD_STR} OFF)
add_library(dlib all/source.cpp ) if (DLIB_ENABLE_SHARED_BUILD)
add_library(dlib SHARED all/source.cpp )
else ()
add_library(dlib STATIC all/source.cpp )
endif ()
IF (NOT DLIB_ISO_CPP_ONLY) if (NOT DLIB_ISO_CPP_ONLY)
# we want to link to the right stuff depending on our platform. # we want to link to the right stuff depending on our platform.
IF (WIN32 AND NOT CYGWIN) ############################################################################### if (WIN32 AND NOT CYGWIN) ###############################################################################
if (DLIB_NO_GUI_SUPPORT) if (DLIB_NO_GUI_SUPPORT)
set (dlib_needed_libraries ws2_32) set (dlib_needed_libraries ws2_32)
else() else()
set (dlib_needed_libraries ws2_32 comctl32 gdi32 imm32) set (dlib_needed_libraries ws2_32 comctl32 gdi32 imm32)
endif() endif()
ELSEIF(APPLE) ############################################################################ elseif(APPLE) ############################################################################
FIND_LIBRARY(pthreadlib pthread) find_library(pthreadlib pthread)
set (dlib_needed_libraries ${pthreadlib}) set (dlib_needed_libraries ${pthreadlib})
if (NOT DLIB_NO_GUI_SUPPORT) if (NOT DLIB_NO_GUI_SUPPORT)
FIND_LIBRARY(xlib X11) find_library(xlib X11)
# make sure X11 is in the include path # make sure X11 is in the include path
FIND_PATH(xlib_path Xlib.h find_path(xlib_path Xlib.h
PATHS PATHS
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include /Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include
PATH_SUFFIXES X11 PATH_SUFFIXES X11
) )
if (xlib AND xlib_path) if (xlib AND xlib_path)
GET_FILENAME_COMPONENT(x11_path ${xlib_path} PATH CACHE) get_filename_component(x11_path ${xlib_path} PATH CACHE)
INCLUDE_DIRECTORIES(${x11_path}) include_directories(${x11_path})
set(dlib_needed_libraries ${dlib_needed_libraries} ${xlib} ) set(dlib_needed_libraries ${dlib_needed_libraries} ${xlib} )
else() else()
message(" ***********************************************************************************") message(" ***********************************************************************************")
...@@ -89,27 +96,27 @@ IF (NOT DLIB_ISO_CPP_ONLY) ...@@ -89,27 +96,27 @@ IF (NOT DLIB_ISO_CPP_ONLY)
endif() endif()
endif() endif()
MARK_AS_ADVANCED(pthreadlib xlib xlib_path x11_path) mark_as_advanced(pthreadlib xlib xlib_path x11_path)
ELSE () ################################################################################## else () ##################################################################################
FIND_LIBRARY(pthreadlib pthread) find_library(pthreadlib pthread)
set (dlib_needed_libraries ${pthreadlib}) set (dlib_needed_libraries ${pthreadlib})
# link to the nsl library if it exists. this is something you need sometimes # link to the nsl library if it exists. this is something you need sometimes
FIND_LIBRARY(nsllib nsl) find_library(nsllib nsl)
if (nsllib) if (nsllib)
set (dlib_needed_libraries ${dlib_needed_libraries} ${nsllib}) set (dlib_needed_libraries ${dlib_needed_libraries} ${nsllib})
endif () endif ()
# link to the socket library if it exists. this is something you need on solaris # link to the socket library if it exists. this is something you need on solaris
FIND_LIBRARY(socketlib socket) find_library(socketlib socket)
if (socketlib) if (socketlib)
set (dlib_needed_libraries ${dlib_needed_libraries} ${socketlib}) set (dlib_needed_libraries ${dlib_needed_libraries} ${socketlib})
endif () endif ()
if (NOT DLIB_NO_GUI_SUPPORT) if (NOT DLIB_NO_GUI_SUPPORT)
INCLUDE(FindX11) include(FindX11)
if (X11_FOUND) if (X11_FOUND)
INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR}) include_directories(${X11_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${X11_LIBRARIES}) set (dlib_needed_libraries ${dlib_needed_libraries} ${X11_LIBRARIES})
else() else()
message(" ***********************************************************************************") message(" ***********************************************************************************")
...@@ -120,30 +127,30 @@ IF (NOT DLIB_ISO_CPP_ONLY) ...@@ -120,30 +127,30 @@ IF (NOT DLIB_ISO_CPP_ONLY)
endif() endif()
endif() endif()
MARK_AS_ADVANCED(nsllib pthreadlib socketlib) mark_as_advanced(nsllib pthreadlib socketlib)
ENDIF () ##### end of if NOT DLIB_ISO_CPP_ONLY ########################################################## endif () ##### end of if NOT DLIB_ISO_CPP_ONLY ##########################################################
# try to find libpng # try to find libpng
SET(ZLIB_FIND_QUIETLY ON) set(ZLIB_FIND_QUIETLY ON)
SET(PNG_FIND_QUIETLY ON) set(PNG_FIND_QUIETLY ON)
INCLUDE(FindPNG) include(FindPNG)
if (PNG_FOUND) if (PNG_FOUND)
INCLUDE_DIRECTORIES(${PNG_PNG_INCLUDE_DIR}) include_directories(${PNG_PNG_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${PNG_LIBRARY}) set (dlib_needed_libraries ${dlib_needed_libraries} ${PNG_LIBRARY})
add_global_define(DLIB_PNG_SUPPORT) add_global_define(DLIB_PNG_SUPPORT)
endif() endif()
TARGET_LINK_LIBRARIES(dlib ${dlib_needed_libraries} ) target_link_libraries(dlib ${dlib_needed_libraries} )
ENDIF () endif ()
#test for some things that really should be true about the compiler #test for some things that really should be true about the compiler
INCLUDE(TestForSTDNamespace) include(TestForSTDNamespace)
INCLUDE(TestForANSIStreamHeaders) include(TestForANSIStreamHeaders)
if (DLIB_ISO_CPP_ONLY) if (DLIB_ISO_CPP_ONLY)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment