Skip to content

Commit

Permalink
Rip all the dynamic build logic out of the static Linux Steam build.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotonen committed Oct 5, 2024
1 parent 392eb56 commit e3d4643
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 198 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pr-unit-tests-static-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ jobs:
run: |
cmake buildsystem/linux-steam \
-D CMAKE_CXX_COMPILER="${{ matrix.compiler }}" \
-D CMAKE_BUILD_TYPE="${{ matrix.build-type }}" \
-D CMAKE_LINK_TYPE=Static
-D CMAKE_BUILD_TYPE="${{ matrix.build-type }}"
- name: Build Anura
run: |
Expand Down
307 changes: 111 additions & 196 deletions buildsystem/linux-steam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,15 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

# Default to dynamic linking
if(NOT CMAKE_LINK_TYPE)
set(CMAKE_LINK_TYPE Dynamic)
endif()

# Use vcpkg for static builds
if (CMAKE_LINK_TYPE MATCHES Static)
set(VCPKG_MANIFEST_DIR "${CMAKE_BINARY_DIR}")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_BINARY_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
endif()
# Use vcpkg for dependencies
set(VCPKG_MANIFEST_DIR "${CMAKE_BINARY_DIR}")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_BINARY_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")

# Default to using LTO for Release builds
if (CMAKE_BUILD_TYPE MATCHES Release)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

# Include repo local modules
set(
CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_BINARY_DIR}/buildsystem/cmake-includes/modules"
)

# END CMake setup

# BEGIN Project config
Expand Down Expand Up @@ -72,81 +58,40 @@ file(
"${CMAKE_BINARY_DIR}/src/xhtml/*.cpp"
)

# Configure compiling against system provided libraries
# Configure compiling against vcpkg provided libraries
# XXX - At the moment (2023-08) we have no idea of the upper and lower bounds
# XXX - At the moment (2023-08) we have no idea of the full minimal set

# https://cmake.org/cmake/help/v3.12/module/FindThreads.html
find_package(Threads REQUIRED)
# https://cmake.org/cmake/help/v3.12/module/FindBoost.html
find_package(Boost REQUIRED COMPONENTS filesystem locale regex system)
# https://cmake.org/cmake/help/v3.12/module/FindZLIB.html
find_package(ZLIB REQUIRED)
# https://cmake.org/cmake/help/v3.12/module/FindOpenGL.html
find_package(OpenGL REQUIRED)
# https://cmake.org/cmake/help/v3.12/module/FindGLEW.html
find_package(GLEW REQUIRED)
# https://cmake.org/cmake/help/v3.12/module/FindFreetype.html
find_package(Freetype REQUIRED)

# https://github.com/assimp/assimp/blob/60989a598e2eec923612597b1516604b816d404a/cmake-modules/FindRT.cmake
find_package(RT REQUIRED)
# https://chromium.googlesource.com/external/github.com/g-truc/glm/+/refs/heads/0.9.6/util/FindGLM.cmake
find_package(GLM REQUIRED)
# https://github.com/tcbrindle/sdl2-cmake-scripts/blob/e037fb54f32973343fada6a051d3a3f8adf3a4a0/FindSDL2.cmake
find_package(SDL2 REQUIRED)
# https://github.com/tcbrindle/sdl2-cmake-scripts/blob/e037fb54f32973343fada6a051d3a3f8adf3a4a0/FindSDL2_image.cmake
find_package(SDL2_image REQUIRED)
# https://github.com/tcbrindle/sdl2-cmake-scripts/blob/e037fb54f32973343fada6a051d3a3f8adf3a4a0/FindSDL2_mixer.cmake
find_package(SDL2_mixer REQUIRED)
# https://github.com/tcbrindle/sdl2-cmake-scripts/blob/e037fb54f32973343fada6a051d3a3f8adf3a4a0/FindSDL2_ttf.cmake
find_package(SDL2_ttf REQUIRED)
# https://github.com/libsndfile/libsndfile/blob/ec104e3631a06c4a16f5cbae93b4af2c554fab20/cmake/FindOgg.cmake
find_package(Ogg REQUIRED)
# https://github.com/libsndfile/libsndfile/blob/ec104e3631a06c4a16f5cbae93b4af2c554fab20/cmake/FindVorbis.cmake
find_package(Vorbis REQUIRED)
# https://github.com/WebKit/WebKit/blob/acece69bd261c37f0a66d82d4abc80bed8b09bd7/Source/cmake/FindCairo.cmake
find_package(Cairo REQUIRED)

