Skip to content
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

Windows compatibility #5

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
af78166
Add initial conanfile with all ibrary dependencies
zmanuel Jan 26, 2023
4b76f45
Add nooby instructions
zmanuel Jan 26, 2023
4bafa43
line end whitespace
zmanuel Jan 27, 2023
9216d6a
baby steps towards CMake integration
zmanuel Jan 27, 2023
6d022d0
Add macOS prerequisite installation
zmanuel Jan 27, 2023
2e26f48
Separate SYSTEM includes
zmanuel Jan 27, 2023
3fad969
Correct include for apple platforms
zmanuel Jan 27, 2023
a9f4b60
Add freealut to macOS and Linux prerequisites
zmanuel Jan 27, 2023
de8f1d0
Only conditionally link stdc++ff
zmanuel Jan 28, 2023
c47392c
Actually check for OpenAL, use detected library
zmanuel Jan 28, 2023
37db31c
Use correct SDL2 libraries
zmanuel Jan 28, 2023
2d67c4b
Merge branch 'macos' into conan
zmanuel Jan 28, 2023
1c68251
Make conan use optional
zmanuel Jan 29, 2023
81062ad
Further include corrections
zmanuel Jan 29, 2023
14ca57e
Allow multiple build directories
zmanuel Jan 29, 2023
b2d4200
Make conan dependencies more flexible
zmanuel Jan 29, 2023
40f8650
Activate shared libraries
zmanuel Jan 29, 2023
fb68991
Additional fishy zlib conflict resolution
zmanuel Jan 29, 2023
7e39fc9
Narrow down doxygen version
zmanuel Jan 29, 2023
59dd727
Add DLL/dynlib imports
zmanuel Jan 29, 2023
f4435ec
This seems to be the modern unified way to deal with dependencies
zmanuel Feb 16, 2023
5ebd932
macOS compatibility
zmanuel Feb 17, 2023
094f19c
Move find_library further up
zmanuel Feb 17, 2023
bde1b58
Windows does not support shared sdl_ttf
zmanuel Feb 17, 2023
d7b837f
Conan reworking
zmanuel Feb 17, 2023
11cd193
Remove options
zmanuel Feb 17, 2023
b10293a
make OpenAL optional
zmanuel Feb 17, 2023
dd039ca
Define preprocessor symbol if OpenAL is available
zmanuel Feb 17, 2023
c8ea7ec
Disable sound if OpenAL is unavailable
zmanuel Feb 17, 2023
78b3301
Activate symbol exports on Windows
zmanuel Feb 18, 2023
8ff9622
Windows: Copy dll into examples directory
zmanuel Feb 18, 2023
3109aea
Non-Windows workaround
zmanuel Feb 18, 2023
35cb07d
Add Windows system preparation/build instructions
zmanuel Feb 18, 2023
20fa459
Disable binreloc on Windows
zmanuel Feb 18, 2023
29d807c
filesystem::path wstring problem
zmanuel Feb 18, 2023
dd2e92a
Move chaining constructors to cpp file
zmanuel Feb 18, 2023
c38b16b
More Windows disabling
zmanuel Feb 27, 2023
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
build
/build*
docs/html
41 changes: 34 additions & 7 deletions BUILDING
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
How to build cerritos

1. Install dependencies
cmake libsdl2 doxygen graphviz libsdl2-image-dev libsdl2-ttf-dev
Linux (package names may vary), in Terminal:
> {your packager} libsdl2 doxygen graphviz libsdl2-image-dev libsdl2-ttf-dev freealut-dev

macOS:
Get XCode: https://developer.apple.com/support/xcode/
Get Homebrew via https://brew.sh/; then, in Terminal:
> brew install sdl2 doxygen graphviz sdl2_image sdl2_ttf freealut

Windows:
Install Visual Studio, for example the 2022 Community Edition: https://visualstudio.microsoft.com/de/vs/community/
Only the C++ Desktop Development package should be required.
In cmd (all a bit more involved as Windows is lacking some basic tools):
> winget install Git.Git
> winget install cmake
> winget install python
optional: Visual Studio Code editor, not required for building:
> winget install code

disable python alias via Settings -> Manage App Execution Aliases (use search)
DO NOT install Microsoft store version of python, its path settings seem broken

