Skip to content

Commit

Permalink
Use target_compile_definitions instead of add_definitions when settin…
Browse files Browse the repository at this point in the history
…g ONNX_NAMESPACE (onnx#1318)

* Use target_compile_options instead of add_definitions

* Set compile flags about namespace for onnx_cpp2py_export

* Use target_compile_definitions instead of add_definitions for ONNX_ML

* Use target_compile_definitions instead of target_compile_options
  • Loading branch information
daquexian authored and bddppq committed Aug 25, 2018
1 parent b15a99e commit 9f5a706
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ else()
set(ONNX_NAMESPACE "onnx")
set(MY_ONNX_NAMESPACE "-DONNX_NAMESPACE=onnx")
endif()
add_definitions(${MY_ONNX_NAMESPACE})

if(ONNX_ML)
add_definitions("-DONNX_ML=1")
endif()

# function(RELATIVE_PROTOBUF_GENERATE_CPP SRCS HDRS ROOT_DIR) from https://githu
# b.com/tensorflow/tensorflow/blob/d2c3b873c6f8ff999a2e4ee707a84ff00d9c15a5/tens
Expand Down Expand Up @@ -276,11 +271,19 @@ if(TARGET protobuf::libprotobuf)
else()
target_link_libraries(onnx_proto PUBLIC ${PROTOBUF_LIBRARIES})
endif()
target_compile_definitions(onnx_proto PUBLIC ${MY_ONNX_NAMESPACE})

add_library(onnx ${onnx_src})
target_include_directories(onnx
PUBLIC ${ONNX_ROOT} "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(onnx PUBLIC onnx_proto)
# interface compile options of onnx_proto will also take effect here, but I think setting it explicitly is better.
target_compile_definitions(onnx PUBLIC ${MY_ONNX_NAMESPACE})

if(ONNX_ML)
target_compile_definitions(onnx_proto PUBLIC ONNX_ML=1)
target_compile_definitions(onnx PUBLIC ONNX_ML=1)
endif()

if(BUILD_ONNX_PYTHON)
if("${PY_EXT_SUFFIX}" STREQUAL "")
Expand All @@ -298,6 +301,8 @@ if(BUILD_ONNX_PYTHON)
set_target_properties(onnx_cpp2py_export PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
set_target_properties(onnx_cpp2py_export
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Setting compile flags about namespace explicitly
target_compile_definitions(onnx_cpp2py_export PUBLIC ${MY_ONNX_NAMESPACE})
target_include_directories(onnx_cpp2py_export
PRIVATE "${ONNX_ROOT}"
"${CMAKE_CURRENT_BINARY_DIR}"
Expand Down Expand Up @@ -372,6 +377,9 @@ if(BUILD_ONNX_PYTHON)
${EXTRA_FLAGS})
target_compile_options(onnx_cpp2py_export PRIVATE /MT)
endif()
if (ONNX_ML)
target_compile_definitions(onnx_cpp2py_export PUBLIC ONNX_ML=1)
endif()
endif()

if(ONNX_BUILD_BENCHMARKS)
Expand Down

0 comments on commit 9f5a706

Please sign in to comment.