Commit 8f2f5cf9 authored by Yangqing Jia's avatar Yangqing Jia Committed by Facebook Github Bot

Use new style caffe2 targets

Summary:
This basically allows Detectron to be built without having to include the many cmake files from Caffe2. Caffe2 now properly exports utility functions and dependent libraries, and so one can use the new style targets "caffe2_library" and "caffe2_gpu_library" directly.

This should also solve problems like #251 after we update the conda version. cc pjh5.
Closes https://github.com/facebookresearch/Detectron/pull/286

Reviewed By: ir413

Differential Revision: D7397696

Pulled By: Yangqing

fbshipit-source-id: 7a47e0addedd4b3c88dd8e2e130afdad04706acc
parent 3c4c7f67
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
# Add CMake modules.
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
# Find the Caffe2 package.
# Caffe2 exports the required targets, so find_package should work for
# the standard Caffe2 installation. If you encounter problems with finding
# the Caffe2 package, make sure you have run `make install` when installing
# Caffe2 (`make install` populates your share/cmake/Caffe2).
find_package(Caffe2 REQUIRED)
if (${CAFFE2_VERSION} VERSION_LESS 0.8.2)
# Pre-0.8.2 caffe2 does not have proper interface libraries set up, so we
# will rely on the old path.
message(WARNING
"You are using an older version of Caffe2 (version " ${CAFFE2_VERSION}
"). Please consider moving to a newer version.")
include(cmake/legacy/legacymake.cmake)
return()
endif()
# Add compiler flags.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -fPIC -Wno-narrowing")
# Include Caffe2 CMake utils.
include(cmake/Utils.cmake)
# Find dependencies.
include(cmake/Dependencies.cmake)
# Print configuration summary.
include(cmake/Summary.cmake)
detectron_print_config_summary()
......@@ -26,14 +34,11 @@ add_library(
caffe2_detectron_custom_ops SHARED
${CUSTOM_OPS_CPU_SRCS})
target_include_directories(
caffe2_detectron_custom_ops PRIVATE
${CAFFE2_INCLUDE_DIRS})
target_link_libraries(caffe2_detectron_custom_ops caffe2)
target_link_libraries(caffe2_detectron_custom_ops caffe2_library)
install(TARGETS caffe2_detectron_custom_ops DESTINATION lib)
# Install custom GPU ops lib.
if (HAVE_CUDA)
# Install custom GPU ops lib, if gpu is present.
if (${HAVE_CUDA})
# Additional -I prefix is required for CMake versions before commit (< 3.7):
# https://github.com/Kitware/CMake/commit/7ded655f7ba82ea72a82d0555449f2df5ef38594
list(APPEND CUDA_INCLUDE_DIRS -I${CAFFE2_INCLUDE_DIRS})
......@@ -42,6 +47,6 @@ if (HAVE_CUDA)
${CUSTOM_OPS_CPU_SRCS}
${CUSTOM_OPS_GPU_SRCS})
target_link_libraries(caffe2_detectron_custom_ops_gpu caffe2_gpu)
target_link_libraries(caffe2_detectron_custom_ops_gpu caffe2_gpu_library)
install(TARGETS caffe2_detectron_custom_ops_gpu DESTINATION lib)
endif()
# Adapted from https://github.com/caffe2/caffe2/blob/master/cmake/Dependencies.cmake
# Find the Caffe2 package.
# Caffe2 exports the required targets, so find_package should work for
# the standard Caffe2 installation. If you encounter problems with finding
# the Caffe2 package, make sure you have run `make install` when installing
# Caffe2 (`make install` populates your share/cmake/Caffe2).
find_package(Caffe2 REQUIRED)
# Find CUDA.
include(cmake/Cuda.cmake)
if (HAVE_CUDA)
......
# This file contains legacy cmake scripts that is going to be removed
# in a future release.
# Add CMake modules.
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/legacy/Modules)
# Add compiler flags.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -fPIC -Wno-narrowing")
# Include Caffe2 CMake utils.
include(cmake/legacy/Utils.cmake)
# Find dependencies.
include(cmake/legacy/Dependencies.cmake)
# Print configuration summary.
include(cmake/Summary.cmake)
detectron_print_config_summary()
# Collect custom ops sources.
file(GLOB CUSTOM_OPS_CPU_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cc)
file(GLOB CUSTOM_OPS_GPU_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cu)
# Install custom CPU ops lib.
add_library(
caffe2_detectron_custom_ops SHARED
${CUSTOM_OPS_CPU_SRCS})
target_include_directories(
caffe2_detectron_custom_ops PRIVATE
${CAFFE2_INCLUDE_DIRS})
target_link_libraries(caffe2_detectron_custom_ops caffe2)
install(TARGETS caffe2_detectron_custom_ops DESTINATION lib)
# Install custom GPU ops lib.
if (HAVE_CUDA)
# Additional -I prefix is required for CMake versions before commit (< 3.7):
# https://github.com/Kitware/CMake/commit/7ded655f7ba82ea72a82d0555449f2df5ef38594
list(APPEND CUDA_INCLUDE_DIRS -I${CAFFE2_INCLUDE_DIRS})
CUDA_ADD_LIBRARY(
caffe2_detectron_custom_ops_gpu SHARED
${CUSTOM_OPS_CPU_SRCS}
${CUSTOM_OPS_GPU_SRCS})
target_link_libraries(caffe2_detectron_custom_ops_gpu caffe2_gpu)
install(TARGETS caffe2_detectron_custom_ops_gpu DESTINATION lib)
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