diff --git a/host/cmake/Modules/UHDBoost.cmake b/host/cmake/Modules/UHDBoost.cmake index e8c0aae6a..43a481bc7 100644 --- a/host/cmake/Modules/UHDBoost.cmake +++ b/host/cmake/Modules/UHDBoost.cmake @@ -6,11 +6,8 @@ # The following variables can be defined external to this script. # -# ENABLE_STATIC_LIBS : whether to enable static libraries, which will -# require static Boost libraries too. If not using static libraries, -# shared libraries will be used. The default is to use shared -# libraries, and this default will be used if this variable is not -# defined or if is it NO/OFF/FALSE. +# Boost_*: Check the FindBoost CMake documentation. For example, +# Boost_USE_STATIC_LIBS can be set to require static libraries. # # UHD_BOOST_REQUIRED_COMPONENTS : Boost components that are required # for Boost_FOUND to be true. The linkage (shared or static) must be @@ -162,23 +159,6 @@ if(NOT CMAKE_CXX_STANDARD) message(WARNING "\nC++ standard not yet set; setting to C++14.\n") endif() -# tell boost the linkage required -set(Boost_USE_STATIC_LIBS ${ENABLE_STATIC_LIBS}) -# temporarily explicitly enable or disable shared libraries, -# build-wise; this can be disabled on a case by case basis for each -# library built. -if(BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS_SET TRUE) - set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) -else() - set(BUILD_SHARED_LIBS_SET FALSE) -endif() -if(ENABLE_STATIC_LIBS) - set(BUILD_SHARED_LIBS FALSE) -else() - set(BUILD_SHARED_LIBS TRUE) -endif() - if(${UHD_BOOST_OPTIONAL_COMPONENTS_LEN} GREATER 0) message(STATUS " Looking for optional Boost components...") find_package(Boost ${UHD_BOOST_MIN_VERSION} QUIET @@ -191,14 +171,6 @@ if(${UHD_BOOST_REQUIRED_COMPONENTS_LEN} GREATER 0) COMPONENTS ${UHD_BOOST_REQUIRED_COMPONENTS} ${UHD_BOOST_REQUIRED}) endif() -# restore BUILD_SHARED_LIBS, if set -if(BUILD_SHARED_LIBS_SET) - set(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS}) - unset(OLD_BUILD_SHARED_LIBS) -else() - unset(BUILD_SHARED_LIBS) -endif() - if(NOT Boost_FOUND) # Boost was not found # clear out return variables, just in case diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 3d374b6b7..8bd5d99f1 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -187,10 +187,15 @@ target_link_libraries(uhd ${libuhd_libs} PRIVATE uhd_rc ) + +function(UHD_LIB_ADD_RPCLIB uhd_lib_name) + target_include_directories(${uhd_lib_name} PRIVATE deps/rpclib/include) + target_sources(${uhd_lib_name} PRIVATE $) +endfunction(UHD_LIB_ADD_RPCLIB) + if(ENABLE_MPMD) - target_include_directories(uhd PRIVATE deps/rpclib/include) add_subdirectory(deps) - target_sources(uhd PRIVATE $) + UHD_LIB_ADD_RPCLIB(uhd) endif() if(ENABLE_DPDK) add_definitions(-DHAVE_DPDK) @@ -217,12 +222,12 @@ if(DEFINED LIBUHD_OUTPUT_NAME) set_target_properties(uhd PROPERTIES OUTPUT_NAME ${LIBUHD_OUTPUT_NAME}) endif(DEFINED LIBUHD_OUTPUT_NAME) -if(ENABLE_SIM) +function(UHD_LIB_ADD_PYTHON uhd_lib_name) # Get python include dirs # This conditional code somewhat duplicates logic also found in # ../python/CMakeLists.txt but omits user messages. This avoid # duplicate output, since SIM mode requires python support. - target_include_directories(uhd PUBLIC ${PYTHON_INCLUDE_DIRS}) + target_include_directories(${uhd_lib_name} PUBLIC ${PYTHON_INCLUDE_DIRS}) if(NOT pybind11_FOUND) set(PYBIND11_INCLUDE_DIR "${UHD_SOURCE_DIR}/lib/deps/pybind11/include" @@ -231,12 +236,15 @@ if(ENABLE_SIM) "Location of PyBind11 includes" ) endif() - target_include_directories(uhd PRIVATE ${PYBIND11_INCLUDE_DIR}) + target_include_directories(${uhd_lib_name} PRIVATE ${PYBIND11_INCLUDE_DIR}) # For PYUHD we don't link against the python libraries, but when calling # python instead of being called by it, we have to. - target_link_libraries(uhd PUBLIC ${PYTHON_LIBRARIES}) + target_link_libraries(${uhd_lib_name} PUBLIC ${PYTHON_LIBRARIES}) +endfunction(UHD_LIB_ADD_PYTHON) +if(ENABLE_SIM) + UHD_LIB_ADD_PYTHON(uhd) endif(ENABLE_SIM) if(NOT UHDHOST_PKG) # Syntax makes it unusable by UHD_INSTALL @@ -250,13 +258,41 @@ endif(NOT UHDHOST_PKG) ####################################################### # Setup libuhd library (static) ####################################################### -if(ENABLE_STATIC_LIBS) + +# Create a function so we have a separate variable scope for Boost_USE_STATIC_LIBS +function(UHD_ADD_STATIC_LIB) + set(Boost_USE_STATIC_LIBS ON) # only find static libs + include(UHDBoost) add_library(uhd_static STATIC ${libuhd_sources} $) set_target_properties(uhd_static PROPERTIES OUTPUT_NAME uhd) set_target_properties(uhd_static PROPERTIES COMPILE_DEFINITIONS UHD_STATIC_LIB) - target_link_libraries(uhd_static uhd_rc) - install(TARGETS uhd_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # .lib or .a file + target_link_libraries(uhd_static + PUBLIC + Boost::boost + Boost::chrono + Boost::date_time + Boost::filesystem + Boost::serialization + Boost::system + Boost::thread ) + target_include_directories(uhd_static + PRIVATE + ${CMRC_INCLUDE_DIR} + ) + if(ENABLE_MPMD) + UHD_LIB_ADD_RPCLIB(uhd_static) + endif() + if(ENABLE_SIM) + UHD_LIB_ADD_PYTHON(uhd_static) + endif() + install(TARGETS uhd_static + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries # .lib or .a file + ) +endfunction(UHD_ADD_STATIC_LIB) + +if(ENABLE_STATIC_LIBS) + UHD_ADD_STATIC_LIB() endif(ENABLE_STATIC_LIBS) if(ENABLE_EXTEND_WIN_PACKAGING)