aboutsummaryrefslogtreecommitdiffstats
path: root/host/cmake/Modules
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2015-01-09 18:39:29 +0100
committerMartin Braun <martin.braun@ettus.com>2015-01-19 09:07:16 +0100
commitad1ef1b64590b72a3286046f8baa79ac055f9923 (patch)
tree05950e99844a12c4c37a9a7a4f8b2cbbe6a59be4 /host/cmake/Modules
parent734180c44b438cf707c4ff48bf4b11a8c5a94136 (diff)
downloaduhd-ad1ef1b64590b72a3286046f8baa79ac055f9923.tar.gz
uhd-ad1ef1b64590b72a3286046f8baa79ac055f9923.tar.bz2
uhd-ad1ef1b64590b72a3286046f8baa79ac055f9923.zip
cmake: Added ENABLE_STATIC_LIBS option
- Allows building static libraries - For users calling find_package(UHD), provides extra options for building apps statically linking UHD. - Updated the init_usrp example to link UHD statically.
Diffstat (limited to 'host/cmake/Modules')
-rw-r--r--host/cmake/Modules/UHDConfig.cmake.in (renamed from host/cmake/Modules/UHDConfig.cmake)25
1 files changed, 25 insertions, 0 deletions
diff --git a/host/cmake/Modules/UHDConfig.cmake b/host/cmake/Modules/UHDConfig.cmake.in
index cf841cc85..78f01706f 100644
--- a/host/cmake/Modules/UHDConfig.cmake
+++ b/host/cmake/Modules/UHDConfig.cmake.in
@@ -60,6 +60,19 @@ ENDIF()
LIST(APPEND UHD_INCLUDE_HINTS ${CMAKE_INSTALL_PREFIX}/include)
LIST(APPEND UHD_LIBDIR_HINTS ${CMAKE_INSTALL_PREFIX}/lib)
+
+# Search for static libs if so required
+IF( UHD_USE_STATIC_LIBS )
+ SET( _UHD_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ IF(WIN32)
+ SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ ELSE()
+ SET(CMAKE_FIND_LIBRARY_SUFFIXES .a )
+ ENDIF()
+ # This is set during build of UHD to match the installed version:
+ SET(UHD_STATIC_LIB_DEPS "@UHD_LINK_LIST_STATIC@")
+ENDIF()
+
# Verify that <uhd/config.hpp> and libuhd are available, and, if a
# version is provided, that UHD meets the version requirements -- no
# matter what pkg-config might think.
@@ -80,6 +93,18 @@ FIND_LIBRARY(
/usr/lib
)
+# Set up linker flags for static linking:
+IF(UHD_USE_STATIC_LIBS)
+ IF(WIN32)
+ MESSAGE(FATAL_ERROR "Static linking not available on Windows")
+ ELSE(WIN32)
+ # This works for gcc and Clang:
+ SET(UHD_STATIC_LIB_LINK_FLAG "-Wl,-whole-archive ${UHD_LIBRARIES} -Wl,-no-whole-archive")
+ ENDIF(WIN32)
+ # Restore the library suffixes, if we changed them:
+ SET(CMAKE_FIND_LIBRARY_SUFFIXES ${_UHD_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
+ENDIF(UHD_USE_STATIC_LIBS)
+
IF(UHD_LIBRARIES AND UHD_INCLUDE_DIRS)
INCLUDE(FindPackageHandleStandardArgs)