Added option BUILD_PYTHON

This commit is contained in:
Yangqing Jia
2017-01-04 16:40:26 -08:00
parent 3d1bda1f3a
commit 347e17600f
3 changed files with 68 additions and 49 deletions

View File

@ -33,6 +33,7 @@ include(ExternalProject)
include(cmake/Utils.cmake)
# options
option(USE_THREADS "Use Threads" ON)
option(USE_NERVANA_GPU "Use Nervana GPU backend" OFF)
option(USE_GLOG "Use GLOG" ON)
option(USE_GFLAGS "Use GFLAGS" ON)
@ -45,6 +46,7 @@ option(USE_MPI "Use MPI" ON)
option(BUILD_SHARED_LIBS "Build libcaffe2.so" ON)
option(USE_SYSTEM_PROTOBUF "Use system-provided protobuf" ON)
option(USE_OPENMP "Use OpenMP for parallel code" ON)
option(BUILD_PYTHON "Build python binaries" ON)
# options that do not affect the main binaries, but affects testing binaries
option(BUILD_TEST "Build C++ test binaries (need gtest and gbenchmark)" ON)
@ -79,33 +81,33 @@ add_subdirectory(caffe/proto)
add_subdirectory(caffe2)
# ---[ Copy all python files to build directory
# ---[ Generate and create all needed __init__.py files as they aren't present in source tree
set(Caffe2_INIT_PY
${CMAKE_BINARY_DIR}/caffe2/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/static/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/static/css/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/templates/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/__init__.py
${CMAKE_BINARY_DIR}/caffe2/proto/__init__.py
${CMAKE_BINARY_DIR}/caffe/__init__.py
${CMAKE_BINARY_DIR}/caffe/proto/__init__.py
)
foreach(init ${Caffe2_INIT_PY})
# create each __init__.py file in build directory
file(WRITE ${init} "")
endforeach()
# Copy the files
message(STATUS ${CMAKE_BINARY_DIR})
# Pick up static python files
install(DIRECTORY ${CMAKE_SOURCE_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")
# Caffe proto files
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")
# Caffe2 proto files
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")
if (BUILD_PYTHON)
# ---[ Generate and create all needed __init__.py files as they aren't present in source tree
set(Caffe2_INIT_PY
${CMAKE_BINARY_DIR}/caffe2/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/static/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/static/css/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/templates/__init__.py
${CMAKE_BINARY_DIR}/caffe2/python/mint/__init__.py
${CMAKE_BINARY_DIR}/caffe2/proto/__init__.py
${CMAKE_BINARY_DIR}/caffe/__init__.py
${CMAKE_BINARY_DIR}/caffe/proto/__init__.py
)
foreach(init ${Caffe2_INIT_PY})
# create each __init__.py file in build directory
file(WRITE ${init} "")
endforeach()
# Copy the files
message(STATUS ${CMAKE_BINARY_DIR})
# Pick up static python files
install(DIRECTORY ${CMAKE_SOURCE_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")
# Caffe proto files
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")
# Caffe2 proto files
install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe2 DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.py")
endif()

View File

@ -34,16 +34,27 @@ add_subdirectory(sgd)
add_subdirectory(utils)
# Debug messages - after cmake is fully tested we should remove these prints.
message(STATUS "After core, cpu sources: ")
message(STATUS "CPU sources: ")
foreach(tmp ${Caffe2_CPU_SRCS})
message(STATUS " " ${tmp})
endforeach()
message(STATUS "After core, gpu sources: ")
message(STATUS "GPU sources: ")
foreach(tmp ${Caffe2_GPU_SRCS})
message(STATUS " " ${tmp})
endforeach()
message(STATUS "CPU test sources: ")
foreach(tmp ${Caffe2_CPU_TEST_SRCS})
message(STATUS " " ${tmp})
endforeach()
message(STATUS "GPU test sources: ")
foreach(tmp ${Caffe2_GPU_TEST_SRCS})
message(STATUS " " ${tmp})
endforeach()
# ---[ List of libraries to link with
set(Caffe2_MAIN_LIBS Caffe_PROTO)
@ -94,17 +105,19 @@ if (BUILD_TEST)
endif()
endif()
# ---[ Python.
add_library(caffe2_pybind11_state SHARED ${Caffe2_CPU_PYTHON_SRCS})
set_target_properties(caffe2_pybind11_state PROPERTIES PREFIX "")
target_link_libraries(caffe2_pybind11_state ${Caffe2_MAIN_LIBS} ${Caffe2_DEPENDENCY_LIBS} ${Caffe2_PYTHON_DEPENDENCY_LIBS})
install(TARGETS caffe2_pybind11_state DESTINATION ${CMAKE_INSTALL_PREFIX}/caffe2/python)
if (BUILD_PYTHON)
# ---[ Python.
add_library(caffe2_pybind11_state SHARED ${Caffe2_CPU_PYTHON_SRCS})
set_target_properties(caffe2_pybind11_state PROPERTIES PREFIX "")
target_link_libraries(caffe2_pybind11_state ${Caffe2_MAIN_LIBS} ${Caffe2_DEPENDENCY_LIBS} ${Caffe2_PYTHON_DEPENDENCY_LIBS})
install(TARGETS caffe2_pybind11_state DESTINATION ${CMAKE_INSTALL_PREFIX}/caffe2/python)
if(HAVE_CUDA)
add_library(caffe2_pybind11_state_gpu SHARED ${Caffe2_GPU_PYTHON_SRCS})
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES PREFIX "")
target_link_libraries(caffe2_pybind11_state_gpu ${Caffe2_MAIN_LIBS} ${Caffe2_DEPENDENCY_LIBS} ${Caffe2_PYTHON_DEPENDENCY_LIBS})
install(TARGETS caffe2_pybind11_state_gpu DESTINATION ${CMAKE_INSTALL_PREFIX}/caffe2/python)
if(HAVE_CUDA)
add_library(caffe2_pybind11_state_gpu SHARED ${Caffe2_GPU_PYTHON_SRCS})
set_target_properties(caffe2_pybind11_state_gpu PROPERTIES PREFIX "")
target_link_libraries(caffe2_pybind11_state_gpu ${Caffe2_MAIN_LIBS} ${Caffe2_DEPENDENCY_LIBS} ${Caffe2_PYTHON_DEPENDENCY_LIBS})
install(TARGETS caffe2_pybind11_state_gpu DESTINATION ${CMAKE_INSTALL_PREFIX}/caffe2/python)
endif()
endif()
# ---[ Binaries.

View File

@ -6,8 +6,10 @@ set(Caffe2_PYTHON_DEPENDENCY_LIBS "")
include("cmake/ProtoBuf.cmake")
# ---[ Threads
find_package(Threads REQUIRED)
list(APPEND Caffe2_DEPENDENCY_LIBS ${CMAKE_THREAD_LIBS_INIT})
if (USE_THREADS)
find_package(Threads REQUIRED)
list(APPEND Caffe2_DEPENDENCY_LIBS ${CMAKE_THREAD_LIBS_INIT})
endif()
# ---[ BLAS
set(BLAS "Eigen" CACHE STRING "Selected BLAS library")
@ -109,12 +111,14 @@ endif()
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third_party/eigen)
# ---[ Python + Numpy
find_package(PythonInterp 2.7)
find_package(PythonLibs 2.7)
find_package(NumPy REQUIRED)
if (BUILD_PYTHON)
find_package(PythonInterp 2.7)
find_package(PythonLibs 2.7)
find_package(NumPy REQUIRED)
include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR})
list(APPEND Caffe2_PYTHON_DEPENDENCY_LIBS ${PYTHON_LIBRARIES})
include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR})
list(APPEND Caffe2_PYTHON_DEPENDENCY_LIBS ${PYTHON_LIBRARIES})
endif()
# ---[ pybind11
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third_party/pybind11/include)