Skip to content

Commit

Permalink
Add guard to not add_subdirectory when the target exists
Browse files Browse the repository at this point in the history
  • Loading branch information
daquexian committed May 24, 2019
1 parent 52da80a commit 52ad7de
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
7 changes: 5 additions & 2 deletions cmake/glog.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
macro(configure_glog)
function(configure_glog)
if (TARGET glog::glog)
return()
endif()
message(STATUS "Configureing glog...")

set(TEMP_BUILD_TESTING ${BUILD_TESTING})
Expand All @@ -10,4 +13,4 @@ macro(configure_glog)

set(BUILD_TESTING ${TEMP_BUILD_TESTING} CACHE BOOL "" FORCE)
set(WITH_GFLAGS ${TEMP_WITH_GFLAGS} CACHE BOOL "" FORCE)
endmacro()
endfunction()
8 changes: 6 additions & 2 deletions cmake/onnx.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
macro(configure_onnx)
function(configure_onnx)
if (TARGET onnx)
return()
endif()

if (NOT ${DNN_SYSTEM_PROTOBUF})
include(${PROJECT_SOURCE_DIR}/cmake/protobuf.cmake)
configure_protobuf()
Expand Down Expand Up @@ -30,4 +34,4 @@ macro(configure_onnx)
# target_compile_definitions(onnx
# PUBLIC
# -DONNX_NAMESPACE=${DAQ_ONNX_NAMESPACE})
endmacro()
endfunction()
29 changes: 15 additions & 14 deletions cmake/protobuf.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
macro(configure_protobuf)
message(STATUS "Configuring protobuf...")
option(protobuf_BUILD_TESTS "" OFF)
option(protobuf_BUILD_EXAMPLES "" OFF)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
option(protobuf_BUILD_PROTOC_BINARIES "" OFF)
else()
option(protobuf_BUILD_PROTOC_BINARIES "" ON)
function(configure_protobuf)
if (NOT TARGET libprotobuf-lite)
message(STATUS "Configuring protobuf...")
option(protobuf_BUILD_TESTS "" OFF)
option(protobuf_BUILD_EXAMPLES "" OFF)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
option(protobuf_BUILD_PROTOC_BINARIES "" OFF)
else()
option(protobuf_BUILD_PROTOC_BINARIES "" ON)
endif()
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/protobuf/cmake)
if (protobuf_BUILD_PROTOC_BINARIES)
add_executable(protobuf::protoc ALIAS protoc)
endif()
endif()
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/protobuf/cmake)
if (protobuf_BUILD_PROTOC_BINARIES)
add_executable(protobuf::protoc ALIAS protoc)
endif()
add_library(protobuf::libprotobuf ALIAS libprotobuf)
add_library(protobuf::libprotobuf-lite ALIAS libprotobuf-lite)
endmacro()
endfunction()

0 comments on commit 52ad7de

Please sign in to comment.