Fix building via CMake.

This commit is contained in:
Maschell 2020-09-05 12:58:27 +02:00
parent 8f5dcdfd35
commit 40c0efcb59
6 changed files with 91 additions and 9 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ build-pc-win/
data/images/button.png.h
data/images/button.png.o
src/resources/filelist.h
cmake-build/

View File

@ -45,4 +45,59 @@ find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(SDL2_mixer REQUIRED)
target_link_libraries(${PROJECT_NAME} SDL2::Main SDL2::Image SDL2::TTF SDL2::Mixer)
enable_language(ASM )
include(ExternalProject)
ExternalProject_Add(bin2s_git
PREFIX vendor/
GIT_REPOSITORY https://github.com/Maschell/bin2s
GIT_TAG master
GIT_SUBMODULES
UPDATE_COMMAND ""
PATCH_COMMAND ""
BUILD_COMMAND ""
CMAKE_ARGS
"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
INSTALL_COMMAND
"${CMAKE_COMMAND}"
--build .
--target install
--config Release)
add_executable(bin2s IMPORTED GLOBAL)
set_target_properties(bin2s PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/vendor/bin/bin2s)
add_dependencies(bin2s bin2s_git)
function(add_binfile_library target_name)
if (NOT ${ARGC} GREATER 1)
message(FATAL_ERROR "add_binfile_library : Argument error (no input files)")
endif()
get_cmake_property(_enabled_languages ENABLED_LANGUAGES)
if (NOT _enabled_languages MATCHES ".*ASM.*")
message(FATAL_ERROR "add_binfile_library : ASM language needs to be enabled")
endif()
set(_output_dir ${CMAKE_CURRENT_BINARY_DIR}/binfile_asm)
set(_output_file ${_output_dir}/${target_name}.s)
file(MAKE_DIRECTORY ${_output_dir})
add_custom_command(OUTPUT ${_output_file}
COMMAND bin2s -o "${_output_file}" ${ARGN}
DEPENDS ${ARGN}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
add_library(${target_name} ${_output_file})
endfunction()
add_binfile_library(resources data/fonts/FreeSans.ttf
data/sounds/bgMusic.ogg
data/sounds/button_click.mp3
data/images/button.png
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CMAKE_BUILD_")
target_link_libraries(${PROJECT_NAME} SDL2::Main SDL2::Image SDL2::TTF SDL2::Mixer resources)

View File

@ -1,5 +1,14 @@
# Building
## With CMake
Make sure you have installed `build-essential make git cmake libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-dev`. Then you can do:
```
# Build the filelist.h
bash ./filelist.sh
#
mkdir build && cd build && cmake .. && make
```
## Windows binaries
### Windows with devkitPros version of msys2

View File

@ -39,12 +39,10 @@ cat <<EOF > $outFile
* NOTE:
* Any manual modification of this file will be overwriten by the generation.
****************************************************************************/
#ifndef _FILELIST_H_
#define _FILELIST_H_
#pragma once
#include "Resources.h"
#ifndef _CMAKE_BUILD_
EOF
for i in ${files[@]}
@ -69,7 +67,30 @@ done
echo -e '\t{NULL, NULL, 0, NULL, 0}' >> $outFile
echo '};' >> $outFile
echo '' >> $outFile
echo '#else' >> $outFile
for i in ${files[@]}
do
filename=${i%.*}
extension=${i##*.}
echo 'extern uint8_t '$filename'_'$extension'[];' >> $outFile
echo 'extern uint32_t '$filename'_'$extension'_size;' >> $outFile
done
echo '' >> $outFile
echo 'static RecourceFile RecourceList[] =' >> $outFile
echo '{' >> $outFile
for i in ${files[@]}
do
filename=${i%.*}
extension=${i##*.}
echo -e '\t{"'$i'", (uint8_t*)&'$filename'_'$extension', '$filename'_'$extension'_size, NULL, 0},' >> $outFile
done
echo -e '\t{NULL, NULL, 0, NULL, 0}' >> $outFile
echo '};' >> $outFile
echo '' >> $outFile
echo '#endif' >> $outFile
fi

View File

@ -48,7 +48,6 @@ bool CheckRunning(){
int main(int argc, char *args[]) {
auto *system = new SDLSystem();
#if defined _WIN32
// Create the Console
AllocConsole();

View File

@ -18,9 +18,6 @@ MainWindow::~MainWindow() {
}
MainWindow::MainWindow(int32_t w, int32_t h, Renderer* renderer) : GuiFrame(w, h) {
#if defined _WIN32
Resources::LoadFiles(".");
#endif
auto picture_path = "button.png";
auto font_path = "FreeSans.ttf";
auto bgMusic_path = "bgMusic.ogg";