Skip to content

CMake Refactor #3093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 233 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
233 commits
Select commit Hold shift + click to select a range
94f8326
Move enscripten
Oct 29, 2024
d83f40c
Move to find_package directly in the CMakeLists.txt
Oct 30, 2024
c72db8b
Remove CMakeLists.txt.old (oops)
Oct 30, 2024
0476871
Remove supertux2_lib and supertux2_c
Oct 30, 2024
b249342
Fix warning from other cmakefiles
Oct 30, 2024
219b28d
Switch to PkgConfig for a few things (kind of a hack)
Oct 30, 2024
7d9a7ef
Remove my attribution from Copyright
Oct 30, 2024
ec7043e
Fix PIC linking issues
Oct 30, 2024
2d17b3f
Fix Emacs
Oct 30, 2024
8b9f20f
Use custom add_package to handle dependency checking in one line
Oct 31, 2024
67395f5
Fix install guide for Ubuntu and Arch
Oct 31, 2024
9866b82
Refactor add_package to a macro, do aliases, move to separate file
Oct 31, 2024
099690b
Fix incorrect terminology
Oct 31, 2024
1b58d75
Better ProvideDiscord warning
Oct 31, 2024
0063eec
Refactor tests a bit
Oct 31, 2024
2d9d3dd
MD5 unit test
Oct 31, 2024
4c29ca7
5am code
Nov 1, 2024
d4d8df9
make_unit_test; fix AATriangleTest
Nov 1, 2024
fd67dcd
Use SDL_rect.h instead of SDL.h for math/rect methods
Nov 1, 2024
6830c02
Custom assert function (broken)
Nov 1, 2024
5e6bc8d
GLM_ENABLE_EXPERIMENTAL
Nov 2, 2024
9fbf635
Make tests/assert more verbose
Nov 2, 2024
ca30f08
Merge branch 'cmake-refactor' of github.com:swagtoy/supertux into cma…
Nov 2, 2024
d13fd68
Add broken DynamicScopeTest for now
Nov 3, 2024
b86b57f
Fix title screen release check
Nov 3, 2024
a8237a4
Move SavePNG
Nov 3, 2024
7013c00
Fix SDL_SavePNG
Nov 3, 2024
d18ffea
Packages using provides code wot i dont think compiles anyway lole ju…
Nov 4, 2024
96ecc66
Merge branch 'cmake-refactor' of https://github.com/swagtoy/supertux …
Nov 4, 2024
84023d2
btich mingw
MatusGuy Nov 4, 2024
5f72189
Merge branch 'master' of https://github.com/swagtoy/supertux into cma…
Nov 5, 2024
9a92c2d
Fix indention
Nov 5, 2024
15733c9
Workaround tinygettext wanting iconv
Nov 5, 2024
9c48859
Add more external links
Nov 5, 2024
b64184e
remove gprof thingy and wip mingw fix error handler
MatusGuy Nov 5, 2024
edc7666
mingw works!!! Create dbghelp.a using a predefined dbghelp.def
MatusGuy Nov 5, 2024
af14dc4
Add ALL_TESTS target; add FileSystemTest just to remove it anyway
Nov 6, 2024
cb08b63
Would help if I actually committed the tests
Nov 6, 2024
e65617f
add this file that i forgot to add for mingw
MatusGuy Nov 6, 2024
244c8ea
Merge branch 'cmake-refactor' of https://github.com/swagtoy/supertux …
MatusGuy Nov 6, 2024
40899c6
fix msvc, add option to disable testing, use console when in debug build
MatusGuy Nov 6, 2024
99a050e
Allow for different package names when using pkg-config
MatusGuy Nov 19, 2024
4106352
Update sexp-cpp
MatusGuy Nov 29, 2024
03dbdb0
Better window title and git version detection
MatusGuy Nov 29, 2024
79a6309
Better window title and git version detection
MatusGuy Nov 29, 2024
13b42c6
Merge branch 'cmake-refactor' of https://github.com/swagtoy/supertux …
MatusGuy Nov 29, 2024
7431a90
Fix git message
Dec 1, 2024
87bac26
Git run improvements
Dec 1, 2024
e2591a2
Modules thing (complete me)
Dec 1, 2024
142b602
Correctly use pkg-config and add option to prefer it
MatusGuy Dec 10, 2024
dd18bf0
Fix git revision checking
MatusGuy Dec 10, 2024
b0d9546
Fix _FOUND if statement
MatusGuy Dec 13, 2024
1686dd6
Move Emscripten.cmake to correct path
MatusGuy Dec 14, 2024
efea468
Fix install target for portable package
MatusGuy Dec 16, 2024
8059e00
Exclude submodules from all target and better release checking
MatusGuy Dec 16, 2024
a711134
Improve git version checking
MatusGuy Dec 16, 2024
25ec5e5
FreeBSD (and others?) error handling
Dec 26, 2024
0b24861
Fix random weird components in WIX cpack generation
MatusGuy Dec 27, 2024
e950507
Fix simplesquirrel merge conflict
MatusGuy Dec 27, 2024
02cc52a
Merge branch 'real-master' into nekobro-cmake-refactor
MatusGuy Dec 27, 2024
b8ee409
Update tinygettext
MatusGuy Jan 25, 2025
cc7187a
Update simplesquirrel
MatusGuy Jan 25, 2025
06cbea1
Mark CTest porting for later
MatusGuy Jan 25, 2025
b062888
Merge branch 'real-master' into nekobro-cmake-refactor
MatusGuy Jan 25, 2025
96a3ebc
Use simpler opengl check without GLEW
MatusGuy Jan 25, 2025
840f469
Try gnulinux.yml
MatusGuy Jan 26, 2025
a5fde84
Fix comment
MatusGuy Jan 26, 2025
20449fb
install fmt
MatusGuy Jan 26, 2025
afc29f4
install physfs
MatusGuy Jan 26, 2025
6297944
strenghten addpackage
MatusGuy Jan 26, 2025
ad125e7
Fix glm on Fedora
MatusGuy Jan 27, 2025
db42c1f
Only check target in add_package
MatusGuy Jan 28, 2025
9bb1822
Use cmake target features for cxx standard
MatusGuy Jan 28, 2025
7777a9f
cmake policy for cxx standard
MatusGuy Jan 28, 2025
f1eff3d
hack
MatusGuy Jan 28, 2025
7a3324b
Change add_subdirectory order
MatusGuy Jan 28, 2025
2b285ed
try this and if it doesnt work i will die probably
MatusGuy Jan 30, 2025
9e6b118
Ok it didnt work but updating sexp-cpp might work
MatusGuy Jan 30, 2025
1a07ccd
Update compilers
MatusGuy Jan 31, 2025
f671506
update sexp
MatusGuy Feb 9, 2025
9b74483
Update sexp again
MatusGuy Feb 9, 2025
e021967
Update sexp
MatusGuy Feb 9, 2025
d6b1410
Fix a bunch of things and fmt
MatusGuy Feb 9, 2025
4287161
go my discord-rpc
MatusGuy Feb 10, 2025
e9a064d
Update discord sdk
MatusGuy Feb 11, 2025
948bb63
Fix fix fix discord update fmt fix fix
MatusGuy Feb 15, 2025
693ecb8
Update ubuntu version
MatusGuy Feb 15, 2025
3dafafc
ugghhhh fix
MatusGuy Feb 15, 2025
5b2be3b
fix gcc.version
MatusGuy Feb 15, 2025
bb0d039
no more coverage
MatusGuy Feb 21, 2025
f8e3336
go back to fmt addpackage
MatusGuy Feb 21, 2025
3920673
fix 32bit
MatusGuy Feb 21, 2025
a90e775
Merge branch 'real-master' into nekobro-cmake-refactor
MatusGuy Feb 21, 2025
ad60575
Merge remote-tracking branch 'upstream/master' into nekobro-cmake-ref…
MatusGuy Feb 21, 2025
125a455
Don't package when debug
MatusGuy Feb 21, 2025
699c81f
fix clang warning
MatusGuy Feb 21, 2025
5f1a252
remove arch args
MatusGuy Feb 22, 2025
e4de0b6
Prefer find package in physfs ci 32bit
MatusGuy Feb 22, 2025
3dc7daf
Disable a clang warning
MatusGuy Feb 22, 2025
02829a6
Remove CI werror
MatusGuy Feb 22, 2025
0eb341b
idk what to do here
MatusGuy Feb 22, 2025
05aebf2
vcpkg toolchain file in linux ci
MatusGuy Feb 22, 2025
b5b68ff
change vcpkg root in ci
MatusGuy Feb 22, 2025
4f1f0fa
fix package.sh
MatusGuy Feb 22, 2025
46f6a2b
32bit vcpkg triplet
MatusGuy Feb 22, 2025
23ce17e
specify vcpkg root as env var
MatusGuy Feb 22, 2025
dffea05
add fuse
MatusGuy Feb 22, 2025
a863283
switch to pwsh aleluja
MatusGuy Feb 22, 2025
edfb00c
try fix
MatusGuy Feb 22, 2025
4ebc21d
test
MatusGuy Feb 22, 2025
5cf35b7
chg name
MatusGuy Feb 22, 2025
fffc748
test again
MatusGuy Feb 22, 2025
473cf87
finally fix
MatusGuy Feb 22, 2025
16eaa3b
fix fix fix fix fix fix fix fix
MatusGuy Feb 22, 2025
046785a
AAHHHHHH HOW COULD I FORGET
MatusGuy Feb 22, 2025
ecd1e9b
test 2
MatusGuy Feb 22, 2025
309aeb7
this should fix EVERYTHING
MatusGuy Feb 22, 2025
aafadf8
turn to string
MatusGuy Feb 22, 2025
c8435ae
fix docs
MatusGuy Feb 22, 2025
af08dab
try
MatusGuy Feb 22, 2025
34fadce
fix indent
MatusGuy Feb 22, 2025
c9c9ef0
revert docs
MatusGuy Feb 22, 2025
37c13f7
doc fix aaha
MatusGuy Feb 22, 2025
39fc31f
normal boolean please???
MatusGuy Feb 22, 2025
3baad69
AAAAAAAAAA DOCS YOU BT
MatusGuy Feb 22, 2025
6dbf7d9
im desperate please work stop trolling me
MatusGuy Feb 22, 2025
14d2f26
REport opengl
MatusGuy Feb 23, 2025
fd2495d
update desktop file install location
MatusGuy Feb 23, 2025
f342885
add glu
MatusGuy Feb 23, 2025
943d0a7
Fix...?
MatusGuy Feb 23, 2025
e1b10f9
fix everythign????
MatusGuy Feb 23, 2025
dfd275f
change quotes
MatusGuy Feb 23, 2025
53e6080
update windows ci
MatusGuy Feb 23, 2025
17b1d08
add physfs and wait another 2 years
MatusGuy Feb 23, 2025
c7dbfde
Update windows.yml
MatusGuy Feb 23, 2025
49d7425
Fix ubuntu touch
MatusGuy Feb 23, 2025
8110670
fix ut fmt maybe?? lol
MatusGuy Feb 23, 2025
8400cd9
fix macos??
MatusGuy Feb 23, 2025
3b99f78
remove macos glbinding
MatusGuy Feb 23, 2025
fad8e38
add ppa
MatusGuy Feb 23, 2025
989cb90
update fmt
MatusGuy Feb 23, 2025
31e014b
get newer fmt
MatusGuy Feb 24, 2025
33db3ab
forgot to commit script
MatusGuy Feb 24, 2025
fdf70c2
set pwd
MatusGuy Feb 24, 2025
eb3b675
dont change pwd
MatusGuy Feb 24, 2025
daa1faa
no way this work
MatusGuy Feb 24, 2025
620b3c0
give up
MatusGuy Feb 24, 2025
8ce39b9
try this
MatusGuy Feb 24, 2025
1a8cb77
omfg leave me alone
MatusGuy Feb 24, 2025
2ea3724
remove sudo
MatusGuy Feb 24, 2025
fc041c6
i have been trolled into oblivion
MatusGuy Feb 24, 2025
5c2a96e
use the force
MatusGuy Feb 24, 2025
2e41427
uuuuhhhh.. wakey wakey?
MatusGuy Feb 24, 2025
c64d63c
DON'T CARE
MatusGuy Feb 24, 2025
a7dfdfb
ok NEVERMIND
MatusGuy Feb 24, 2025
4f40e3d
Fix sdl version
MatusGuy Feb 27, 2025
17a433a
build fmt from source
MatusGuy Mar 1, 2025
64d1938
try again
MatusGuy Mar 1, 2025
22a75ed
aauu
MatusGuy Mar 1, 2025
bd02d47
gicve up
MatusGuy Mar 1, 2025
1fe3a44
fix link
MatusGuy Mar 1, 2025
88dcb76
use zip
MatusGuy Mar 1, 2025
d8147a5
fix cmake command fmt
MatusGuy Mar 1, 2025
b065041
add deps to pkgconfig path
MatusGuy Mar 1, 2025
d3598cf
add to env
MatusGuy Mar 1, 2025
f1c8ba4
no more tests
MatusGuy Mar 1, 2025
556c041
update tinygettext and fix macos
MatusGuy Mar 1, 2025
f79adaa
remove macos tests
MatusGuy Mar 1, 2025
f34ab82
wasm vcpkg
MatusGuy Mar 1, 2025
0843dbe
run emsdk env
MatusGuy Mar 1, 2025
6dca29d
emscripten glew
MatusGuy Mar 1, 2025
8431298
rm glew
MatusGuy Mar 1, 2025
5b81cce
chainload emscripten
MatusGuy Mar 2, 2025
49dacc0
fix fix fix
MatusGuy Mar 2, 2025
30edf91
use emscripten ports
MatusGuy Mar 3, 2025
6a019a4
move
MatusGuy Mar 3, 2025
fbcdbe1
install libpng
MatusGuy Mar 3, 2025
2000c9e
disable sq install
MatusGuy Mar 3, 2025
bbd99d6
disable sq installer but better
MatusGuy Mar 3, 2025
943d5c1
opengl emscripten but better
MatusGuy Mar 3, 2025
1d23c02
update tinygettext
MatusGuy Mar 3, 2025
2d85f5e
sdl savepng wasm
MatusGuy Mar 3, 2025
11aade8
add wasm vorbis
MatusGuy Mar 3, 2025
66cd726
link openal but better
MatusGuy Mar 3, 2025
6059c1a
put opengl in link flags instead
MatusGuy Mar 3, 2025
872f384
update sexp
MatusGuy Mar 3, 2025
8d13db0
oops
MatusGuy Mar 3, 2025
122d17f
add back raqm and sdl ttf fork
MatusGuy Mar 7, 2025
dfece05
use raqm 32bit package
MatusGuy Apr 2, 2025
119ce90
Fix addpackage required flag
MatusGuy Apr 2, 2025
95a192d
update sexp
MatusGuy Apr 2, 2025
97c7599
Merge branch 'real-master' into nekobro-cmake-refactor
MatusGuy Apr 2, 2025
d5ce394
CMake 3.5 compat
MatusGuy Apr 2, 2025
36084a6
str
MatusGuy Apr 2, 2025
1e5948b
raqm vcpkg
MatusGuy Apr 2, 2025
ea537f8
RAQM try fix
MatusGuy Apr 2, 2025
e17e874
darn logic
MatusGuy Apr 2, 2025
a186c96
do this do that
MatusGuy Apr 2, 2025
650b02d
try try try
MatusGuy Apr 2, 2025
fc9ad4c
Merge branch 'master' into cmake-refactor
MatusGuy Apr 19, 2025
0fc349b
Fix arabic text FOREVER
MatusGuy Apr 19, 2025
78abbfa
fix savepng emscripten
MatusGuy Apr 19, 2025
146be1c
add sdl2ttf to emscripten
MatusGuy Apr 19, 2025
b486015
Add gles
MatusGuy Apr 19, 2025
750c1fa
gl in use flags
MatusGuy Apr 19, 2025
4d4d3c1
opengl es
MatusGuy Apr 19, 2025
dc1cf9d
add opengles compile def
MatusGuy Apr 19, 2025
5a60ecf
move option
MatusGuy Apr 19, 2025
010328d
uoooaaah add define manually
MatusGuy Apr 19, 2025
652ce40
what is even going on anymore
MatusGuy Apr 20, 2025
263578d
if this doesnt work im gonna DIE
MatusGuy Apr 20, 2025
ff4f343
WAKE UP
MatusGuy Apr 20, 2025
dd74053
testy
MatusGuy Apr 20, 2025
c7af1ae
set as cachevars auguh
MatusGuy Apr 20, 2025
d0e13f2
try fix github actions cache
MatusGuy Apr 20, 2025
aaa13c0
Print opengl src
MatusGuy Apr 20, 2025
05e79c8
Foda-se!
MatusGuy Apr 20, 2025
80302b2
final fix and im OUTTA HERE
MatusGuy Apr 20, 2025
e308384
Remove all unneeded files
MatusGuy Apr 20, 2025
c7928b4
add IPH and PCH
MatusGuy Apr 20, 2025
3640c24
try fix windows dlls
MatusGuy Apr 20, 2025
0055e56
we dont need these lets be honest
MatusGuy Apr 20, 2025
8a41c04
try fux
MatusGuy Apr 20, 2025
b599765
OOPS
MatusGuy Apr 20, 2025
ff27e1e
Dude who tf is u
MatusGuy Apr 20, 2025
330b313
wtf...
MatusGuy Apr 20, 2025
40ee161
this is so unbearable
MatusGuy Apr 21, 2025
c4f8c87
Fix windows packaging???? Dear god
MatusGuy Apr 21, 2025
dfe140d
dont package on debug workflow
MatusGuy Apr 21, 2025
5f4114a
Add vcpkg manifest file
MatusGuy May 4, 2025
e7d1eba
Manually specify supertux release
MatusGuy May 4, 2025
75d70e2
Fix linux install
MatusGuy May 4, 2025
50f83b8
Update compilation docs
MatusGuy May 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 79 additions & 96 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,20 @@
# make
#

cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.14)

## Project name to use as command prefix.

project(SUPERTUX)


### CMake configuration

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0008 NEW)
cmake_policy(SET CMP0023 NEW)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Stop CMake from whining about 3.5 or future versions that other FindXXXXX.cmake files (seen from vcpkg) use
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)

# This should be set only with windows Visual Studio generator builds
string(TOLOWER "${CMAKE_GENERATOR_PLATFORM}" PLATFORM)
if(${PLATFORM} MATCHES "arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_ARM64_ /DMY_CPU_LE")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D_ARM64_ /DMY_CPU_LE")
Expand All @@ -69,16 +62,9 @@ set(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/games/supertux2")
set(BUILD_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/data")
set(BUILD_CONFIG_DATA_DIR "${CMAKE_BINARY_DIR}/data")

## Check endianess
if(NOT EMSCRIPTEN)
# FIXME: Any reason why we need this?
include(TestBigEndian)
test_big_endian(WORDS_BIGENDIAN)
endif()

## Add definitions
if(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo")
add_definitions(-DRELEASE)
add_definitions(-DRELEASE) # FIXME Unnecessary?
elseif(CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DDEBUG)
endif()
Expand All @@ -101,22 +87,9 @@ else()
endif()

if(EMSCRIPTEN)
set(CMAKE_EXECUTABLE_SUFFIX .html)
set(IS_EMSCRIPTEN_BUILD ON)

set(EM_USE_FLAGS "-sDISABLE_EXCEPTION_CATCHING=0")
set(EM_LINK_FLAGS " -sINITIAL_MEMORY=134217728 -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=536870912 -sERROR_ON_UNDEFINED_SYMBOLS=0 --preload-file ${BUILD_CONFIG_DATA_DIR} --use-preload-plugins -lidbfs.js")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(EM_USE_FLAGS "${EM_USE_FLAGS} -fsanitize=undefined")
set(EM_LINK_FLAGS "${EM_LINK_FLAGS} -fsanitize=undefined -sSAFE_HEAP=1 -sASSERTIONS=1 -sDEMANGLE_SUPPORT=1")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EM_USE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EM_USE_FLAGS}")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${EM_USE_FLAGS} ${EM_LINK_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${EM_USE_FLAGS} ${EM_LINK_FLAGS}")
include(SuperTux/Emscripten)
endif()

# TODO: Add " OR ANDROID OR IOS" to this
if(EMSCRIPTEN OR UBUNTU_TOUCH OR ANDROID)
option(REMOVE_QUIT_BUTTON "Remove the option to quit the game (useful on mobile devices)" ON)
else()
Expand Down Expand Up @@ -167,21 +140,28 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()

## Add lots of dependencies to compiler switches
include(SuperTux/ProvideGlm)
include(SuperTux/ProvideFmt)
include(SuperTux/ProvideSDL2)
include(SuperTux/ProvideOpenAL)
include(SuperTux/ProvideOggVorbis)
include(SuperTux/ProvidePhysfs)
include(SuperTux/ProvideCurl)
include(SuperTux/AddPackage)

# Find dependencies
add_package(TARGET SDL2 PKG SDL2 PKG_USE SDL2::SDL2 CONFIG REQUIRED PKG_CONFIG sdl2)
add_package(TARGET SDL2_image PKG SDL2_image PKG_USE SDL2_image::SDL2_image CONFIG REQUIRED PKG_CONFIG sdl2_image)
add_package(TARGET SDL2_ttf PKG SDL2_ttf PKG_USE SDL2_ttf::SDL2_ttf CONFIG REQUIRED PKG_CONFIG sdl2_ttf)
add_package(TARGET CURL PKG CURL PKG_USE CURL::libcurl PKG_CONFIG libcurl)
add_package(TARGET OpenAL PKG OpenAL PKG_USE OpenAL::OpenAL CONFIG REQUIRED PKG_CONFIG OpenAL)
add_package(TARGET Ogg PKG Ogg PKG_USE Ogg::ogg CONFIG REQUIRED PKG_CONFIG ogg)
add_package(TARGET Vorbis PKG Vorbis PKG_USE Vorbis::vorbis CONFIG REQUIRED PKG_CONFIG vorbis)
add_package(TARGET VorbisFile PKG Vorbis PKG_USE Vorbis::vorbisfile CONFIG REQUIRED PKG_CONFIG vorbisfile)
add_package(TARGET glm PKG glm PKG_USE glm::glm CONFIG REQUIRED PKG_CONFIG glm)
add_package(TARGET fmt PKG fmt PKG_USE fmt::fmt CONFIG REQUIRED PKG_CONFIG fmt)
add_package(TARGET PhysFS PKG PhysFS PKG_USE PhysFS::PhysFS CONFIG REQUIRED PKG_CONFIG physfs PROVIDES ProvidePhysfs)

include(SuperTux/ProvideSavePNG)
include(SuperTux/ProvideSimpleSquirrel)
include(SuperTux/ProvideTinygettext)
include(SuperTux/ProvideSDL2_ttf)
include(SuperTux/ProvideDiscord)
include(SuperTux/ProvideSexpcpp)
include(SuperTux/ProvideSavePNG)
include(SuperTux/ProvidePartioZip)
include(SuperTux/ProvideOpenGL)
include(SuperTux/ProvideTinygettext)

## Build stuff
include(SuperTux/BuildVersion)
Expand All @@ -204,89 +184,87 @@ list(SORT SUPERTUX_SOURCES_C)
list(SORT SUPERTUX_SOURCES_CXX)
list(SORT SUPERTUX_RESOURCES)

## On Windows, add an icon
if(WIN32)
if(MINGW)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o
COMMAND ${CMAKE_RC_COMPILER} -I${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons -i${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc -o ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o)
set(SUPERTUX_SOURCES_C ${SUPERTUX_SOURCES_C} ${CMAKE_CURRENT_BINARY_DIR}/supertux_rc.o)
endif()
endif()

include(SuperTux/CompileAmalgation)

## Generate supertux executable in the right place

# Is this needed? - Swagtoy
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})

