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

Build instructions and build system refinement #6

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 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
f39e72b
Handle diamond conflicts differently
zmanuel Feb 23, 2023
2618a1f
Add VirtualBuildEnv
zmanuel Feb 23, 2023
4d4d627
Add USE_OPENAL switch
zmanuel Feb 23, 2023
3209e04
Disable cmake toolchain generation
zmanuel Feb 23, 2023
17faeb6
Add USE_CONAN variable to check later
zmanuel Feb 23, 2023
c1935b1
Add cross compilation script
zmanuel Feb 23, 2023
80c3dd9
Make sure we install conan < 2.0
zmanuel Feb 24, 2023
19076eb
Add WIP documentation on how to build in wine
zmanuel Feb 24, 2023
6e1c291
Make versions conan 2.0 compatible
zmanuel Feb 25, 2023
403e92d
Remove iconv dependency from SDL
zmanuel Feb 25, 2023
97c6dd6
Remove futule attempts to fix wine compilation
zmanuel Feb 25, 2023
8e44103
Convert conan config to conanfile.py
zmanuel Feb 25, 2023
ab2a65c
Keep sdl.iconv on macOS
zmanuel Feb 25, 2023
08509bf
Really pass all parameters to CMake
zmanuel Feb 25, 2023
ce9f882
Describe successful compilation in Wine
zmanuel Feb 25, 2023
4a2bf86
Remove note that claims this does not work :)
zmanuel Feb 25, 2023
aeb3543
Try and make conanfile compatible with w64devkit
zmanuel Feb 26, 2023
f0ef42d
Revert "Try and make conanfile compatible with w64devkit"
zmanuel Feb 27, 2023
39f6d84
Add MSYS2 instructions
zmanuel Feb 27, 2023
d684265
Visual Studio SDL also does not have the iconv option
zmanuel Feb 27, 2023
4ca1164
Remove SDLMain from linking
zmanuel Feb 27, 2023
897a786
Add better dependency install information
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
67 changes: 60 additions & 7 deletions BUILDING
Original file line number Diff line number Diff line change
@@ -1,17 +1,70 @@
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
For example, on Arch:
> sudo pacman -S cmake make gcc sdl2 sdl2_ttf sdl2_image openal freealut doxygen graphviz
On Ubuntu:
> sudo apt install cmake make gcc libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libopenal-dev doxygen graphviz

