Move to CMake

This commit is contained in:
zvon 2021-08-05 00:33:55 +02:00
parent bfe658618e
commit 040b3b63c2
3 changed files with 63 additions and 108 deletions

1
mario/.gitignore vendored
View File

@ -4,3 +4,4 @@ mario
editor editor
.DS_Store .DS_Store
*bin *bin
build

62
mario/CMakeLists.txt Normal file
View File

@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
enable_language(CXX)
include(ExternalProject)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
project(Mario)
list(APPEND CommonFiles
global_vars.cpp
sprites.cpp
maploader.cpp
mapobject.cpp
blocks/simpleblocks.cpp
mario.cpp
blocks.cpp
)
set(SDLPPDir ${CMAKE_CURRENT_SOURCE_DIR}/../sdlpp)
add_library(sdlpp STATIC IMPORTED)
set_target_properties(sdlpp PROPERTIES
IMPORTED_LOCATION libsdlpp.a
)
ExternalProject_Add(sdlpp_external
SOURCE_DIR ${SDLPPDir}
CONFIGURE_COMMAND ""
BUILD_COMMAND make libsdlpp.a
BUILD_IN_SOURCE 1
INSTALL_COMMAND install -m 644 "${SDLPPDir}/libsdlpp.a" ${CMAKE_CURRENT_BINARY_DIR}
)
add_executable(mario
${CommonFiles}
main.cpp
visitors/mario_visitor.cpp
visitors/bounce_visitor.cpp
visitors/visitor_generator.cpp
blocks/coinblock.cpp
)
add_executable(editor
${CommonFiles}
blocks/coineditorblock.cpp
editor.cpp
edit_box.cpp
tool_box.cpp
editor_visitor.cpp
)
target_compile_definitions(editor PUBLIC EDITOR)
target_link_libraries(mario PRIVATE sdlpp)
target_link_libraries(editor PRIVATE sdlpp)
target_link_libraries(mario PRIVATE SDL2 SDL2_image SDL2_gfx SDL2_ttf Threads::Threads)
target_link_libraries(editor PRIVATE SDL2 SDL2_image SDL2_gfx SDL2_ttf Threads::Threads)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/testfont.ttf ${CMAKE_CURRENT_SOURCE_DIR}/sprites DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

View File