## Add target for supertux binary

add_library(supertux2_c OBJECT ${SUPERTUX_SOURCES_C})
add_library(supertux2_lib STATIC ${CMAKE_BINARY_DIR}/version.h ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_RESOURCES} $<TARGET_OBJECTS:supertux2_c>)
target_include_directories(supertux2_lib PUBLIC ${CMAKE_BINARY_DIR} src/)
add_executable(supertux2 WIN32 ${CMAKE_BINARY_DIR}/version.h ${SUPERTUX_SOURCES_C} ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_RESOURCES} src/main.cpp)
# TODO Is this even needed?
# $<$<BOOL:WIN32>:{CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc>
target_include_directories(supertux2 PUBLIC ${CMAKE_BINARY_DIR} src/)

if(WIN32)
add_executable(supertux2 WIN32 src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.rc)
target_link_libraries(supertux2 LibSDL2main)
else()
add_executable(supertux2 src/main.cpp)
endif()
target_link_libraries(supertux2 supertux2_lib)

set_target_properties(supertux2_lib PROPERTIES OUTPUT_NAME supertux2_lib)
set_target_properties(supertux2_lib PROPERTIES COMPILE_FLAGS "${SUPERTUX2_EXTRA_WARNING_FLAGS}")
if(EMSCRIPTEN)
target_link_options(supertux2 PUBLIC -sEXPORTED_FUNCTIONS=['_main','_set_resolution','_save_config','_onDownloadProgress','_onDownloadFinished','_onDownloadError','_onDownloadAborted','_getExceptionMessage'] PUBLIC -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'])
endif()
set_target_properties(supertux2 PROPERTIES OUTPUT_NAME "supertux2")
set_target_properties(supertux2 PROPERTIES COMPILE_FLAGS "${SUPERTUX2_EXTRA_WARNING_FLAGS}")

if(WIN32 AND NOT VCPKG_BUILD)
if(NOT MINGW)
#if(WIN32 AND NOT VCPKG_BUILD)
#if(NOT MINGW)
## Copy dlls on windows
add_custom_command(TARGET supertux2_lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${DEPENDENCY_FOLDER}/dll"
$<TARGET_FILE_DIR:supertux2_lib>)
endif()
endif()
# add_custom_command(TARGET supertux2_lib POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# "${DEPENDENCY_FOLDER}/dll"
# $<TARGET_FILE_DIR:supertux2_lib>)
#endif()
#endif()

## Some additional include paths
target_include_directories(supertux2_lib SYSTEM PUBLIC
target_include_directories(supertux2 SYSTEM PUBLIC
external/findlocale/
external/obstack/
)


# Include altivec wrapper on ppc
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc.*")
target_include_directories(supertux2_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/ppc)
target_include_directories(supertux2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/ppc)
endif()

# Linking fixes
set_source_files_properties(external/findlocale/findlocale.c PROPERTIES COMPILE_FLAGS -fPIE)
set_source_files_properties(external/obstack/obstack.c PROPERTIES COMPILE_FLAGS -fPIE)
set_target_properties(LibSavePNG PROPERTIES POSITION_INDEPENDENT_CODE ON)

## Link supertux binary with squirrel and other libraries

target_link_libraries(supertux2_lib PUBLIC LibSimpleSquirrel)
target_link_libraries(supertux2_lib PUBLIC LibTinygettext)
target_link_libraries(supertux2_lib PUBLIC LibSexp)
target_link_libraries(supertux2_lib PUBLIC LibSavePNG)
target_link_libraries(supertux2_lib PUBLIC LibPartioZip)
target_link_libraries(supertux2_lib PUBLIC LibOpenAL)
target_link_libraries(supertux2_lib PUBLIC LibGlm)
target_link_libraries(supertux2_lib PUBLIC LibFmt)
target_link_libraries(supertux2_lib PUBLIC LibPhysfs)
target_link_libraries(supertux2 PUBLIC LibSimpleSquirrel)
target_link_libraries(supertux2 PUBLIC LibTinygettext)
target_link_libraries(supertux2 PUBLIC LibSexp)
target_link_libraries(supertux2 PUBLIC LibSavePNG)
target_link_libraries(supertux2 PUBLIC LibPartioZip)
target_link_libraries(supertux2 PUBLIC OpenAL)
target_link_libraries(supertux2 PUBLIC glm)
target_compile_definitions(supertux2 PUBLIC GLM_ENABLE_EXPERIMENTAL)
target_link_libraries(supertux2 PUBLIC fmt)
target_link_libraries(supertux2 PUBLIC PhysFS)

if(NOT EMSCRIPTEN)
target_link_libraries(supertux2_lib PUBLIC LibSDL2_ttf)
target_link_libraries(supertux2_lib PUBLIC LibSDL2 LibSDL2_image)
target_link_libraries(supertux2_lib PUBLIC LibOggVorbis)
target_link_libraries(supertux2_lib PUBLIC LibCurl)
target_link_libraries(supertux2 PUBLIC
# SDL2_image
SDL2_image
# SDL2_ttf
SDL2_ttf
# SDL2 main (windows?)
$<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>
# SDL2
SDL2)
target_link_libraries(supertux2 PUBLIC
Ogg
Vorbis
VorbisFile
)
target_link_libraries(supertux2 PUBLIC CURL::libcurl)
endif()

if(HAVE_OPENGL)
target_link_libraries(supertux2_lib PUBLIC LibOpenGL)
target_link_libraries(supertux2 PUBLIC LibOpenGL)
endif()

if(ENABLE_DISCORD)
target_link_libraries(supertux2_lib PUBLIC LibDiscord)
target_link_libraries(supertux2 PUBLIC LibDiscord)
endif()

## Install stuff
Expand All @@ -296,7 +274,12 @@ include(SuperTux/BuildInstall)
configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )

## Build tests
include(SuperTux/BuildTests)
# TODO Move to CMake Tests
#include(SuperTux/BuildTests)
option(BUILD_TESTS "Build tests" OFF)
if(BUILD_TESTS)
add_subdirectory(tests)
endif()

## CPack/Installation-specific stuff
include(SuperTux/BuildCPack)
Expand Down
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ For ease of use, here are some installation lines for some Linux distributions:

- Ubuntu 18.04/20.04:
```
sudo apt-get update && sudo apt-get install -y cmake build-essential libogg-dev libvorbis-dev libopenal-dev libsdl2-dev libsdl2-image-dev libfreetype6-dev libraqm-dev libcurl4-openssl-dev libglew-dev libharfbuzz-dev libfribidi-dev libglm-dev zlib1g-dev
sudo apt-get update && sudo apt-get install -y cmake build-essential libogg-dev libvorbis-dev libopenal-dev libsdl2-dev libsdl2-image-dev libfreetype6-dev libraqm-dev libcurl4-openssl-dev libglew-dev libharfbuzz-dev libfribidi-dev libglm-dev zlib1g-dev libfmt-dev libsdl2-ttf-dev libphysfs-dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to include these packages in the vcpkg example!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please note that cmake 3.19 isn't in the apt repository of neither Ubuntu 18.04 or Ubuntu 20.04, so this won't work. It may work if you install cmake manually, I didn't test that.

```

- ArchLinux (using sudo, as of August 28th 2024)
```
sudo pacman -S cmake base-devel libogg libvorbis openal sdl2 sdl2_image freetype2 libraqm curl openssl glew harfbuzz fribidi glm zlib
sudo pacman -S cmake base-devel libogg libvorbis openal sdl2 sdl2_image sdl2_ttf freetype2 libraqm curl openssl glew harfbuzz fribidi glm zlib fmt physfs
```

### Linux/UNIX using CMake
Expand Down
15 changes: 15 additions & 0 deletions mk/cmake/Emscripten.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(CMAKE_EXECUTABLE_SUFFIX .html)
set(IS_EMSCRIPTEN_BUILD ON)

set(EM_USE_FLAGS "-sDISABLE_EXCEPTION_CATCHING=0")
set(EM_LINK_FLAGS " -sINITIAL_MEMORY=134217728 -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=536870912 -sERROR_ON_UNDEFINED_SYMBOLS=0 --preload-file ${BUILD_CONFIG_DATA_DIR} --use-preload-plugins -lidbfs.js")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(EM_USE_FLAGS "${EM_USE_FLAGS} -fsanitize=undefined")
set(EM_LINK_FLAGS "${EM_LINK_FLAGS} -fsanitize=undefined -sSAFE_HEAP=1 -sASSERTIONS=1 -sDEMANGLE_SUPPORT=1")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EM_USE_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EM_USE_FLAGS}")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${EM_USE_FLAGS} ${EM_LINK_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${EM_USE_FLAGS} ${EM_LINK_FLAGS}")

