From b71f7b70803c52fa2568747df400043ced230a62 Mon Sep 17 00:00:00 2001 From: Paul Sutton Date: Fri, 23 Jun 2017 14:49:21 +0100 Subject: [PATCH] Adding support for static builds --- CMakeLists.txt | 18 +++++++++++++++--- cmake/modules/FindMbedTLS.cmake | 18 ++++++++++++++++-- cmake/modules/FindPolarssl.cmake | 18 ++++++++++++++++-- lib/include/srslte/upper/pdcp.h | 7 +++---- lib/src/phy/CMakeLists.txt | 6 +++--- srsenb/CMakeLists.txt | 4 ++-- srsenb/src/CMakeLists.txt | 4 ++-- srsue/src/CMakeLists.txt | 5 +++++ 8 files changed, 62 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd2aaf433..17609e65f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ option(ENABLE_BLADERF "Enable BladeRF" ON) option(BUILD_STATIC "Attempt to statically link external deps" OFF) option(RPATH "Enable RPATH" OFF) -option(USE_LTE_RATES "Use standard LTE sampling rates" OFF) +option(USE_LTE_RATES "Use standard LTE sampling rates" OFF) set(GCC_ARCH native CACHE STRING "GCC compile for specific architecture.") @@ -79,13 +79,21 @@ find_package(Threads REQUIRED) find_package(Polarssl) if (POLARSSL_FOUND) set(SEC_INCLUDE_DIRS "${POLARSSL_INCLUDE_DIRS}") - set(SEC_LIBRARIES "${POLARSSL_LIBRARIES}") + if(BUILD_STATIC) + set(SEC_LIBRARIES "${POLARSSL_STATIC_LIBRARIES}") + else(BUILD_STATIC) + set(SEC_LIBRARIES "${POLARSSL_LIBRARIES}") + endif(BUILD_STATIC) add_definitions(-DHAVE_POLARSSL) else(POLARSSL_FOUND) find_package(MbedTLS REQUIRED) if (MBEDTLS_FOUND) set(SEC_INCLUDE_DIRS "${MBEDTLS_INCLUDE_DIRS}") - set(SEC_LIBRARIES "${MBEDTLS_LIBRARIES}") + if(BUILD_STATIC) + set(SEC_LIBRARIES "${MBEDTLS_STATIC_LIBRARIES}") + else(BUILD_STATIC) + set(SEC_LIBRARIES "${MBEDTLS_LIBRARIES}") + endif(BUILD_STATIC) add_definitions(-DHAVE_MBEDTLS) endif (MBEDTLS_FOUND) endif(POLARSSL_FOUND) @@ -119,6 +127,10 @@ endif(BLADERF_FOUND OR UHD_FOUND OR SOAPYSDR_FOUND) if(ENABLE_SRSUE OR ENABLE_SRSENB) # Find Boost + if(BUILD_STATIC) + set(Boost_USE_STATIC_LIBS ON) + endif(BUILD_STATIC) + set(BOOST_REQUIRED_COMPONENTS program_options system diff --git a/cmake/modules/FindMbedTLS.cmake b/cmake/modules/FindMbedTLS.cmake index 94d814874..11499bad4 100644 --- a/cmake/modules/FindMbedTLS.cmake +++ b/cmake/modules/FindMbedTLS.cmake @@ -32,9 +32,23 @@ FIND_LIBRARY( /usr/lib64 ) +FIND_LIBRARY( + MBEDTLS_STATIC_LIBRARIES + NAMES libmbedcrypto.a + HINTS $ENV{MBEDTLS_DIR}/lib + ${PC_MBEDTLS_LIBDIR} + ${CMAKE_INSTALL_PREFIX}/lib + ${CMAKE_INSTALL_PREFIX}/lib64 + PATHS /usr/local/lib + /usr/local/lib64 + /usr/lib + /usr/lib64 +) + message(STATUS "MBEDTLS LIBRARIES: " ${MBEDTLS_LIBRARIES}) +message(STATUS "MBEDTLS STATIC LIBRARIES: " ${MBEDTLS_STATIC_LIBRARIES}) message(STATUS "MBEDTLS INCLUDE DIRS: " ${MBEDTLS_INCLUDE_DIRS}) INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(MBEDTLS DEFAULT_MSG MBEDTLS_LIBRARIES MBEDTLS_INCLUDE_DIRS) -MARK_AS_ADVANCED(MBEDTLS_LIBRARIES MBEDTLS_INCLUDE_DIRS) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(MBEDTLS DEFAULT_MSG MBEDTLS_LIBRARIES MBEDTLS_STATIC_LIBRARIES MBEDTLS_INCLUDE_DIRS) +MARK_AS_ADVANCED(MBEDTLS_LIBRARIES MBEDTLS_STATIC_LIBRARIES MBEDTLS_INCLUDE_DIRS) diff --git a/cmake/modules/FindPolarssl.cmake b/cmake/modules/FindPolarssl.cmake index ccf0d6b91..6e6c5c2cb 100644 --- a/cmake/modules/FindPolarssl.cmake +++ b/cmake/modules/FindPolarssl.cmake @@ -31,9 +31,23 @@ FIND_LIBRARY( /usr/lib64 ) +FIND_LIBRARY( + POLARSSL_STATIC_LIBRARIES + NAMES libpolarssl.a + HINTS $ENV{POLARSSL_DIR}/lib + ${PC_POLARSSL_LIBDIR} + ${CMAKE_INSTALL_PREFIX}/lib + ${CMAKE_INSTALL_PREFIX}/lib64 + PATHS /usr/local/lib + /usr/local/lib64 + /usr/lib + /usr/lib64 +) + message(STATUS "POLARSSL LIBRARIES: " ${POLARSSL_LIBRARIES}) +message(STATUS "POLARSSL STATIC LIBRARIES: " ${POLARSSL_STATIC_LIBRARIES}) message(STATUS "POLARSSL INCLUDE DIRS: " ${POLARSSL_INCLUDE_DIRS}) INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(POLARSSL DEFAULT_MSG POLARSSL_LIBRARIES POLARSSL_INCLUDE_DIRS) -MARK_AS_ADVANCED(POLARSSL_LIBRARIES POLARSSL_INCLUDE_DIRS) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(POLARSSL DEFAULT_MSG POLARSSL_LIBRARIES POLARSSL_STATIC_LIBRARIES POLARSSL_INCLUDE_DIRS) +MARK_AS_ADVANCED(POLARSSL_STATIC_LIBRARIES POLARSSL_LIBRARIES POLARSSL_INCLUDE_DIRS) diff --git a/lib/include/srslte/upper/pdcp.h b/lib/include/srslte/upper/pdcp.h index 090f8f045..857806810 100644 --- a/lib/include/srslte/upper/pdcp.h +++ b/lib/include/srslte/upper/pdcp.h @@ -66,14 +66,13 @@ public: void write_pdu_pcch(byte_buffer_t *sdu); private: - log *pdcp_log; - pdcp_entity pdcp_array[SRSLTE_N_RADIO_BEARERS]; - srsue::rlc_interface_pdcp *rlc; srsue::rrc_interface_pdcp *rrc; srsue::gw_interface_pdcp *gw; - uint8_t direction; + log *pdcp_log; + pdcp_entity pdcp_array[SRSLTE_N_RADIO_BEARERS]; + uint8_t direction; bool valid_lcid(uint32_t lcid); }; diff --git a/lib/src/phy/CMakeLists.txt b/lib/src/phy/CMakeLists.txt index 074ddec55..26271f2a7 100644 --- a/lib/src/phy/CMakeLists.txt +++ b/lib/src/phy/CMakeLists.txt @@ -72,11 +72,11 @@ endif(MKL_FOUND) if(MKL_FOUND) - if(STATIC_MKL) + if(BUILD_STATIC) target_link_libraries(srslte_phy ${MKL_STATIC_LIBRARIES}) - else(STATIC_MKL) + else(BUILD_STATIC) target_link_libraries(srslte_phy ${MKL_LIBRARIES}) - endif(STATIC_MKL) + endif(BUILD_STATIC) else(MKL_FOUND) target_link_libraries(srslte_phy ${FFTW3F_LIBRARIES}) endif(MKL_FOUND) diff --git a/srsenb/CMakeLists.txt b/srsenb/CMakeLists.txt index 7fa60301a..c836f36d5 100644 --- a/srsenb/CMakeLists.txt +++ b/srsenb/CMakeLists.txt @@ -21,9 +21,9 @@ find_package(LibConfig REQUIRED) find_package(SCTP REQUIRED) -if(STATIC_LIBCONFIGPP) +if(BUILD_STATIC) set(LIBCONFIGPP_LIBRARIES "${LIBCONFIGPP_STATIC_LIBRARY_PATH}") -endif(STATIC_LIBCONFIGPP) +endif(BUILD_STATIC) if(NOT Boost_FOUND) message(FATAL_ERROR "Boost required to compile srsENB") diff --git a/srsenb/src/CMakeLists.txt b/srsenb/src/CMakeLists.txt index 199650fac..23272ea85 100644 --- a/srsenb/src/CMakeLists.txt +++ b/srsenb/src/CMakeLists.txt @@ -5,9 +5,9 @@ add_subdirectory(upper) # Link libstdc++ and libgcc -if(STATIC_LIB) +if(BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc") -endif(STATIC_LIB) +endif(BUILD_STATIC) if (RPATH) diff --git a/srsue/src/CMakeLists.txt b/srsue/src/CMakeLists.txt index 5a56bb057..1c6b87bc1 100644 --- a/srsue/src/CMakeLists.txt +++ b/srsue/src/CMakeLists.txt @@ -22,6 +22,11 @@ add_subdirectory(phy) add_subdirectory(mac) add_subdirectory(upper) +# Link libstdc++ and libgcc +if(BUILD_STATIC) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc") +endif(BUILD_STATIC) + if (RPATH) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) endif (RPATH)