Skip to content

Commit

Permalink
Tease apart the platform-specific dependencies on additional platform…
Browse files Browse the repository at this point in the history
…/system libs, Boost components, Bonjour and PCAP, so that (next) each target's dependencies can be brought together
  • Loading branch information
garethsb committed Aug 2, 2021
1 parent 4b6de18 commit ab5d5f1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
53 changes: 25 additions & 28 deletions Development/cmake/NmosCppCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ if(TARGET websocketpp::websocketpp)
else()
target_include_directories(websocketpp INTERFACE "${WEBSOCKETPP_INCLUDE_DIR}")
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# define __STDC_LIMIT_MACROS to work around C99 vs. C++11 bug in glibc 2.17
# should be harmless with newer glibc or in other scenarios
# see https://sourceware.org/bugzilla/show_bug.cgi?id=15366
# and https://sourceware.org/ml/libc-alpha/2013-04/msg00598.html
target_compile_definitions(
websocketpp INTERFACE
__STDC_LIMIT_MACROS
)
endif()
add_library(nmos-cpp::websocketpp ALIAS websocketpp)

# boost
Expand Down Expand Up @@ -140,33 +150,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
# find Bonjour or Avahi compatibility library for the mDNS support library (mdns)
# note: BONJOUR_INCLUDE and BONJOUR_LIB_DIR aren't set, the headers and library are assumed to be installed in the system paths
set(BONJOUR_LIB -ldns_sd)
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# find resolver (for cpprest/host_utils.cpp)
# note: this is no longer required on all platforms
list(APPEND PLATFORM_LIBS -lresolv)

# define __STDC_LIMIT_MACROS to work around C99 vs. C++11 bug in glibc 2.17
# should be harmless with newer glibc or in other scenarios
# see https://sourceware.org/bugzilla/show_bug.cgi?id=15366
# and https://sourceware.org/ml/libc-alpha/2013-04/msg00598.html
add_definitions(/D__STDC_LIMIT_MACROS)

# add dependency required by nmos/filesystem_route.cpp
if((CMAKE_CXX_COMPILER_ID MATCHES GNU) AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5.3))
list(APPEND PLATFORM_LIBS -lstdc++fs)
else()
list(APPEND FIND_BOOST_COMPONENTS filesystem)
endif()

if(BUILD_LLDP)
# find libpcap for the LLDP support library (lldp)
set(PCAP_LIB -lpcap)
endif()
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# find Bonjour for the mDNS support library (mdns)
set(MDNS_SYSTEM_BONJOUR OFF CACHE BOOL "Use installed Bonjour SDK")
if(MDNS_SYSTEM_BONJOUR)
Expand Down Expand Up @@ -208,8 +192,13 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
${NMOS_CPP_DIR}/third_party/mDNSResponder/mDNSWindows/DLLStub/DLLStub.h
)
endif()
endif()

if(BUILD_LLDP)
if(BUILD_LLDP)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# find libpcap for the LLDP support library (lldp)
set(PCAP_LIB -lpcap)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# find WinPcap for the LLDP support library (lldp)
set(PCAP_INCLUDE_DIR "${NMOS_CPP_DIR}/third_party/WpdPack/Include" CACHE PATH "WinPcap include directory")
set(PCAP_LIB_DIR "${NMOS_CPP_DIR}/third_party/WpdPack/Lib/x64" CACHE PATH "WinPcap library directory")
Expand All @@ -220,6 +209,14 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
endif()
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
if((CMAKE_CXX_COMPILER_ID MATCHES GNU) AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5.3))
else()
# add filesystem (for bst/filesystem.h, used by nmos/filesystem_route.cpp)
list(APPEND FIND_BOOST_COMPONENTS filesystem)
endif()
endif()

# since std::shared_mutex is not available until C++17
# see bst/shared_mutex.h
list(APPEND FIND_BOOST_COMPONENTS thread)
Expand Down
16 changes: 15 additions & 1 deletion Development/cmake/NmosCppLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,6 @@ target_link_libraries(
nmos-cpp::nmos_is09_schemas
nmos-cpp::Boost
nmos-cpp::OpenSSL
${PLATFORM_LIBS}
)
target_link_libraries(
nmos-cpp PRIVATE
Expand All @@ -1014,6 +1013,21 @@ if(BUILD_LLDP)
nmos-cpp::lldp
)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# link to resolver functions (for cpprest/host_utils.cpp)
# note: this is no longer required on all platforms
target_link_libraries(
nmos-cpp PUBLIC
resolv
)
if((CMAKE_CXX_COMPILER_ID MATCHES GNU) AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5.3))
# link to std::filesystem functions (for nmos/filesystem_route.cpp, depending on bst/filesystem.h)
target_link_libraries(
nmos-cpp PUBLIC
stdc++fs
)
endif()
endif()
target_include_directories(nmos-cpp PUBLIC
${NMOS_CPP_DIR}
)
Expand Down

0 comments on commit ab5d5f1

Please sign in to comment.