target_link_options(supertux2 PUBLIC -sEXPORTED_FUNCTIONS=['_main','_set_resolution','_save_config','_onDownloadProgress','_onDownloadFinished','_onDownloadError','_onDownloadAborted','_getExceptionMessage'] PUBLIC -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'])
83 changes: 83 additions & 0 deletions mk/cmake/SuperTux/AddPackage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# AddPackage.cmake - Portable find_package approach
#
# Copyright (C) 2024 Hyland B. <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

# This monstrosity essentially adds a complex package wrapping
# function, but it's honestly impressive. It essentially tries to
# default to find_package, however, this may not always work,
# especially on *NIX machines or anything weird like that. So, being
# clever, it then tries to go to PkgConfig, which (generally speaking)
# tends to produce more accurate results on *NIX
# machines. Unfortunately, this may not always work (and sometimes by
# design), so then it finally falls back to Supertux's old, weird
# Provide files. And if that fails, then that means the package
# doesn't exist or wasn't installed.

# Usage:
#
# add_package(TARGET SDL2 <-- The output target, a "target alias" (sometimes)
# PKG SDL2 <-- The find_package package, in this case it gets SDL2
# (might look similar to the output target)
# PKG_USE SDL2::SDL2 <-- Specific target from the package we want to alias
# CONFIG <-- (optional) Passed to find_package if its a CONFIG
# REQUIRED <-- (optional) NOT passed to find_package, just a check to
# throw an error if we've exhausted all options.
# PKG_CONFIG sdl2 sdl2_ttf <-- (optional, recommended) List of packages for PkgConfig
# PROVIDES ProvideSDL2 <-- (optional) Fallback to just look at the provided file.
# ) Undecided if I should fall back to a FindXXXX.cmake yet

find_package(PkgConfig)
macro(add_package)
cmake_parse_arguments(addpackage_args
"CONFIG;REQUIRED" "TARGET;PROVIDES;PKG;PKG_USE" "PKG_CONFIG"
${ARGN}
)

# Note: We don't pass "REQUIRED" here because we choose to fallback if it doesn't exist.
# Later, however, we do choose to throw an error based on this flag.
set(addpackage_fp_args "")
if (${addpackage_args_CONFIG})
string(APPEND addpackage_fp_args "CONFIG")
endif()

find_package(${addpackage_args_PKG} ${addpackage_fp_args})

if(${addpackage_args_PKG}_FOUND)
# See if its an alias (Is this needed?)
get_target_property(addpackage_pkg_alias_check ${addpackage_args_PKG_USE} ALIASED_TARGET)
if (addpackage_pkg_alias_check STREQUAL "addpackage_pkg_alias_check-NOTFOUND")
add_library(${addpackage_args_TARGET} ALIAS ${addpackage_args_PKG_USE})
else()
message(STATUS "Package \"${addpackage_args_PKG}\" is an alias. Realiasing it.")
# "unalias" it, aka just export the "alias" as the new target, so a re-alias, really...
get_target_property(${addpackage_args_TARGET} ${addpackage_args_PKG_USE} ALIASED_TARGET)
endif()
else()
#message(STATUS "CMake Package \"${addpackage_args_PKG}\" doesn't exist, so falling back to PkgConfig")

if (PkgConfig_FOUND)
if (${addpackage_args_REQUIRED})
list(APPEND addpackage_args_pkg_config_args REQUIRED)
endif()
pkg_check_modules(${addpackage_args_TARGET} ${addpackage_args_pkg_config_args} ${addpackage_args_PKG_CONFIG})
elseif(addpackage_args_REQUIRED)
# TODO look in Provides
message(FATAL_ERROR "Package \"${addpackage_args_TARGET}\" couldn't be found, but it's required.\nI don't know what to do. Is it installed?")
endif()
endif()
endmacro(add_package)
6 changes: 3 additions & 3 deletions mk/cmake/SuperTux/BuildInstall.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if(WIN32 AND NOT UNIX)
install(DIRECTORY $<TARGET_FILE_DIR:supertux2_lib>/
DESTINATION ${INSTALL_SUBDIR_BIN}
FILES_MATCHING PATTERN "*.dll")
#install(DIRECTORY $<TARGET_FILE_DIR:supertux2>/
# DESTINATION ${INSTALL_SUBDIR_BIN}
# FILES_MATCHING PATTERN "*.dll")

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.png
${CMAKE_CURRENT_SOURCE_DIR}/data/images/engine/icons/supertux.ico
Expand Down
Loading