For the optional Conan path, install python, then pip (https://pip.pypa.io/en/stable/installation/)
> python -m ensurepip --upgrade
then install conan over pip (https://docs.conan.io/en/2.0/installation.html):
> pip install 'conan<2.0' --upgrade

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

For the optional Conan path, install python, pip (https://pip.pypa.io/en/stable/installation/)
> python -m ensurepip --upgrade
then install conan over pip (https://docs.conan.io/en/2.0/installation.html):
> pip install 'conan<2.0' --upgrade

Windows via Visual Studio and Conan (will not have OpenAL support):
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<2.0' --upgrade

Windows via MSYS2, a more Unix-like environment (not yet fully functional):
Install MSYS2 (https://www.msys2.org/)
Start a shell in the MINGW32 environment (or, should you want 64 bit binaries, MINGW64)
Install pactoys for easier typing:
> pacman -S pactoys
Install dependencies:
> pacboy -S cmake:p gcc:p SDL2:p SDL2_ttf:p SDL2_image:p openal:p freealut:p doxygen:p graphviz:p
Optionally also make:p for makefile based compilation if you prefer that; the system defaults to ninja.

Cross Compilation:
Look at the scripts and documentation in the crosscompile directory

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

3. Get Dependencies via Conan (Optional on Linux, macOS and MSYS2 if nothing went wrong in step 1, required for Visual Studio):
> 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.

42 changes: 32 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,47 @@ 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)

# The actual cerritos sources
add_subdirectory(src)
# support libraries in thirdparty
# optionally include conan generated file
set(CONAN_FILE_TO_INCLUDE ${CMAKE_BINARY_DIR}/conan_paths.cmake)
set(USE_CONAN OFF)
if(EXISTS ${CONAN_FILE_TO_INCLUDE})
include(${CONAN_FILE_TO_INCLUDE})
set(USE_CONAN ON)
endif()

# Build documentation
option(BUILD_DOC "Build documentation" ON)
option(USE_SDL "Use SDL" ON)
option(USE_OPENAL "Use OpenAL" ON)

#include(sdl)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
if(USE_OPENAL)
find_package(OpenAL)
endif(USE_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)
# support libraries in thirdparty

if(USE_SDL)
target_compile_definitions(cerritos PUBLIC USING_SDL)
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})


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

from conans import ConanFile, CMake

class CerritosConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"

generators = \
"cmake_find_package", \
"cmake_paths", \
"CMakeDeps", \
"VirtualBuildEnv"

requires = \
"sdl/[^2.0 >=2.26.1]", \
"sdl_ttf/[^2.0 >=2.0.15]", \
"sdl_image/[^2.0 >=2.0.5]", \
"libpng/[^1]", \
"xz_utils/[^5]"

# libpng and xy_utils are for conflict resolution; apparently it is enough to just state the conflicting transitive
# dependencies with a broad version specification.


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

def configure(self):
if self.settings.os != "Macos" and self.settings.compiler != "Visual Studio":
self.options["sdl"].iconv = False

def imports(self):
self.copy("*.dll", dst="bin", src="bin")
self.copy("*.dylib", dst="bin", src="lib")
95 changes: 95 additions & 0 deletions crosscompile/linux_to_windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

# Usage: linux_to_windows.sh <arguments to CMake>
# call from your build directory. So, for example, you would do starting from the main source:
# > mkdir build_win64
# > cd build_win64
# > ../crosscompile/linux_to_windows.sh

# Prerequisites (aside from conan and cmake):
# Install mingw-w64
# Ubunutu: sudo apt-get install g++-mingw-w64 gcc-mingw-w64
# Arch: sudo pacman -S mingw-w64-crt

# Documentation this is based on:
# https://docs.conan.io/1/systems_cross_building/cross_building.html#cross-building-examples-profiles
# https://docs.conan.io/2.0/tutorial/consuming_packages/cross_building_with_conan.html
# https://www.aroeira.io/post/cross-compile/

set -x

SOURCE_PATH=$(dirname $(dirname $0))

# see if we need to update the conan configuration
if test "${SOURCE_PATH}"/conanfile.txt -nt conan_paths.cmake || test "$0" -nt conan_paths.cmake; then
rm -f CMakeCache.txt conan.lock conan_paths.cmake

# determine mingw version

# generate profile data
toolchain=/usr/x86_64-w64-mingw32 # Maybe adjust this path
target_host=x86_64-w64-mingw32
cc_compiler=gcc
cxx_compiler=g++

# somehow, one has to set this manually to a cross compiler, or some conan builds fail
export CC=$target_host-$cc_compiler
export CXX=$target_host-$cxx_compiler

# horrible way to fetch conan compliant version from mingw.
# conan expects at most two versions segments, no trailing zero. So 1, 1.1, 2, 2.1, 2.2
# # to here: line with version at the end
# # to here: just the version, bits before cut off
# # to here: cut off any more than two version segments
# # cut off trailing 0
compiler_version=$($target_host-$cc_compiler --version | head -n 1 | sed -e 's/.* //g' | sed -E 's/([^\.]*)\.([^\.]*)\..*/\1.\2/' | sed -e 's/^{0}/\0/')

# compose profle
cat > win64.profile << EOF
toolchain=$toolchain
target_host=$target_host
cc_compiler=$cc_compiler
cxx_compiler=$cxx_compiler

[buildenv]
CONAN_CMAKE_FIND_ROOT_PATH=\$toolchain # Optional, for CMake to find things in that folder
CONAN_CMAKE_SYSROOT=\$toolchain # Optional, if we want to define sysroot
CHOST=\$target_host
AR=\$target_host-ar
AS=\$target_host-as
RANLIB=\$target_host-ranlib
CC=\$target_host-\$cc_compiler
CXX=\$target_host-\$cxx_compiler
STRIP=\$target_host-strip
RC=\$target_host-windres

[settings]
# We are cross-building to Windows
os=Windows
arch=x86_64
compiler=gcc

compiler.version=$compiler_version
#compiler.version=12
compiler.libcxx=libstdc++11
build_type=Release
EOF

#conan install "${SOURCE_PATH}" -pr:b=default -pr:h=win64.profile --no-imports || exit $?

# use the generated profile to make conan install the correct cross compilation libraries
#conan install "${SOURCE_PATH}" --build=missing -s:b os_build=Linux -pr=win64.profile || exit $?
conan install "${SOURCE_PATH}" --build=missing -pr:b=default -pr:h=win64.profile || exit $?
fi

# use the conan provided build environment from here on
source ./conanbuild.sh || exit $?

# build configuration with CMAKE. All further arguments are passed to it
# USE_OPENAL=OFF is required because we can't install OpenAL over conan and
# cmake would pick up a native version, if available
cmake -DUSE_OPENAL=OFF "${SOURCE_PATH}" "$@" || exit $?

# build with maximum paralellism
cmake --build . -j $(( `nproc` + 1 )) || exit $?

Loading