CMake: Add build option to select static or shared libraries

This commit is contained in:
Marius Greuel 2022-05-11 21:08:05 +02:00
parent 0ea4b08b2f
commit 65bb41f8e9
1 changed files with 8 additions and 2 deletions

View File

@ -35,6 +35,13 @@ option(USE_LIBUSBWIN32 "Prefer libusb-win32 over libusb" OFF)
option(DEBUG_CMAKE "Enable debugging output for this CMake project" OFF) option(DEBUG_CMAKE "Enable debugging output for this CMake project" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
if(WIN32)
# Prefer static libraries over DLLs on Windows
option(USE_STATIC_LIBS "Use static libraries" ON)
else()
option(USE_STATIC_LIBS "Use static libraries" OFF)
endif()
include(CheckIncludeFile) include(CheckIncludeFile)
include(CheckSymbolExists) include(CheckSymbolExists)
include(FetchContent) include(FetchContent)
@ -110,8 +117,7 @@ endif()
# Detect installed libraries # Detect installed libraries
# ===================================== # =====================================
# Prefer static libraries over DLLs on Windows if(USE_STATIC_LIBS)
if(WIN32)
set(PREFERRED_LIBELF libelf.a elf) set(PREFERRED_LIBELF libelf.a elf)
set(PREFERRED_LIBUSB libusb.a usb) set(PREFERRED_LIBUSB libusb.a usb)
set(PREFERRED_LIBUSB_1_0 libusb-1.0.a usb-1.0) set(PREFERRED_LIBUSB_1_0 libusb-1.0.a usb-1.0)