Add static-linkage support to CMake file
Well, kind of. It uses pkg-config and GCC's `-static' flag. It's very tied the Linux way of doing things.
This commit is contained in:
parent
6be5aac70d
commit
ca5b092807
1 changed files with 44 additions and 5 deletions
|
@ -18,8 +18,9 @@ option(DEBUG_SAVE "Re-enable the ability to drag-and-drop save files onto the wi
|
||||||
set(BACKEND_RENDERER "SDLTexture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'OpenGLES2' for an OpenGL ES 2.0 renderer, 'SDLTexture' for SDL2's hardware-accelerated Texture API, 'SDLSurface' for SDL2's software-rendered Surface API, or 'Software' for a handwritten software renderer")
|
set(BACKEND_RENDERER "SDLTexture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'OpenGLES2' for an OpenGL ES 2.0 renderer, 'SDLTexture' for SDL2's hardware-accelerated Texture API, 'SDLSurface' for SDL2's software-rendered Surface API, or 'Software' for a handwritten software renderer")
|
||||||
set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2' or 'miniaudio'")
|
set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2' or 'miniaudio'")
|
||||||
|
|
||||||
|
option(STATIC_LINKAGE "On platforms with pkg-config, static-link the dependencies" OFF)
|
||||||
option(LTO "Enable link-time optimisation" OFF)
|
option(LTO "Enable link-time optimisation" OFF)
|
||||||
option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library" OFF)
|
option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library (Visual Studio only)" OFF)
|
||||||
|
|
||||||
option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF)
|
option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF)
|
||||||
|
|
||||||
|
@ -258,6 +259,10 @@ if(DEBUG_SAVE)
|
||||||
target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE)
|
target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(STATIC_LINKAGE)
|
||||||
|
target_link_options(CSE2 PRIVATE "-static")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(LTO)
|
if(LTO)
|
||||||
include(CheckIPOSupported)
|
include(CheckIPOSupported)
|
||||||
|
|
||||||
|
@ -372,10 +377,29 @@ set_target_properties(CSE2 PROPERTIES
|
||||||
################
|
################
|
||||||
|
|
||||||
if(NOT FORCE_LOCAL_LIBS)
|
if(NOT FORCE_LOCAL_LIBS)
|
||||||
find_package(SDL2)
|
find_package(PkgConfig QUIET)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(TARGET SDL2::SDL2)
|
if(NOT FORCE_LOCAL_LIBS)
|
||||||
|
find_package(SDL2)
|
||||||
|
|
||||||
|
if (PKG_CONFIG_FOUND)
|
||||||
|
pkg_check_modules(sdl2 QUIET sdl2)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(sdl2_FOUND)
|
||||||
|
# pkg-config
|
||||||
|
if (STATIC_LINKAGE)
|
||||||
|
message(STATUS "Using system SDL2 (pkg-config, static)")
|
||||||
|
target_compile_options(CSE2 PRIVATE ${sdl2_STATIC_CFLAGS})
|
||||||
|
target_link_libraries(CSE2 PRIVATE ${sdl2_STATIC_LIBRARIES})
|
||||||
|
else()
|
||||||
|
message(STATUS "Using system SDL2 (pkg-config, dynamic)")
|
||||||
|
target_compile_options(CSE2 PRIVATE ${sdl2_CFLAGS})
|
||||||
|
target_link_libraries(CSE2 PRIVATE ${sdl2_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
elseif(TARGET SDL2::SDL2)
|
||||||
# CMake-generated config (Arch, vcpkg, Raspbian)
|
# CMake-generated config (Arch, vcpkg, Raspbian)
|
||||||
message(STATUS "Using system SDL2 (CMake, dynamic)")
|
message(STATUS "Using system SDL2 (CMake, dynamic)")
|
||||||
target_link_libraries(CSE2 PRIVATE SDL2::SDL2 SDL2::SDL2main)
|
target_link_libraries(CSE2 PRIVATE SDL2::SDL2 SDL2::SDL2main)
|
||||||
|
@ -401,10 +425,25 @@ endif()
|
||||||
|
|
||||||
if(NOT FORCE_LOCAL_LIBS)
|
if(NOT FORCE_LOCAL_LIBS)
|
||||||
find_package(Freetype)
|
find_package(Freetype)
|
||||||
|
|
||||||
|
if (PKG_CONFIG_FOUND)
|
||||||
|
pkg_check_modules(freetype2 QUIET freetype2)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FREETYPE_FOUND)
|
if(freetype2_FOUND)
|
||||||
message(STATUS "Using system FreeType")
|
# pkg-config
|
||||||
|
if (STATIC_LINKAGE)
|
||||||
|
message(STATUS "Using system FreeType (pkg-config, static)")
|
||||||
|
target_compile_options(CSE2 PRIVATE ${freetype2_STATIC_CFLAGS})
|
||||||
|
target_link_libraries(CSE2 PRIVATE ${freetype2_STATIC_LIBRARIES})
|
||||||
|
else()
|
||||||
|
message(STATUS "Using system FreeType (pkg-config, dynamic)")
|
||||||
|
target_compile_options(CSE2 PRIVATE ${freetype2_CFLAGS})
|
||||||
|
target_link_libraries(CSE2 PRIVATE ${freetype2_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
elseif(FREETYPE_FOUND)
|
||||||
|
message(STATUS "Using system FreeType (CMake)")
|
||||||
target_include_directories(CSE2 PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
target_include_directories(CSE2 PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
||||||
target_link_libraries(CSE2 PRIVATE ${FREETYPE_LIBRARIES})
|
target_link_libraries(CSE2 PRIVATE ${FREETYPE_LIBRARIES})
|
||||||
else()
|
else()
|
||||||
|
|
Loading…
Add table
Reference in a new issue