Remove STATIC and SHARED variables. (#1542)
As described in the official documentation https://cmake.org/cmake/help/v3.0/variable/BUILD_SHARED_LIBS.html this flag is global by default and controls if the library will be built as a shared or a static library allowing us to define only one call to the add_library function (without specifying its type). It is also added as an option to be visible in CMake GUI applications.
This commit is contained in:
parent
18ab694f70
commit
05dfbf3cd4
@ -14,8 +14,7 @@ option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended
|
||||
|
||||
# Shared library is always PIC. Static library should be PIC too if linked into a shared library
|
||||
option(WITH_PIC "Compile static library as position-independent code" OFF)
|
||||
option(SHARED "Build raylib as a dynamic library" OFF)
|
||||
option(STATIC "Build raylib as a static library" ON)
|
||||
option(BUILD_SHARED_LIBS "Build raylib as a shared library" OFF)
|
||||
option(MACOS_FATLIB "Build fat library for both i386 and x86_64 on macOS" OFF)
|
||||
option(USE_AUDIO "Build raylib with audio module" ON)
|
||||
|
||||
|
@ -1,24 +1,3 @@
|
||||
if(NOT (STATIC OR SHARED))
|
||||
message(FATAL_ERROR "Nothing to do if both -DSHARED=OFF and -DSTATIC=OFF...")
|
||||
endif()
|
||||
|
||||
if (DEFINED BUILD_SHARED_LIBS)
|
||||
set(SHARED ${BUILD_SHARED_LIBS})
|
||||
if (${BUILD_SHARED_LIBS})
|
||||
set(STATIC OFF)
|
||||
else()
|
||||
set(STATIC ON)
|
||||
endif()
|
||||
endif()
|
||||
if(DEFINED SHARED_RAYLIB)
|
||||
set(SHARED ${SHARED_RAYLIB})
|
||||
message(DEPRECATION "-DSHARED_RAYLIB is deprecated. Please use -DSHARED instead.")
|
||||
endif()
|
||||
if(DEFINED STATIC_RAYLIB)
|
||||
set(STATIC ${STATIC_RAYLIB})
|
||||
message(DEPRECATION "-DSTATIC_RAYLIB is deprecated. Please use -DSTATIC instead.")
|
||||
endif()
|
||||
|
||||
if(${PLATFORM} MATCHES "Desktop" AND APPLE)
|
||||
if(MACOS_FATLIB)
|
||||
if (CMAKE_OSX_ARCHITECTURES)
|
||||
|
@ -16,11 +16,16 @@ if(NOT glfw3_FOUND AND NOT USE_EXTERNAL_GLFW STREQUAL "ON" AND "${PLATFORM}" MAT
|
||||
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL " " FORCE)
|
||||
set(GLFW_USE_WAYLAND ${USE_WAYLAND} CACHE BOOL "" FORCE)
|
||||
|
||||
set(WAS_SHARED ${BUILD_SHARED_LIBS})
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL " " FORCE)
|
||||
|
||||
add_subdirectory(external/glfw)
|
||||
|
||||
set(BUILD_SHARED_LIBS WAS_SHARED CACHE BOOL " " FORCE)
|
||||
unset(WAS_SHARED)
|
||||
|
||||
list(APPEND raylib_sources $<TARGET_OBJECTS:glfw_objlib>)
|
||||
include_directories(BEFORE SYSTEM external/glfw/include)
|
||||
else()
|
||||
|
@ -7,12 +7,12 @@ install(
|
||||
)
|
||||
|
||||
# PKG_CONFIG_LIBS_PRIVATE is used in raylib.pc.in
|
||||
if (STATIC)
|
||||
if (NOT BUILD_SHARED_LIBS)
|
||||
include(LibraryPathToLinkerFlags)
|
||||
library_path_to_linker_flags(__PKG_CONFIG_LIBS_PRIVATE "${LIBS_PRIVATE}")
|
||||
set(PKG_CONFIG_LIBS_PRIVATE ${__PKG_CONFIG_LIBS_PRIVATE} ${GLFW_PKG_LIBS})
|
||||
string(REPLACE ";" " " PKG_CONFIG_LIBS_PRIVATE "${PKG_CONFIG_LIBS_PRIVATE}")
|
||||
elseif (SHARED)
|
||||
elseif (BUILD_SHARED_LIBS)
|
||||
set(PKG_CONFIG_LIBS_EXTRA "")
|
||||
endif ()
|
||||
|
||||
|
@ -51,20 +51,14 @@ include(LibraryConfigurations)
|
||||
|
||||
set(LIBS_PRIVATE ${LIBS_PRIVATE} ${OPENAL_LIBRARY})
|
||||
|
||||
if (STATIC)
|
||||
add_library(raylib ${raylib_sources} ${raylib_public_headers})
|
||||
|
||||
if (NOT BUILD_SHARED_LIBS)
|
||||
MESSAGE(STATUS "Building raylib static library")
|
||||
|
||||
add_library(raylib STATIC ${raylib_sources} ${raylib_public_headers})
|
||||
add_library(raylib_static ALIAS raylib)
|
||||
|
||||
add_test("pkg-config--static" ${PROJECT_SOURCE_DIR}/../cmake/test-pkgconfig.sh --static)
|
||||
endif (STATIC)
|
||||
|
||||
|
||||
if (SHARED)
|
||||
else()
|
||||
MESSAGE(STATUS "Building raylib shared library")
|
||||
add_library(raylib SHARED ${raylib_sources} ${raylib_public_headers})
|
||||
|
||||
if (MSVC)
|
||||
target_compile_definitions(raylib
|
||||
PRIVATE $<BUILD_INTERFACE:BUILD_LIBTYPE_SHARED>
|
||||
@ -82,7 +76,7 @@ set_target_properties(raylib PROPERTIES
|
||||
SOVERSION ${API_VERSION}
|
||||
)
|
||||
|
||||
if (WITH_PIC OR SHARED)
|
||||
if (WITH_PIC OR BUILD_SHARED_LIBS)
|
||||
set_property(TARGET raylib PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
endif ()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user