From 4568f1fa79146566de4d6f93a3c5fabfb43263f1 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Sat, 16 May 2020 00:30:13 -0700 Subject: [PATCH] Use system-provided nanomsg if available Otherwise, maintain current behavior of using the bundled version. --- CMakeLists.txt | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5edf1e3..7df1d28f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,22 +60,25 @@ add_subdirectory(vendor/libcorrect EXCLUDE_FROM_ALL) add_subdirectory(vendor/libaec EXCLUDE_FROM_ALL) add_subdirectory(vendor/json EXCLUDE_FROM_ALL) -# Build nanomsg -option(NN_STATIC_LIB "Build nanomsg as static library." ON) -option(NN_ENABLE_DOC "Build nanomsg documentation." OFF) -option(NN_TESTS "Build nanomsg tests" OFF) -option(NN_TOOLS "Build nanomsg tools" OFF) -add_subdirectory(vendor/nanomsg EXCLUDE_FROM_ALL) - -# Symlink vendor/nanomsg/src such that we can still use the "nanomsg" -# include path and not conflict with system includes (e.g. protocol.h). -execute_process(COMMAND - ${CMAKE_COMMAND} -E make_directory - ${PROJECT_BINARY_DIR}/include) -execute_process(COMMAND - ${CMAKE_COMMAND} -E create_symlink - ${PROJECT_SOURCE_DIR}/vendor/nanomsg/src - ${PROJECT_BINARY_DIR}/include/nanomsg) +find_package(nanomsg QUIET) +if(NOT ${nanomsg_FOUND}) + # Build nanomsg + option(NN_STATIC_LIB "Build nanomsg as static library." ON) + option(NN_ENABLE_DOC "Build nanomsg documentation." OFF) + option(NN_TESTS "Build nanomsg tests" OFF) + option(NN_TOOLS "Build nanomsg tools" OFF) + add_subdirectory(vendor/nanomsg EXCLUDE_FROM_ALL) + + # Symlink vendor/nanomsg/src such that we can still use the "nanomsg" + # include path and not conflict with system includes (e.g. protocol.h). + execute_process(COMMAND + ${CMAKE_COMMAND} -E make_directory + ${PROJECT_BINARY_DIR}/include) + execute_process(COMMAND + ${CMAKE_COMMAND} -E create_symlink + ${PROJECT_SOURCE_DIR}/vendor/nanomsg/src + ${PROJECT_BINARY_DIR}/include/nanomsg) +endif() include_directories(BEFORE SYSTEM ${PROJECT_BINARY_DIR}/include) include_directories(BEFORE SYSTEM ${PROJECT_SOURCE_DIR}/vendor/libcorrect/include)