if (CMAKE_LINK_TYPE MATCHES Static)
find_package(harfbuzz CONFIG REQUIRED)
find_package(WebP CONFIG REQUIRED)
find_package(unofficial-lerc CONFIG REQUIRED)
find_package(zstd CONFIG REQUIRED)
endif()
find_package(harfbuzz CONFIG REQUIRED)
find_package(WebP CONFIG REQUIRED)
find_package(unofficial-lerc CONFIG REQUIRED)
find_package(zstd CONFIG REQUIRED)

# Add the headers
if (CMAKE_LINK_TYPE MATCHES Static)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
include_directories(
"${CMAKE_BINARY_DIR}/src"
"${CMAKE_BINARY_DIR}/src/hex"
"${CMAKE_BINARY_DIR}/src/imgui"
"${CMAKE_BINARY_DIR}/src/imgui_additions"
"${CMAKE_BINARY_DIR}/src/kre"
"${CMAKE_BINARY_DIR}/src/svg"
"${CMAKE_BINARY_DIR}/src/tiled"
"${CMAKE_BINARY_DIR}/src/treetree"
"${CMAKE_BINARY_DIR}/src/xhtml"
"${CMAKE_BINARY_DIR}/vcpkg_installed/x64-linux/include"
)
else()
# XXX - Unknown as of 2023-08 why only Freetype ft2build and SLD2 are needed
include_directories(
"${CMAKE_BINARY_DIR}/src"
"${CMAKE_BINARY_DIR}/src/hex"
"${CMAKE_BINARY_DIR}/src/imgui"
"${CMAKE_BINARY_DIR}/src/imgui_additions"
"${CMAKE_BINARY_DIR}/src/kre"
"${CMAKE_BINARY_DIR}/src/svg"
"${CMAKE_BINARY_DIR}/src/tiled"
"${CMAKE_BINARY_DIR}/src/treetree"
"${CMAKE_BINARY_DIR}/src/xhtml"
"${FREETYPE_INCLUDE_DIR_ft2build}"
"${SDL2_INCLUDE_DIR}"
)
endif()
include_directories(
"${CMAKE_BINARY_DIR}/src"
"${CMAKE_BINARY_DIR}/src/hex"
"${CMAKE_BINARY_DIR}/src/imgui"
"${CMAKE_BINARY_DIR}/src/imgui_additions"
"${CMAKE_BINARY_DIR}/src/kre"
"${CMAKE_BINARY_DIR}/src/svg"
"${CMAKE_BINARY_DIR}/src/tiled"
"${CMAKE_BINARY_DIR}/src/treetree"
"${CMAKE_BINARY_DIR}/src/xhtml"
"${CMAKE_BINARY_DIR}/vcpkg_installed/x64-linux/include"
)

# END Project config

Expand Down Expand Up @@ -177,18 +122,6 @@ if (CMAKE_BUILD_TYPE MATCHES Release)
link_directories("${CMAKE_BINARY_DIR}/vcpkg_installed/x64-linux/release/lib")
endif()

# Warnings as errors
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")

# Enable all compiler warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

# Enable extra compiler warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")

# Enable pedantic compiler warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")

# Inject our own imgui config for our own vector operations
add_compile_definitions(IMGUI_USER_CONFIG="${CMAKE_BINARY_DIR}/src/imgui_additions/imconfig_anura.h")

Expand All @@ -203,18 +136,22 @@ endif()
# XXX - imgui_custom.cpp relies on these
add_compile_definitions(IMGUI_DEFINE_MATH_OPERATORS)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Older compilers should not trip up when we selectively silence warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
endif()

# We need to hide a ton of warnings
include("${CMAKE_BINARY_DIR}/buildsystem/cmake-includes/silence-warnings/CMakeLists.txt")
# XXX - The md5 module of anura does not build without this.
# XXX - Other files also emit the warning, but somehow this gets elevated to an error - no clue, probably worse.
set_property(
SOURCE "${CMAKE_BINARY_DIR}/src/md5.cpp"
APPEND_STRING
PROPERTY COMPILE_FLAGS " -Wno-narrowing"
)

