Skip to content

Commit

Permalink
Using BUILD_SHARED_LIBS (defaulted to ON) instead of a custom CMake o…
Browse files Browse the repository at this point in the history
…ption NGRAPH_STATIC_LIBRARY
  • Loading branch information
emmanuelattia committed Oct 30, 2020
1 parent 7c4a3c5 commit 72837db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 4 additions & 0 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ ie_option (ENABLE_PROFILING_ITT "Build with ITT tracing. Optionally configure pr
ie_option (ENABLE_DOCS "build docs using Doxygen" OFF)

ie_dependent_option (ENABLE_FASTER_BUILD "Enable build features (PCH, UNITY) to speed up build time" OFF "CMAKE_VERSION VERSION_GREATER_EQUAL 3.16" OFF)

# Type of build, we add this as an explicit option to default it to ON
# FIXME: Ah this moment setting this to OFF will only build ngraph a static library
ie_option (BUILD_SHARED_LIBS, "Build as a shared library" ON)
5 changes: 1 addition & 4 deletions ngraph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ option(NGRAPH_ADDRESS_SANITIZER_ENABLE "Compiles and links with Address Sanitize
option(NGRAPH_THREAD_SANITIZER_ENABLE "Compiles and links with Thread Sanitizer" FALSE)
option(NGRAPH_UB_SANITIZER_ENABLE "Compiles and links with Undefined Behavior Sanitizer" FALSE)
option(NGRAPH_USE_PROTOBUF_LITE "Compiles and links with protobuf-lite" FALSE)
option(NGRAPH_STATIC_LIBRARY "Compiles ngraph as a static library" FALSE)

if (NGRAPH_ONNX_IMPORT_ENABLE)
option(NGRAPH_USE_SYSTEM_PROTOBUF "Use system provided Protobuf shared object" FALSE)
Expand Down Expand Up @@ -162,7 +161,6 @@ NORMALIZE_BOOL(NGRAPH_ADDRESS_SANITIZER_ENABLE)
NORMALIZE_BOOL(NGRAPH_THREAD_SANITIZER_ENABLE)
NORMALIZE_BOOL(NGRAPH_UB_SANITIZER_ENABLE)
NORMALIZE_BOOL(NGRAPH_USE_PROTOBUF_LITE)
NORMALIZE_BOOL(NGRAPH_STATIC_LIBRARY)

message(STATUS "NGRAPH_ADDRESS_SANITIZER_ENABLE: ${NGRAPH_ADDRESS_SANITIZER_ENABLE}")
message(STATUS "NGRAPH_CODE_COVERAGE_ENABLE: ${NGRAPH_CODE_COVERAGE_ENABLE}")
Expand All @@ -181,7 +179,6 @@ message(STATUS "NGRAPH_UB_SANITIZER_ENABLE: ${NGRAPH_UB_SANITIZER_ENAB
message(STATUS "NGRAPH_USE_PROTOBUF_LITE: ${NGRAPH_USE_PROTOBUF_LITE}")
message(STATUS "NGRAPH_UNIT_TEST_ENABLE: ${NGRAPH_UNIT_TEST_ENABLE}")
message(STATUS "NGRAPH_WARNINGS_AS_ERRORS: ${NGRAPH_WARNINGS_AS_ERRORS}")
message(STATUS "NGRAPH_STATIC_LIBRARY: ${NGRAPH_STATIC_LIBRARY}")

set(NGRAPH_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD ${NGRAPH_CXX_STANDARD})
Expand Down Expand Up @@ -483,7 +480,7 @@ if (NGRAPH_EXPORT_TARGETS_ENABLE)
set(NGRAPH_TARGETS_FILE "${CMAKE_CURRENT_BINARY_DIR}/ngraphTargets.cmake")
export(TARGETS ngraph NAMESPACE ngraph:: FILE "${NGRAPH_TARGETS_FILE}")

if(NOT NGRAPH_STATIC_LIBRARY)
if(BUILD_SHARED_LIBS)
install(EXPORT ngraphTargets
FILE ngraphTargets.cmake
NAMESPACE ngraph::
Expand Down
12 changes: 4 additions & 8 deletions ngraph/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ source_group("include" FILES ${PUBLIC_HEADERS})

configure_file(include/ngraph/version.in.hpp include/ngraph/version.hpp)

if (NGRAPH_STATIC_LIBRARY)
# Create static library
add_library(ngraph STATIC ${LIBRARY_SRC} ${PUBLIC_HEADERS})
else()
# Create shared library
add_library(ngraph SHARED ${LIBRARY_SRC} ${PUBLIC_HEADERS})
endif()
# Create static or shared library depending on BUILD_SHARED_LIBS
add_library(ngraph ${LIBRARY_SRC} ${PUBLIC_HEADERS})


if(COMMAND ie_faster_build)
ie_faster_build(ngraph
Expand Down Expand Up @@ -75,7 +71,7 @@ if(NGRAPH_LIB_VERSIONING_ENABLE)
SOVERSION ${NGRAPH_API_VERSION})
endif()
target_compile_definitions(ngraph PUBLIC NGRAPH_VERSION="${NGRAPH_VERSION}")
if(NGRAPH_STATIC_LIBRARY)
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(ngraph PUBLIC NGRAPH_STATIC_LIBRARY)
endif()

Expand Down

0 comments on commit 72837db

Please sign in to comment.