In Git Bash (installed with git), install pip (https://pip.pypa.io/en/stable/installation/)
> py -m ensurepip --upgrade
then install conan over pip (https://docs.conan.io/en/2.0/installation.html):
> pip install conan --upgrade

2. Create build directory
mkdir build
cd build
> mkdir build
> cd build

3: Get Dependencies via Conan (Optional on Linux and macOS if nothing went wrong in step 1, required on Windows):
> conan install .. --build=missing

3. Run cmake
cmake ../
4. Run cmake
> cmake ..

4. Build!
make
5. Build!
> cmake --build .

TODO: Make this document a lot more detailed.

29 changes: 23 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,34 @@ cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# create .lib file on Windows (alternative: export specifically all desired symbols with dllexport, make that a NOP on Unix platforms)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# set the project name
project(cerritos VERSION 0.1.0)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

include(sdl)
INCLUDE(FindPkgConfig)
#find_package(SDL_ttf REQUIRED)
#PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image)
PKG_SEARCH_MODULE(SDL2TTF REQUIRED SDL2_ttf)
# optionally include conan generated file
set(CONAN_FILE_TO_INCLUDE ${CMAKE_BINARY_DIR}/conan_paths.cmake)
if(EXISTS ${CONAN_FILE_TO_INCLUDE})
include(${CONAN_FILE_TO_INCLUDE})
endif()

#include(sdl)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(OpenAL)

if(OPENAL_FOUND)
find_path(ALUT_INCLUDE_DIR
NAMES AL/alut.h)
find_library(ALUT_LIBRARY
NAMES alut
HINTS lib lib64
PATH /usr /usr/local /opt/local /sw)
endif(OPENAL_FOUND)

# The actual cerritos sources
add_subdirectory(src)
Expand Down
2 changes: 1 addition & 1 deletion cmake/sdl.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
include_directories(SYSTEM ${SDL2_INCLUDE_DIRS})


31 changes: 31 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# standard conan instructions?
# make a new build directory, change into it
# install dependencies with
# conan install <path to source> --build=missing

[requires]
sdl/[^2.0,>=2.0.14]
sdl_ttf/[^2.0,>=2.0.15]
sdl_image/[^2.0,>=2.0.5]

# conflict resolution
libpng/[^1.6] # odd that this is enough, but no complaining
[tool_requires]

# the conan version of doxygen does not work the way we exect, so don't use it (for now)
#doxygen/[^1.9,<=1.9.2]
# 1.9.4 locks zlib to a higher version than one of its dependencies, causing irresolvable conflicts here

# graphviz is not in Conan. Figures, it is a perl program.
# Hope it is optional or can be manually installed if needed.

[generators]
cmake_find_package
cmake_paths
CMakeDeps
CMakeToolchain

[imports]
# copy macOS and Windows dynamic libraries to where they can be found
bin, *.dll -> ./bin
lib, *.dylib* -> ./bin
7 changes: 7 additions & 0 deletions examples/dadsteroids.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ target_include_directories(dadsteroids PUBLIC
target_link_libraries(dadsteroids
cerritos
)

# copy dll on windows into binary directory
if(WIN32)
add_custom_command(TARGET dadsteroids POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:dadsteroids> $<TARGET_RUNTIME_DLLS:dadsteroids> $<TARGET_FILE_DIR:dadsteroids>
)
endif(WIN32)
4 changes: 2 additions & 2 deletions examples/dasteroids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Ship : public Sprite {
void Fire() {
m_Fired = true;
m_Bullet = new Bullet();
m_Bullet->setBackground(_PATH.getFilepath("share", "bullet.bmp"));
m_Bullet->setBackground(_PATH.getFilepath("share", "bullet.bmp").u8string());
m_Bullet->setPosition(this->getPosition());
m_Bullet->setHeading(this->getHeading());
m_Bullet->setSpeed(2.0);
Expand Down Expand Up @@ -112,7 +112,7 @@ class ftApplication : public Application {

m_Ship = new Ship(getMainWindow()->getWindow(), 200,200, 40, 40, 1 );

m_Ship->setBackground(_PATH.getFilepath("share", "dadship.png"));
m_Ship->setBackground(_PATH.getFilepath("share", "dadship.png").u8string());

m_Ship->setPosition(200,200);

Expand Down
7 changes: 7 additions & 0 deletions examples/drumTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ target_include_directories(drumTest PUBLIC
target_link_libraries(drumTest
cerritos
)

# copy dll on windows into binary directory
if(WIN32)
add_custom_command(TARGET drumTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:drumTest> $<TARGET_RUNTIME_DLLS:drumTest> $<TARGET_FILE_DIR:drumTest>
)
endif(WIN32)
6 changes: 6 additions & 0 deletions examples/eventTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ target_link_libraries(eventTest
cerritos
)

# copy dll on windows into binary directory
if(WIN32)
add_custom_command(TARGET eventTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eventTest> $<TARGET_RUNTIME_DLLS:eventTest> $<TARGET_FILE_DIR:eventTest>
)
endif(WIN32)
7 changes: 7 additions & 0 deletions examples/fontTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ target_include_directories(fontTest PUBLIC
target_link_libraries(fontTest
cerritos
)

# copy dll on windows into binary directory
if(WIN32)
add_custom_command(TARGET fontTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:fontTest> $<TARGET_RUNTIME_DLLS:fontTest> $<TARGET_FILE_DIR:fontTest>
)
endif(WIN32)
6 changes: 6 additions & 0 deletions examples/hello.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ target_link_libraries(hello
cerritos
)

# copy dll on windows into binary directory
if(WIN32)
add_custom_command(TARGET hello POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:hello> $<TARGET_RUNTIME_DLLS:hello> $<TARGET_FILE_DIR:hello>
)
endif(WIN32)
7 changes: 7 additions & 0 deletions examples/pathTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ target_include_directories(pathTest PUBLIC
target_link_libraries(pathTest
cerritos
)

# copy dll on windows into binary directory
if(WIN32)
add_custom_command(TARGET pathTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pathTest> $<TARGET_RUNTIME_DLLS:pathTest> $<TARGET_FILE_DIR:pathTest>
)
endif(WIN32)
6 changes: 6 additions & 0 deletions examples/spriteTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ target_link_libraries(spriteTest
cerritos
)

# copy dll on windows into binary directory
if(WIN32)
add_custom_command(TARGET spriteTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:spriteTest> $<TARGET_RUNTIME_DLLS:spriteTest> $<TARGET_FILE_DIR:spriteTest>
)
endif(WIN32)
22 changes: 11 additions & 11 deletions examples/spriteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ int main( int argc, char* args[] ) {
theSprite = new Sprite(theWindow->getWindow(), 0, 0, 64, 64, 10);
theOtherSprite = new Sprite(theWindow->getWindow(), 250, 250, 64, 64, 1);

List<String> dancing = {_PATH.getFilepath("share", "boimlerdance00.bmp"),
_PATH.getFilepath("share", "boimlerdance01.bmp"),
_PATH.getFilepath("share", "boimlerdance02.bmp"),
_PATH.getFilepath("share", "boimlerdance01.bmp") };
List<String> dancing = {_PATH.getFilepath("share", "boimlerdance00.bmp").u8string(),
_PATH.getFilepath("share", "boimlerdance01.bmp").u8string(),
_PATH.getFilepath("share", "boimlerdance02.bmp").u8string(),
_PATH.getFilepath("share", "boimlerdance01.bmp").u8string() };

List<String> walking = {_PATH.getFilepath("share", "boimlerdance10.bmp"),
_PATH.getFilepath("share", "boimlerdance11.bmp"),
_PATH.getFilepath("share", "boimlerdance12.bmp"),
_PATH.getFilepath("share", "boimlerdance13.bmp"),
_PATH.getFilepath("share", "boimlerdance14.bmp"),
_PATH.getFilepath("share", "boimlerdance12.bmp") };
List<String> walking = {_PATH.getFilepath("share", "boimlerdance10.bmp").u8string(),
_PATH.getFilepath("share", "boimlerdance11.bmp").u8string(),
_PATH.getFilepath("share", "boimlerdance12.bmp").u8string(),
_PATH.getFilepath("share", "boimlerdance13.bmp").u8string(),
_PATH.getFilepath("share", "boimlerdance14.bmp").u8string(),
_PATH.getFilepath("share", "boimlerdance12.bmp").u8string() };

List<String> ship = {_PATH.getFilepath("share", "spaceship.bmp")};
List<String> ship = {_PATH.getFilepath("share", "spaceship.bmp").u8string()};

theSprite->addSpriteMode(0, dancing);
theSprite->setDefaultMode(1);
Expand Down
42 changes: 29 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ install(FILES
DESTINATION include
)

target_include_directories(cerritos PUBLIC
${SDL2_LIBRARIES}
${SDL2IMAGE_INCLUDE_DIRS}
${SDL2TTF_INCLUDE_DIRS}
${OPENAL_INCLUDE_DIRS}
target_include_directories(cerritos BEFORE PUBLIC
.
backend
core
Expand All @@ -85,16 +81,36 @@ target_include_directories(cerritos PUBLIC
widgets
)

target_link_libraries(cerritos
${SDL2_LIBRARIES}
${SDL2IMAGE_LIBRARIES}
${SDL2TTF_LIBRARIES}
${OPENAL_LIBRARIES}
alut
stdc++fs
stdc++
target_include_directories(cerritos SYSTEM PUBLIC
${SDL2_INCLUDE_DIRS}
${SDL2IMAGE_INCLUDE_DIRS}
${SDL2TTF_INCLUDE_DIRS}
)

target_link_libraries(cerritos PUBLIC
SDL2::SDL2
SDL2::SDL2main
SDL2_image::SDL2_image
SDL2_ttf::SDL2_ttf
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.1>>:stdc++fs>
)

if(OPENAL_FOUND)
# having this PUBLIC is probably bad style, but the ALUT definitions
# are required in a header right now...
target_compile_definitions(cerritos PUBLIC USING_OPENAL)

target_include_directories(cerritos SYSTEM PUBLIC
${OPENAL_INCLUDE_DIR}
${ALUT_INCLUDE_DIR}
)

target_link_libraries(cerritos PUBLIC
${OPENAL_LIBRARY}
${ALUT_LIBRARY}
)
endif(OPENAL_FOUND)

install(TARGETS cerritos
EXPORT cerritos
LIBRARY DESTINATION lib
Expand Down
2 changes: 1 addition & 1 deletion src/core/imagemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Surface* ImageManager::loadFromFile(const char* filename) {
}

Surface* ImageManager::loadPath(String searchpath, String filename) {
return loadFromFile(_PATH.getFilepath(searchpath, filename) );
return loadFromFile(_PATH.getFilepath(searchpath, filename).u8string() );
}

Surface* ImageManager::loadFromFile(String filename) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void Path::m_initialize(const char* programName, bool overwrite) {
return;

if(programName != NULL) {
p_name = Dirpath(programName).filename();
p_name = Dirpath(programName).filename().u8string();
} else {
p_name = getProgramNameFile();
}
Expand Down Expand Up @@ -184,7 +184,7 @@ void Path::setAssetDir(String newAssetdir) {
}

String Path::getProgramNameFile() {
return String(m_ProgramName.filename() );
return m_ProgramName.filename().u8string();
}

void Path::setProgramName(String programName) {
Expand All @@ -204,7 +204,7 @@ void Path::showPaths() {
const Dirpath Path::getFilepath(String searchpath, String filename, bool useSysDirs) {
if (m_AllPaths.has_key(searchpath)) {
// Found the path
return String( (m_AllPaths[searchpath] / filename).c_str() );
return (m_AllPaths[searchpath] / filename).u8string();
}

return String("");
Expand Down
8 changes: 4 additions & 4 deletions src/core/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ class Path {
const Dirpath getFilepath(String searchpath, String filename, bool useSysDirs=false);

/// Overloaded member for convenience.
String getFilepath(const char* searchpath, const char* filename, bool useSysDirs=false) {
Dirpath getFilepath(const char* searchpath, const char* filename, bool useSysDirs=false) {
return getFilepath(String(searchpath), String(filename), useSysDirs);
};

/// Overloaded member for convenience.
String getFilepath(String searchpath, const char* filename, bool useSysDirs=false) {
Dirpath getFilepath(String searchpath, const char* filename, bool useSysDirs=false) {
return getFilepath(searchpath, String(filename), useSysDirs);
};

/// Overloaded member for convenience.
String getFilepath(const char* searchpath, String filename, bool useSysDirs=false) {
Dirpath getFilepath(const char* searchpath, String filename, bool useSysDirs=false) {
return getFilepath(String(searchpath), filename, useSysDirs );
};

Expand All @@ -108,7 +108,7 @@ class Path {

String getAssetDir() { return m_AssetDir; };

String getAppPath() { return m_AppPath; };
String getAppPath() { return m_AppPath.u8string(); };

void setPrefix(const char* prefix) {
setPrefix(String(prefix) );
Expand Down
Loading