Commit b527635e authored by Davis E. King's avatar Davis E. King

Merge pull request #35 from severin-lemaignan/installation

Adding an install target to dlib's CMakeLists
parents f5d8e1b6 c67cafe2
......@@ -8,6 +8,16 @@ SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
cmake_minimum_required(VERSION 2.4)
# default to a Release build (except if CMAKE_BUILD_TYPE is set)
include(release_build_by_default)
project(dlib)
set(CPACK_PACKAGE_VERSION_MAJOR "18")
set(CPACK_PACKAGE_VERSION_MINOR "17")
set(CPACK_PACKAGE_VERSION_PATCH "99")
set(VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
# Suppress cmake warnings about changes in new versions.
if(COMMAND cmake_policy)
......@@ -45,7 +55,6 @@ if (NOT CMAKE_CXX_FLAGS_DEBUG MATCHES "-DENABLE_ASSERTS")
FORCE)
endif ()
# Don't try to call add_library(dlib) and setup dlib's stuff if it has already
# been done by some other part of the current cmake project. We do this
# because it avoids getting warnings/errors about cmake policy CMP0002. This
......@@ -66,24 +75,33 @@ if (NOT TARGET dlib)
"Disable this if you don't want to use a BLAS library" )
set (DLIB_USE_LAPACK_STR
"Disable this if you don't want to use a LAPACK library" )
set (DLIB_LINK_WITH_LIBPNG_STR
set (DLIB_PNG_SUPPORT_STR
"Disable this if you don't want to link against libpng" )
set (DLIB_LINK_WITH_LIBJPEG_STR
set (DLIB_JPEG_SUPPORT_STR
"Disable this if you don't want to link against libjpeg" )
set (DLIB_LINK_WITH_SQLITE3_STR
"Disable this if you don't want to link against sqlite3" )
#set (DLIB_LINK_WITH_FFTW_STR "Disable this if you don't want to link against fftw" )
#set (DLIB_USE_FFTW_STR "Disable this if you don't want to link against fftw" )
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)
if(DLIB_ENABLE_ASSERTS)
set (DLIB_DISABLE_ASSERTS false)
set (ENABLE_ASSERTS true) # we need the CMake variable to properly configure config.h.in
else()
set (DLIB_DISABLE_ASSERTS true)
endif()
option(DLIB_USE_BLAS ${DLIB_USE_BLAS_STR} ON)
option(DLIB_USE_LAPACK ${DLIB_USE_LAPACK_STR} ON)
option(DLIB_LINK_WITH_LIBPNG ${DLIB_LINK_WITH_LIBPNG_STR} ON)
option(DLIB_LINK_WITH_LIBJPEG ${DLIB_LINK_WITH_LIBJPEG_STR} ON)
option(DLIB_PNG_SUPPORT ${DLIB_PNG_SUPPORT_STR} ON)
option(DLIB_JPEG_SUPPORT ${DLIB_JPEG_SUPPORT_STR} ON)
option(DLIB_LINK_WITH_SQLITE3 ${DLIB_LINK_WITH_SQLITE3_STR} ON)
#option(DLIB_LINK_WITH_FFTW ${DLIB_LINK_WITH_FFTW_STR} ON)
#option(DLIB_USE_FFTW ${DLIB_USE_FFTW_STR} ON)
set(source_files
base64/base64_kernel_1.cpp
......@@ -100,7 +118,10 @@ if (NOT TARGET dlib)
data_io/image_dataset_metadata.cpp)
if (DLIB_ISO_CPP_ONLY)
add_library(dlib STATIC ${source_files} )
add_library(dlib STATIC ${source_files} )
if (UNIX AND NOT DLIB_IN_PROJECT_BUILD)
add_library(dlib-shared SHARED ${source_files} )
endif()
else()
set(source_files ${source_files}
......@@ -218,7 +239,7 @@ if (NOT TARGET dlib)
INCLUDE (CheckFunctionExists)
if (DLIB_LINK_WITH_LIBPNG)
if (DLIB_PNG_SUPPORT)
# try to find libpng
find_package(PNG QUIET)
# Make sure there isn't something wrong with the version of LIBPNG
......@@ -272,7 +293,7 @@ if (NOT TARGET dlib)
)
endif()
if (DLIB_LINK_WITH_LIBJPEG)
if (DLIB_JPEG_SUPPORT)
# try to find libjpeg
find_package(JPEG QUIET)
# Make sure there isn't something wrong with the version of libjpeg
......@@ -381,7 +402,7 @@ if (NOT TARGET dlib)
if (DLIB_LINK_WITH_FFTW)
if (DLIB_USE_FFTW)
find_library(fftw fftw3)
# make sure fftw3.h is in the include path
find_path(fftw_path fftw3.h)
......@@ -389,36 +410,96 @@ if (NOT TARGET dlib)
include_directories(${fftw_path})
set(dlib_needed_libraries ${dlib_needed_libraries} ${fftw} )
else()
set(DLIB_LINK_WITH_FFTW OFF CACHE STRING ${DLIB_LINK_WITH_SQLITE3_STR} FORCE )
set(DLIB_USE_FFTW OFF CACHE STRING ${DLIB_LINK_WITH_SQLITE3_STR} FORCE )
endif()
mark_as_advanced(fftw fftw_path)
endif()
add_library(dlib STATIC ${source_files} )
target_link_libraries(dlib ${dlib_needed_libraries} )
if (UNIX AND NOT DLIB_IN_PROJECT_BUILD)
add_library(dlib-shared SHARED ${source_files} )
target_link_libraries(dlib-shared ${dlib_needed_libraries} )
endif()
endif () ##### end of if NOT DLIB_ISO_CPP_ONLY ##########################################################
# Install the library
if (NOT DLIB_IN_PROJECT_BUILD)
if(UNIX)
set_target_properties(dlib-shared PROPERTIES
OUTPUT_NAME dlib
VERSION ${VERSION})
install(TARGETS dlib dlib-shared
EXPORT dlib
RUNTIME DESTINATION bin # Windows (including cygwin) considers .dll to be runtime artifacts
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
else()
install(TARGETS dlib
EXPORT dlib
RUNTIME DESTINATION bin # Windows considers .dll to be runtime artifacts
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()
install(DIRECTORY ${CMAKE_SOURCE_DIR}/ DESTINATION include/dlib
FILES_MATCHING PATTERN "*.h"
REGEX "${CMAKE_CURRENT_BINARY_DIR}" EXCLUDE)
configure_file(${CMAKE_SOURCE_DIR}/../dlib/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
# overwrite config.h with the configured one
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h DESTINATION include/dlib)
configure_file(${CMAKE_SOURCE_DIR}/../dlib/revision.h.in ${CMAKE_CURRENT_BINARY_DIR}/revision.h)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/revision.h DESTINATION include/dlib)
install(FILES "LICENSE.txt" DESTINATION share/doc/dlib)
## Config.cmake generation and installation
set(ConfigPackageLocation lib/cmake/dlib)
install(EXPORT dlib
NAMESPACE dlib::
DESTINATION ${ConfigPackageLocation})
set(CONF_INSTALL_PATH "\${dlib_CMAKE_DIR}/../../../")
configure_file(dlibConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/config/dlibConfig.cmake" @ONLY)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/config/dlibConfigVersion.cmake"
VERSION ${VERSION}
COMPATIBILITY AnyNewerVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/config/dlibConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/config/dlibConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation})
endif()
#test for some things that really should be true about the compiler
include(TestForSTDNamespace)
include(TestForANSIStreamHeaders)
if (DLIB_LINK_WITH_LIBPNG AND NOT DLIB_ISO_CPP_ONLY)
if (DLIB_PNG_SUPPORT AND NOT DLIB_ISO_CPP_ONLY)
add_global_define(DLIB_PNG_SUPPORT)
else()
remove_global_define(DLIB_PNG_SUPPORT)
endif()
if (DLIB_LINK_WITH_LIBJPEG AND NOT DLIB_ISO_CPP_ONLY)
if (DLIB_JPEG_SUPPORT AND NOT DLIB_ISO_CPP_ONLY)
add_global_define(DLIB_JPEG_SUPPORT)
else()
remove_global_define(DLIB_JPEG_SUPPORT)
endif()
if (DLIB_LINK_WITH_FFTW AND NOT DLIB_ISO_CPP_ONLY)
if (DLIB_USE_FFTW AND NOT DLIB_ISO_CPP_ONLY)
add_global_define(DLIB_USE_FFTW)
else()
remove_global_define(DLIB_USE_FFTW)
......
# This is a CMake file meant to be included via include()
# It will trigger a compilation of dlib *in the project*
# including it
set(DLIB_IN_PROJECT_BUILD true)
cmake_minimum_required(VERSION 2.6.4)
......
// If you are compiling dlib as a shared library and installing it somewhere on your system
// then it is important that any programs that use dlib agree on the state of the
// DLIB_ASSERT statements (i.e. they are either always on or always off). Therefore,
// uncomment one of the following lines to force all DLIB_ASSERTs to either always on or
// always off. If you don't define one of these two macros then DLIB_ASSERT will toggle
// automatically depending on the state of certain other macros, which is not what you want
// when creating a shared library.
#cmakedefine ENABLE_ASSERTS // asserts always enabled
#cmakedefine DLIB_DISABLE_ASSERTS // asserts always disabled
#cmakedefine DLIB_ISO_CPP_ONLY
#cmakedefine DLIB_NO_GUI_SUPPORT
#cmakedefine DLIB_ENABLE_STACK_TRACE
// You should also consider telling dlib to link against libjpeg, libpng, fftw, and a BLAS
// and LAPACK library. To do this you need to uncomment the following #defines.
#cmakedefine DLIB_JPEG_SUPPORT
#cmakedefine DLIB_PNG_SUPPORT
#cmakedefine DLIB_USE_FFTW
#cmakedefine DLIB_USE_BLAS
#cmakedefine DLIB_USE_LAPACK
# ===================================================================================
# The dlib CMake configuration file
#
# ** File generated automatically, do not modify **
#
# Usage from an external project:
# In your CMakeLists.txt, add these lines:
#
# FIND_PACKAGE(dlib REQUIRED)
# TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${dlib_LIBRARIES})
#
# This file will define the following variables:
# - dlib_LIBRARIES : The list of all imported targets for dlib modules.
# - dlib_INCLUDE_DIRS : The dlib include directories.
# - dlib_VERSION : The version of this dlib build.
# - dlib_VERSION_MAJOR : Major version part of this dlib revision.
# - dlib_VERSION_MINOR : Minor version part of this dlib revision.
#
# ===================================================================================
# Compute paths
get_filename_component(dlib_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 2.8)
get_filename_component(dlib_INSTALL_PATH "@CONF_INSTALL_PATH@" ABSOLUTE)
else()
get_filename_component(dlib_INSTALL_PATH "@CONF_INSTALL_PATH@" REALPATH)
endif()
set(dlib_INCLUDE_DIRS "${dlib_INSTALL_PATH}/include")
# Our library dependencies (contains definitions for IMPORTED targets)
if(NOT TARGET dlib-shared AND NOT dlib_BINARY_DIR)
include("${dlib_CMAKE_DIR}/dlib.cmake")
endif()
find_library(dlib_LIBRARIES dlib HINTS ${dlib_INSTALL_PATH}/lib)
set(dlib_LIBRARIES ${dlib_LIBRARIES} "@dlib_needed_libraries@")
#ifndef DLIB_REVISION_H
#define DLIB_MAJOR_VERSION @CPACK_PACKAGE_VERSION_MAJOR@
#define DLIB_MINOR_VERSION @CPACK_PACKAGE_VERSION_MINOR@
#define DLIB_PATCH_VERSION @CPACK_PACKAGE_VERSION_PATCH@
#endif
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