-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added export config generation for build and install code trees
- Loading branch information
Anatoly Baksheev
committed
Jan 2, 2015
1 parent
f7d774e
commit 31fcb38
Showing
5 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
################################################################################################ | ||
# Helper function to fetch caffe includes which will be passed to dependent projects | ||
# Usage: | ||
# caffe_get_current_includes(<includes_list_variable>) | ||
function(caffe_get_current_includes includes_variable) | ||
get_property(current_includes DIRECTORY PROPERTY INCLUDE_DIRECTORIES) | ||
caffe_convert_absolute_paths(current_includes) | ||
|
||
# remove at most one ${CMAKE_BINARY_DIR} include added for caffe_config.h | ||
list(FIND current_includes ${CMAKE_BINARY_DIR} __index) | ||
list(REMOVE_AT current_includes ${__index}) | ||
|
||
caffe_list_unique(current_includes) | ||
set(${includes_variable} ${current_includes} PARENT_SCOPE) | ||
endfunction() | ||
|
||
################################################################################################ | ||
# Helper function to get all list items that begin with given prefix | ||
# Usage: | ||
# caffe_get_items_with_prefix(<prefix> <list_variable> <output_variable>) | ||
function(caffe_get_items_with_prefix prefix list_variable output_variable) | ||
set(__result "") | ||
foreach(__e ${${list_variable}}) | ||
if(__e MATCHES "^${prefix}.*") | ||
list(APPEND __result ${__e}) | ||
endif() | ||
endforeach() | ||
set(${output_variable} ${__result} PARENT_SCOPE) | ||
endfunction() | ||
|
||
################################################################################################ | ||
# Function for generation Caffe build- and install- tree export config files | ||
# Usage: | ||
# caffe_generate_export_configs() | ||
function(caffe_generate_export_configs) | ||
set(install_cmake_suffix "share/caffe") | ||
|
||
# ---[ Configure build-tree CaffeConfig.cmake file ]--- | ||
caffe_get_current_includes(Caffe_INCLUDE_DIRS) | ||
if(NOT HAVE_CUDA) | ||
set(HAVE_CUDA FALSE) | ||
set(Caffe_DEFINITIONS -DCPU_ONLY) | ||
endif() | ||
if(NOT HAVE_CUDNN) | ||
set(HAVE_CUDNN FALSE) | ||
else() | ||
set(Caffe_DEFINITIONS -DUSE_CUDNN) | ||
endif() | ||
|
||
configure_file("cmake/Templates/CaffeConfig.cmake.in" "${CMAKE_BINARY_DIR}/CaffeConfig.cmake" @ONLY) | ||
|
||
# Add targets to the build-tree export set | ||
export(TARGETS caffe proto FILE "${CMAKE_BINARY_DIR}/CaffeTargets.cmake") | ||
export(PACKAGE Caffe) | ||
|
||
# ---[ Configure install-tree CaffeConfig.cmake file ]--- | ||
|
||
# remove source and build dir includes | ||
caffe_get_items_with_prefix(${CMAKE_SOURCE_DIR} Caffe_INCLUDE_DIRS __insource) | ||
caffe_get_items_with_prefix(${CMAKE_BINARY_DIR} Caffe_INCLUDE_DIRS __inbinary) | ||
list(REMOVE_ITEM Caffe_INCLUDE_DIRS ${__insource} ${__inbinary}) | ||
|
||
# add `install` include folder | ||
set(lines "") | ||
list(APPEND lines "get_filename_component(__caffe_include \"\${Caffe_CMAKE_DIR}/../../include\" ABSOLUTE)\n") | ||
list(APPEND lines "list(APPEND Caffe_INCLUDE_DIRS \${__caffe_include})\n") | ||
list(APPEND lines "unset(__caffe_include)\n") | ||
string(REPLACE ";" "" Caffe_INSTALL_INCLUDE_DIR_APPEND_COMMAND ${lines}) | ||
|
||
configure_file("cmake/Templates/CaffeConfig.cmake.in" "${CMAKE_BINARY_DIR}/cmake/CaffeConfig.cmake" @ONLY) | ||
|
||
# Install the CaffeConfig.cmake and export set to use wuth install-tree | ||
install(FILES "${CMAKE_BINARY_DIR}/cmake/CaffeConfig.cmake" DESTINATION ${install_cmake_suffix}) | ||
install(EXPORT CaffeTargets DESTINATION ${install_cmake_suffix}) | ||
|
||
# ---[ Configure and install version file ]--- | ||
|
||
# TODO: Lines below are commented because Caffe does't declare its version in headers. | ||
# When the declarations are added, modify `caffe_extract_caffe_version()` macro and uncomment | ||
|
||
# configure_file(cmake/Templates/CaffeConfigVersion.cmake.in "${CMAKE_BINARY_DIR}/CaffeConfigVersion.cmake" @ONLY) | ||
# install(FILES "${CMAKE_BINARY_DIR}/CaffeConfigVersion.cmake" DESTINATION ${install_cmake_suffix}) | ||
endfunction() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Config file for the Caffe package. | ||
# | ||
# Note: | ||
# Caffe and this config file depends on opencv, | ||
# so put `find_package(OpenCV)` before searching Caffe | ||
# via `find_package(Caffe)`. All other lib/includes | ||
# dependencies are hard coded int the file | ||
# | ||
# After successful configuration the following variables | ||
# will be defined: | ||
# | ||
# Caffe_INCLUDE_DIRS - Caffe include directories | ||
# Caffe_LIBRARIES - libraries to link against | ||
# Caffe_DEFINITIONS - a list of definitions to pass to compiler | ||
# | ||
# Caffe_HAVE_CUDA - signals about CUDA support | ||
# Caffe_HAVE_CUDNN - signals about cuDNN support | ||
|
||
|
||
# OpenCV dependency | ||
|
||
if(NOT OpenCV_FOUND) | ||
set(Caffe_OpenCV_CONFIG_PATH "@OpenCV_CONFIG_PATH@") | ||
if(Caffe_OpenCV_CONFIG_PATH) | ||
get_filename_component(Caffe_OpenCV_CONFIG_PATH ${Caffe_OpenCV_CONFIG_PATH} ABSOLUTE) | ||
|
||
if(EXISTS ${Caffe_OpenCV_CONFIG_PATH} AND NOT TARGET opencv_core) | ||
message(STATUS "Caffe: using OpenCV config from ${Caffe_OpenCV_CONFIG_PATH}") | ||
include(${Caffe_OpenCV_CONFIG_PATH}/OpenCVModules.cmake) | ||
endif() | ||
|
||
else() | ||
find_package(OpenCV REQUIRED) | ||
endif() | ||
unset(Caffe_OpenCV_CONFIG_PATH) | ||
endif() | ||
|
||
# Compute paths | ||
get_filename_component(Caffe_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) | ||
set(Caffe_INCLUDE_DIRS "@Caffe_INCLUDE_DIRS@") | ||
|
||
@Caffe_INSTALL_INCLUDE_DIR_APPEND_COMMAND@ | ||
|
||
# Our library dependencies | ||
if(NOT TARGET caffe AND NOT caffe_BINARY_DIR) | ||
include("${Caffe_CMAKE_DIR}/CaffeTargets.cmake") | ||
endif() | ||
|
||
# List of IMPORTED libs created by CaffeTargets.cmake | ||
set(Caffe_LIBRARIES caffe) | ||
|
||
# Definitions | ||
set(Caffe_DEFINITIONS "@Caffe_DEFINITIONS@") | ||
|
||
# Cuda support variables | ||
set(Caffe_CPU_ONLY @CPU_ONLY@) | ||
set(Caffe_HAVE_CUDA @HAVE_CUDA@) | ||
set(Caffe_HAVE_CUDNN @HAVE_CUDNN@) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
set(PACKAGE_VERSION "@Caffe_VERSION@") | ||
|
||
# Check whether the requested PACKAGE_FIND_VERSION is compatible | ||
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") | ||
set(PACKAGE_VERSION_COMPATIBLE FALSE) | ||
else() | ||
set(PACKAGE_VERSION_COMPATIBLE TRUE) | ||
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") | ||
set(PACKAGE_VERSION_EXACT TRUE) | ||
endif() | ||
endif() |