提交 9244cdeb 编写于 作者: J jinhui yuan

re-org cmake files

上级 42cf3049
build
build_oneflow
build_third_party
third_party
......@@ -6,15 +6,26 @@ project(oneflow C CXX)
enable_testing()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (WIN32)
set(CMAKE_BUILD_TYPE Debug)
endif()
set(oneflow_src_dir ${PROJECT_SOURCE_DIR}/oneflow)
set(oneflow_cmake_dir ${PROJECT_SOURCE_DIR}/cmake)
if (WIN32)
else()
list(APPEND CUDA_NVCC_FLAGS "-std=c++11 -w")
endif()
# option
option(DOWNLOAD_THIRD_PARTY "Download and build all third party codes" OFF)
option(PREPARE_THIRD_PARTY "Whether include the third party codes in the solution" OFF)
set(THIRD_PARTY_DIR "${PROJECT_SOURCE_DIR}/third_party")
if (NOT EXISTS ${THIRD_PARTY_DIR})
message(FATAL_ERROR "Please set third party directory by: -DTHIRD_PARTY_DIR=/your/third_party/path")
endif()
# Different set for different platform
if (MSVC)
......@@ -76,9 +87,6 @@ RELATIVE_PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS
cuda_add_library(of_protoobj ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(of_protoobj ${oneflow_third_party_libs})
if (DOWNLOAD_THIRD_PARTY)
add_dependencies(of_protoobj ${oneflow_third_party_dependencies})
endif()
# cc obj lib
include_directories(${oneflow_src_dir})
......
del build_oneflow
mkdir build_oneflow
cd ./build_oneflow
cmake .. -A x64
msbuild /p:Configuration=Debug ALL_BUILD.vcxproj
cd ..
rm -rf build_oneflow
mkdir build_oneflow
cd ./build_oneflow
cmake ..
make -j
cd ..
del build_third_party
mkdir build_third_party
cd ./build_third_party
cmake ../cmake/third_party -A x64
msbuild /p:Configuration=Debug ALL_BUILD.vcxproj
cd ..
rm -rf build_third_party
mkdir build_third_party
cd ./build_third_party
cmake ../cmake/third_party
make -j
cd ..
set(THIRD_PARTY_DIR "${CMAKE_BINARY_DIR}/third_party"
CACHE PATH "Location where third party headers and libs will be put.")
mark_as_advanced(THIRD_PARTY_DIR)
if (NOT WIN32)
find_package(Threads)
endif()
......
......@@ -24,10 +24,13 @@ foreach(LIBRARY_NAME ${GFLAGS_LIBRARY_NAMES})
list(APPEND GFLAGS_BUILD_STATIC_LIBRARIES ${GFLAGS_BUILD_LIBRARY_DIR}/${LIBRARY_NAME})
endforeach()
if (PREPARE_THIRD_PARTY)
ExternalProject_Add(gflags
PREFIX gflags
GIT_REPOSITORY ${gflags_URL}
GIT_TAG ${gflags_TAG}
UPDATE_COMMAND ""
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
CMAKE_CACHE_ARGS
......@@ -51,3 +54,5 @@ add_custom_target(gflags_create_library_dir
add_custom_target(gflags_copy_libs_to_destination
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GFLAGS_BUILD_STATIC_LIBRARIES} ${GFLAGS_LIBRARY_DIR}
DEPENDS gflags_create_library_dir)
endif(PREPARE_THIRD_PARTY)
......@@ -31,10 +31,13 @@ set (GLOG_PUBLIC_H
${CMAKE_CURRENT_BINARY_DIR}/glog/src/glog/src/glog/log_severity.h
)
if(PREPARE_THIRD_PARTY)
ExternalProject_Add(glog
PREFIX glog
GIT_REPOSITORY ${glog_URL}
GIT_TAG ${glog_TAG}
UPDATE_COMMAND ""
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
CMAKE_CACHE_ARGS
......@@ -66,3 +69,5 @@ add_custom_target(glog_create_library_dir
add_custom_target(glog_copy_libs_to_destination
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GLOG_BUILD_STATIC_LIBRARIES} ${GLOG_LIBRARY_DIR}
DEPENDS glog_create_library_dir)
endif(PREPARE_THIRD_PARTY)
\ No newline at end of file
......@@ -23,10 +23,13 @@ foreach(LIBRARY_NAME ${GOOGLETEST_LIBRARY_NAMES})
list(APPEND GOOGLETEST_BUILD_STATIC_LIBRARIES ${GOOGLETEST_BUILD_LIBRARY_DIR}/${LIBRARY_NAME})
endforeach()
if(PREPARE_THIRD_PARTY)
ExternalProject_Add(googletest
PREFIX googletest
GIT_REPOSITORY ${googletest_URL}
GIT_TAG ${googletest_TAG}
UPDATE_COMMAND ""
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
CMAKE_CACHE_ARGS
......@@ -51,3 +54,5 @@ add_custom_target(googletest_create_library_dir
add_custom_target(googletest_copy_libs_to_destination
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GOOGLETEST_BUILD_STATIC_LIBRARIES} ${GOOGLETEST_LIBRARY_DIR}
DEPENDS googletest_create_library_dir)
endif(PREPARE_THIRD_PARTY)
\ No newline at end of file
......@@ -29,11 +29,14 @@ foreach(LIBRARY_NAME ${GRPC_LIBRARY_NAMES})
list(APPEND GRPC_BUILD_STATIC_LIBRARIES ${GRPC_BUILD_LIBRARY_DIR}/${LIBRARY_NAME})
endforeach()
if(PREPARE_THIRD_PARTY)
ExternalProject_Add(grpc
PREFIX grpc
DEPENDS protobuf zlib
GIT_REPOSITORY ${GRPC_URL}
GIT_TAG ${GRPC_TAG}
UPDATE_COMMAND ""
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
CMAKE_CACHE_ARGS
......@@ -63,3 +66,5 @@ add_custom_target(grpc_create_library_dir
add_custom_target(grpc_copy_libs_to_destination
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GRPC_BUILD_STATIC_LIBRARIES} ${GRPC_LIBRARY_DIR}
DEPENDS grpc_create_library_dir)
endif(PREPARE_THIRD_PARTY)
\ No newline at end of file
......@@ -31,11 +31,14 @@ endforeach()
set(PROTOBUF_BUILD_PROTOC_EXECUTABLE ${PROTOBUF_BUILD_LIBRARY_DIR}/${PROTOC_EXECUTABLE_NAME})
set(PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_BINARY_DIR}/${PROTOC_EXECUTABLE_NAME})
if (PREPARE_THIRD_PARTY)
ExternalProject_Add(protobuf
PREFIX protobuf
DEPENDS zlib
GIT_REPOSITORY ${PROTOBUF_URL}
GIT_TAG ${PROTOBUF_TAG}
UPDATE_COMMAND ""
BUILD_IN_SOURCE 1
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf/src/protobuf
CONFIGURE_COMMAND ${CMAKE_COMMAND} cmake/
......@@ -77,3 +80,5 @@ add_custom_target(protobuf_create_binary_dir
add_custom_target(protobuf_copy_binary_to_destination
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROTOBUF_BUILD_PROTOC_EXECUTABLE} ${PROTOBUF_BINARY_DIR}
DEPENDS protobuf_create_binary_dir)
endif(PREPARE_THIRD_PARTY)
\ No newline at end of file
......@@ -28,10 +28,13 @@ set(ZLIB_HEADERS
"${ZLIB_INSTALL}/include/zlib.h"
)
if(PREPARE_THIRD_PARTY)
ExternalProject_Add(zlib
PREFIX zlib
GIT_REPOSITORY ${ZLIB_URL}
GIT_TAG ${ZLIB_TAG}
UPDATE_COMMAND ""
INSTALL_DIR ${ZLIB_INSTALL}
BUILD_IN_SOURCE 1
CMAKE_CACHE_ARGS
......@@ -61,3 +64,5 @@ add_custom_target(zlib_create_library_dir
add_custom_target(zlib_copy_libs_to_destination
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ZLIB_BUILD_STATIC_LIBRARIES} ${ZLIB_LIBRARY_DIR}
DEPENDS zlib_create_library_dir)
endif(PREPARE_THIRD_PARTY)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册