CMake: add USE_STATIC option

USE_STATIC will:
 - always link statically with external libraries (such as glib2)
 - will not set rpath to avoid the following error:

CMake Error at cmake_install.cmake:50 (file):
  file RPATH_CHANGE could not write new RPATH:

    /usr/lib

  to the file:

    /home/fabrice/br-test-pkg/br-arm-full-static/target/usr/bin/tshark

  No valid ELF RPATH or RUNPATH entry exists in the file;

Change-Id: I242dc1a091cc211ee891568a2dee5080c9974fba
Ping-Bug: 15713
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Reviewed-on: https://code.wireshark.org/review/32945
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
Fabrice Fontaine 2019-04-22 18:39:52 +02:00 committed by Peter Wu
parent dd1245f5be
commit 900b9f1379
2 changed files with 6 additions and 1 deletions

View File

@ -185,7 +185,7 @@ set(PROJECT_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
set(LIBRARY_INSTALL_RPATH "")
set(EXECUTABLE_INSTALL_RPATH "")
set(EXTCAP_INSTALL_RPATH "")
if(NOT (WIN32 OR APPLE))
if(NOT (WIN32 OR APPLE OR USE_STATIC))
# Try to set a RPATH for installed binaries if the library directory is
# not already included in the default search list.
list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" IS_SYSTEM_DIR)
@ -325,6 +325,10 @@ if(OSS_FUZZ)
message(FATAL_ERROR "Cannot force libFuzzer when using oss-fuzz")
endif()
# Must not depend on external dependencies so statically link all libs.
set(USE_STATIC ON)
endif()
if(USE_STATIC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()

View File

@ -59,6 +59,7 @@ if(WIN32)
option(ENABLE_AIRPCAP "Enable AirPcap support" ON)
endif()
option(ENABLE_STATIC "Build Wireshark libraries statically" OFF)
option(USE_STATIC "Always link statically with external libraries" OFF)
option(ENABLE_PLUGINS "Build with plugins" ON)
option(ENABLE_PLUGIN_IFDEMO "Build with plugin interface demo" OFF)
option(ENABLE_PCAP_NG_DEFAULT "Enable pcapng as default file format" ON)