Skip to content

Commit

Permalink
cmake: relative paths for install()
Browse files Browse the repository at this point in the history
Summary:
I discovered this while investigating more build-caching issues like facebookarchive/caffe2#1103.

> If a relative path is given it is interpreted relative to the value of the CMAKE_INSTALL_PREFIX variable.
https://cmake.org/cmake/help/v3.0/command/install.html

This is a non-functional change - it just makes the code a bit easier to read. I verified locally that the resulting install directories are identical.
Closes facebookarchive/caffe2#1111

Differential Revision: D5677328

Pulled By: Yangqing

fbshipit-source-id: 9bb1bfe85fc0bc54a9b7ce33cc31e45ea061d21e
  • Loading branch information
lukeyeager authored and facebook-github-bot committed Aug 22, 2017
1 parent 440d979 commit e902620
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion caffe/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ file(GLOB Caffe_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
caffe2_protobuf_generate_cpp_py(Caffe_PROTO_SRCS Caffe_PROTO_HEADERS Caffe_PROTO_PY ${Caffe_PROTOBUF_FILES})

add_library(Caffe_PROTO OBJECT ${Caffe_PROTO_HEADERS} ${Caffe_PROTO_SRCS})
install(FILES ${Caffe_PROTO_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/caffe/proto)
install(FILES ${Caffe_PROTO_HEADERS} DESTINATION include/caffe/proto)
24 changes: 10 additions & 14 deletions caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ set(Caffe2_MAIN_LIBS_ORDER ${Caffe2_MAIN_LIBS})
# Compile exposed libraries.
add_library(Caffe2_CPU ${Caffe2_CPU_SRCS} $<TARGET_OBJECTS:Caffe_PROTO> $<TARGET_OBJECTS:Caffe2_PROTO>)
target_link_libraries(Caffe2_CPU ${Caffe2_DEPENDENCY_LIBS})
install(TARGETS Caffe2_CPU DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS Caffe2_CPU DESTINATION lib)
list(APPEND Caffe2_MAIN_LIBS_ORDER Caffe2_CPU)
if (BUILD_SHARED_LIBS)
list(APPEND Caffe2_MAIN_LIBS Caffe2_CPU)
Expand Down Expand Up @@ -108,10 +108,10 @@ endforeach()

# Installing the header files
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/
DESTINATION include
FILES_MATCHING PATTERN "*.h")
install(FILES ${PROJECT_BINARY_DIR}/caffe2/core/macros.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/caffe2/core/)
DESTINATION include/caffe2/core)

# ---[ CUDA library.
if(USE_CUDA)
Expand All @@ -128,7 +128,7 @@ if(USE_CUDA)
if (Caffe2_EXTERNAL_DEPENDENCIES)
add_dependencies(Caffe2_GPU ${Caffe2_EXTERNAL_DEPENDENCIES})
endif()
install(TARGETS Caffe2_GPU DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS Caffe2_GPU DESTINATION lib)
link_directories(${CMAKE_INSTALL_PREFIX}/lib)
add_dependencies(Caffe2_GPU Caffe2_PROTO)
endif()
Expand All @@ -149,7 +149,7 @@ if (BUILD_TEST)
target_compile_features(${test_name} PRIVATE cxx_range_for)
endif()
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
install(TARGETS ${test_name} DESTINATION ${CMAKE_INSTALL_PREFIX}/test)
install(TARGETS ${test_name} DESTINATION test)
endforeach()
endif()

Expand Down Expand Up @@ -181,9 +181,7 @@ if (BUILD_PYTHON)
COMMAND install_name_tool -add_rpath ${CMAKE_INSTALL_PREFIX}/lib
$<TARGET_FILE:caffe2_pybind11_state>)
endif()
install(
TARGETS caffe2_pybind11_state DESTINATION
${CMAKE_INSTALL_PREFIX}/caffe2/python)
install(TARGETS caffe2_pybind11_state DESTINATION caffe2/python)

if(USE_CUDA)
add_library(caffe2_pybind11_state_gpu MODULE ${Caffe2_GPU_PYTHON_SRCS})
Expand All @@ -206,9 +204,7 @@ if (BUILD_PYTHON)
COMMAND install_name_tool -add_rpath ${CMAKE_INSTALL_PREFIX}/lib
$<TARGET_FILE:caffe2_pybind11_state_gpu>)
endif()
install(
TARGETS caffe2_pybind11_state_gpu DESTINATION
${CMAKE_INSTALL_PREFIX}/caffe2/python)
install(TARGETS caffe2_pybind11_state_gpu DESTINATION caffe2/python)
endif()

if (MSVC AND CMAKE_GENERATOR MATCHES "Visual Studio")
Expand Down Expand Up @@ -267,13 +263,13 @@ if (BUILD_PYTHON)

# Install commands
# Pick up static python files
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION .
FILES_MATCHING PATTERN "*.py")
# Caffe proto files
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe DESTINATION ${CMAKE_INSTALL_PREFIX}
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe DESTINATION .
FILES_MATCHING PATTERN "*.py")
# Caffe2 proto files
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION .
FILES_MATCHING PATTERN "*.py")
endif()

Expand Down
2 changes: 1 addition & 1 deletion caffe2/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ file(GLOB Caffe2_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
caffe2_protobuf_generate_cpp_py(Caffe2_PROTO_SRCS Caffe2_PROTO_HEADERS Caffe2_PROTO_PY ${Caffe2_PROTOBUF_FILES})

add_library(Caffe2_PROTO OBJECT ${Caffe2_PROTO_HEADERS} ${Caffe2_PROTO_SRCS})
install(FILES ${Caffe2_PROTO_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/caffe2/proto)
install(FILES ${Caffe2_PROTO_HEADERS} DESTINATION include/caffe2/proto)
2 changes: 1 addition & 1 deletion cmake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,5 @@ function(caffe2_binary_target target_name_or_src)
add_executable(${__target} ${__srcs})
add_dependencies(${__target} ${Caffe2_MAIN_LIBS_ORDER})
target_link_libraries(${__target} ${Caffe2_MAIN_LIBS} ${Caffe2_DEPENDENCY_LIBS})
install(TARGETS ${__target} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS ${__target} DESTINATION bin)
endfunction()

0 comments on commit e902620

Please sign in to comment.