# END Compiler config

# BEGIN Linker config

# Staticly link dependencies in
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)

# Output an executable from the anura sources for anura
add_executable(anura "${anura_SRC}")

Expand All @@ -230,107 +167,85 @@ add_executable(anura "${anura_SRC}")
# - libc (with: realtme, dlopen)
#
# We must YOLO and trust the platform has these things
if (CMAKE_LINK_TYPE MATCHES Static)
target_link_libraries(
anura
PRIVATE
-Wl,-Bstatic

-Wl,--start-group
SDL2
-Wl,--end-group

-Wl,--start-group
Boost::filesystem
-Wl,--end-group

-Wl,--start-group
cairo
pixman-1
freetype
ZLIB::ZLIB
fontconfig
png
expat
brotlidec
brotlicommon
uuid
# XXX - For whatever reason on Debian Bookworm you have to add the below
# jbig
-Wl,--end-group

-Wl,--start-group
GLEW::GLEW
-Wl,--end-group

-Wl,--start-group
vorbisfile
vorbis
ogg
-Wl,--end-group

-Wl,--start-group
SDL2_ttf
harfbuzz::harfbuzz
-Wl,--end-group

-Wl,--start-group
Boost::locale
-Wl,--end-group

-Wl,--start-group
SDL2_image
WebP::webp
WebP::webpdemux
WebP::webpdecoder
tiff
lzma
deflate
WebP::webp
jpeg
unofficial::Lerc::Lerc
zstd::libzstd_static
-Wl,--end-group

-Wl,-Bdynamic
-lrt
-ldl
-ldrm
-lgbm
-lX11
-lXcursor
-lXext
-lXfixes
-lXi
-lXrandr
-lXss
-lxkbcommon
-ldecor-0
-lwayland-client
-lwayland-cursor
-lwayland-egl
-lsamplerate
-lasound
-lpulse
)
else()
target_link_libraries(
anura
PRIVATE
"${RT_LIBRARIES}"
"${CMAKE_THREAD_LIBS_INIT}"
"${Boost_LIBRARIES}"
"${ZLIB_LIBRARIES}"
"${OPENGL_LIBRARIES}"
"${GLEW_LIBRARIES}"
"${FREETYPE_LIBRARIES}"
"${SDL2_LIBRARY}"
"${SDL2_IMAGE_LIBRARIES}"
"${SDL2_MIXER_LIBRARIES}"
"${SDL2_TTF_LIBRARIES}"
"${Vorbis_File_LIBRARY}"
"${Cairo_LIBRARIES}"
)
endif()
target_link_libraries(
anura
PRIVATE
-Wl,-Bstatic

-Wl,--start-group
SDL2
-Wl,--end-group

-Wl,--start-group
Boost::filesystem
-Wl,--end-group

-Wl,--start-group
cairo
pixman-1
freetype
ZLIB::ZLIB
fontconfig
png
expat
brotlidec
brotlicommon
uuid
-Wl,--end-group

-Wl,--start-group
GLEW::GLEW
-Wl,--end-group

-Wl,--start-group
vorbisfile
vorbis
ogg
-Wl,--end-group

-Wl,--start-group
SDL2_ttf
harfbuzz::harfbuzz
-Wl,--end-group

-Wl,--start-group
Boost::locale
-Wl,--end-group

-Wl,--start-group
SDL2_image
WebP::webp
WebP::webpdemux
WebP::webpdecoder
tiff
lzma
deflate
WebP::webp
jpeg
unofficial::Lerc::Lerc
zstd::libzstd_static
-Wl,--end-group

-Wl,-Bdynamic
-lrt
-ldl
-ldrm
-lgbm
-lX11
-lXcursor
-lXext
-lXfixes
-lXi
-lXrandr
-lXss
-lxkbcommon
-ldecor-0
-lwayland-client
-lwayland-cursor
-lwayland-egl
-lsamplerate
-lasound
-lpulse
)

# END Linker config

0 comments on commit e3d4643

Please sign in to comment.