@ -1,108 +0,0 @@
PREFIX ?= /usr/local/bin
EDITORFLAGS = -DEDITOR
ifeq ($(OS),Windows_NT)
UNAME_S := Windows
CXX = cl
CXXFLAGS = -MD -EHsc
OBJEXT = obj
LDFLAGS =
OUTPUTFLAG = -Fo
else
UNAME_S := $(shell uname -s)
CXX ?= g++
CXXFLAGS = -std=c++14 -Wall -Wextra -pedantic -O2 -DDEBUG -DFEATURE #-g -fsanitize=address
OBJEXT = o
LDFLAGS ?= -lSDL2 -lSDL2_image -lSDL2_gfx -lSDL2_ttf -pthread
OUTPUTFLAG = -o
endif
COMMON_OBJECTS = global_vars.${OBJEXT} sprites.${OBJEXT} maploader.${OBJEXT} mapobject.${OBJEXT} coineditorblock.${OBJEXT} coinblock.${OBJEXT} simpleblocks.${OBJEXT} mario.${OBJEXT}
ifneq ($(UNAME_S),Windows)
COMMON_OBJECTS += libsdlpp.a
endif
MARIO_OBJECTS = main.${OBJEXT} blocks.${OBJEXT} mario_visitor.${OBJEXT} bounce_visitor.${OBJEXT} visitor_generator.${OBJEXT} ${COMMON_OBJECTS}
EDITOR_OBJECTS = editor.${OBJEXT} editor_blocks.${OBJEXT} edit_box.${OBJEXT} tool_box.${OBJEXT} editor_visitor.${OBJEXT} ${COMMON_OBJECTS}
ifeq ($(UNAME_S),Windows)
MARIO_OBJECTS += ../sdlpp/SDL2/SDL2_framerate.c ../sdlpp/SDL2/SDL2_gfxPrimitives.c ../sdlpp/SDL2/SDL2_imageFilter.c ../sdlpp/SDL2/SDL2_rotozoom.c
EDITOR_OBJECTS += ../sdlpp/SDL2/SDL2_framerate.c ../sdlpp/SDL2/SDL2_gfxPrimitives.c ../sdlpp/SDL2/SDL2_imageFilter.c ../sdlpp/SDL2/SDL2_rotozoom.c
SDLLIB = libsdlpp.dll
endif
.PHONY: default
default: mario
ifeq ($(UNAME_S),Windows)
mario: ${MARIO_OBJECTS} ${SDLLIB}
$(CXX) $(CXXFLAGS) -Fe"$@" ${MARIO_OBJECTS} /link ..\sdlpp\SDL2.lib ..\sdlpp\SDL2_ttf.lib ..\sdlpp\SDL2_image.lib libsdlpp.lib
editor: ${EDITOR_OBJECTS} ${SDLLIB}
$(CXX) $(CXXFLAGS) ${EDITORFLAGS} -Fe"$@" ${EDITOR_OBJECTS} /link ..\sdlpp\SDL2.lib ..\sdlpp\SDL2_ttf.lib ..\sdlpp\SDL2_image.lib libsdlpp.lib
else
mario: ${MARIO_OBJECTS}
$(CXX) $(CXXFLAGS) -o $@ $^ ${LDFLAGS} -L $(shell pwd)
editor: ${EDITOR_OBJECTS}
$(CXX) $(CXXFLAGS) ${EDITORFLAGS} -o $@ $^ ${LDFLAGS} -L $(shell pwd)
endif
main.${OBJEXT}: main.cpp ../sdlpp/sdlpp.hpp sprites.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
blocks.${OBJEXT}: blocks.cpp ../sdlpp/sdlpp.hpp blocks.hpp sprites.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
editor_blocks.${OBJEXT}: blocks.cpp ../sdlpp/sdlpp.hpp blocks.hpp sprites.hpp
$(CXX) $(CXXFLAGS) ${EDITORFLAGS} -c ${OUTPUTFLAG}$@ $<
global_vars.${OBJEXT}: global_vars.cpp ../sdlpp/sdlpp.hpp global_vars.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
sprites.${OBJEXT}: sprites.cpp ../sdlpp/sdlpp.hpp sprites.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
maploader.${OBJEXT}: maploader.cpp ../sdlpp/sdlpp.hpp maploader.hpp sprites.hpp blocks.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
mario_visitor.${OBJEXT}: visitors/mario_visitor.cpp ../sdlpp/sdlpp.hpp visitors/mario_visitor.hpp objectids.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
bounce_visitor.${OBJEXT}: visitors/bounce_visitor.cpp ../sdlpp/sdlpp.hpp visitors/bounce_visitor.hpp objectids.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
visitor_generator.${OBJEXT}: visitors/visitor_generator.cpp ../sdlpp/sdlpp.hpp visitors/visitor_generator.hpp objectids.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
editor.${OBJEXT}: editor.cpp ../sdlpp/sdlpp.hpp sprites.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
edit_box.${OBJEXT}: edit_box.cpp ../sdlpp/sdlpp.hpp sprites.hpp edit_box.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
tool_box.${OBJEXT}: tool_box.cpp ../sdlpp/sdlpp.hpp sprites.hpp tool_box.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
editor_visitor.${OBJEXT}: editor_visitor.cpp ../sdlpp/sdlpp.hpp sprites.hpp editor_visitor.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
coineditorblock.${OBJEXT}: blocks/coineditorblock.cpp ../sdlpp/sdlpp.hpp sprites.hpp global_vars.hpp blocks.hpp blocks/coineditorblock.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
coinblock.${OBJEXT}: blocks/coinblock.cpp ../sdlpp/sdlpp.hpp sprites.hpp global_vars.hpp blocks.hpp blocks/coinblock.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
simpleblocks.${OBJEXT}: blocks/simpleblocks.cpp ../sdlpp/sdlpp.hpp sprites.hpp global_vars.hpp blocks.hpp blocks/simpleblocks.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
mapobject.${OBJEXT}: mapobject.cpp ../sdlpp/sdlpp.hpp objectids.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
mario.${OBJEXT}: mario.cpp ../sdlpp/sdlpp.hpp mario.hpp global_vars.hpp objectids.hpp sprites.hpp ../sdlpp/sdlpp_rectrenderer.hpp
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
libsdlpp.a: ../sdlpp
$(MAKE) clean -C ../sdlpp
$(MAKE) libsdlpp.a -C ../sdlpp
cp ../sdlpp/libsdlpp.a .
libsdlpp.dll:
$(MAKE) clean -C ../sdlpp
$(MAKE) -C ../sdlpp
cp ../sdlpp/libsdlpp.dll .
cp ../sdlpp/libsdlpp.lib .
windows_release: ../Release/Mario mario editor ${SDLLIB}
cp -R ${SDLLIB} mario.exe editor.exe sprites testfont.ttf ../Release/Mario
rm -f ../Release/Mario.zip
cd ../Release && zip -r Mario.zip Mario
start:
LD_LIBRARY_PATH=$$(pwd) ./mario
start_edit:
LD_LIBRARY_PATH=$$(pwd) ./editor
clean:
${RM} *.dll *.lib *.a *.${OBJEXT} mario editor