Default cmake BUILD_SHARED_LIBS to OFF

By not having BUILD_SHARED_LIBS as a defaulted option, if it was not set
in the invocation of cmake then any submodule could come along and set
it instead by declaring it as an option.  If/when this happens in the
middle of the cmake process, some modules will have the flag unset and
others will have it as the default that the submodule set, leading to
inconsistent compilation parameters at best, but likely linking failure.
pull/2214/head
Thomas Winget 9 months ago
parent db01c7c4ce
commit edd3534425

@ -70,11 +70,17 @@ include(cmake/enable_lto.cmake)
option(CROSS_PLATFORM "cross compiler platform" "Linux")
option(CROSS_PREFIX "toolchain cross compiler prefix" "")
option(BUILD_SHARED_LIBS "Build shared library" OFF)
option(BUILD_STATIC_DEPS "Download, build, and statically link against core dependencies" OFF)
option(STATIC_LINK "link statically against dependencies" ${BUILD_STATIC_DEPS})
if(BUILD_STATIC_DEPS AND NOT STATIC_LINK)
message(FATAL_ERROR "Option BUILD_STATIC_DEPS requires STATIC_LINK to be enabled as well")
endif()
if(BUILD_STATIC_DEPS AND BUILD_SHARED_LIBS)
message(FATAL_ERROR "Incompatible options: BUILD_STATIC_DEPS cannot be used with BUILD_SHARED_LIBS")
endif()
if(BUILD_STATIC_DEPS)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
include(cmake/StaticBuild.cmake)
@ -92,11 +98,6 @@ endif()
option(WARN_DEPRECATED "show deprecation warnings" ${debug})
if(BUILD_STATIC_DEPS AND STATIC_LINK)
message(STATUS "we are building static deps so we won't build shared libs")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
endif()
include(CheckCXXSourceCompiles)
include(CheckLibraryExists)
set(CMAKE_CXX_STANDARD 17)

Loading…
Cancel
Save