SDLPP: add .dll target for windows

This commit is contained in:
zv0n 2020-11-22 23:37:55 +01:00
parent 5f40ffe4e1
commit 730a00b8fa
15 changed files with 63 additions and 34 deletions

View File

@ -1,14 +1,17 @@
CXX ?= g++
CPPFLAGS = -std=c++14 -Wall -Wextra -pedantic
MAJOR ?= 1 MAJOR ?= 1
MINOR ?= 0 MINOR ?= 0
RELEASE ?= 0 RELEASE ?= 0
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
UNAME_S := Windows UNAME_S := Windows
CXX = cl
CXXFLAGS = -MD -EHsc /DDLLEXPORT
OBJEXT = obj
else else
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
CXX ?= g++
CXXFLAGS = -std=c++14 -Wall -Wextra -pedantic
OBJEXT = o
endif endif
ifeq ($(UNAME_S),Linux) ifeq ($(UNAME_S),Linux)
@ -19,28 +22,41 @@ ifeq ($(UNAME_S),Darwin)
SDLPPLIBRARY = libsdlpp.dylib SDLPPLIBRARY = libsdlpp.dylib
LIBRARYFLAGS = LIBRARYFLAGS =
endif endif
ifeq ($(UNAME_S),Windows)
SDLPPLIBRARY = libsdlpp.dll
LIBRARYFLAGS =
endif
OBJECTFILES = sdlpp_circlecolider.o sdlpp_circlerenderer.o sdlpp_collision.o sdlpp_common.o sdlpp_font.o sdlpp_linerenderer.o sdlpp_rectcolider.o sdlpp_rectrenderer.o sdlpp_renderer.o sdlpp_renderobject.o sdlpp_scene.o sdlpp_textrenderer.o sdlpp_texture.o sdlpp_window.o OBJECTFILES = sdlpp_circlecolider.${OBJEXT} sdlpp_circlerenderer.${OBJEXT} sdlpp_collision.${OBJEXT} sdlpp_common.${OBJEXT} sdlpp_font.${OBJEXT} sdlpp_linerenderer.${OBJEXT} sdlpp_rectcolider.${OBJEXT} sdlpp_rectrenderer.${OBJEXT} sdlpp_renderer.${OBJEXT} sdlpp_renderobject.${OBJEXT} sdlpp_scene.${OBJEXT} sdlpp_textrenderer.${OBJEXT} sdlpp_texture.${OBJEXT} sdlpp_window.${OBJEXT}
all: ${SDLPPLIBRARY} all: ${SDLPPLIBRARY}
%.o: %.cpp ifeq ($(UNAME_S),Windows)
${CXX} ${CPPFLAGS} ${LIBRARYFLAGS} -c $< -o $@ %.${OBJEXT}: %.cpp
${CXX} ${CXXFLAGS} ${LIBRARYFLAGS} /c $< /Fo"$@"
else
%.${OBJEXT}: %.cpp
${CXX} ${CXXFLAGS} ${LIBRARYFLAGS} -c $< -o $@
endif
ifeq ($(UNAME_S),Linux) ifeq ($(UNAME_S),Linux)
${SDLPPLIBRARY}: ${OBJECTFILES} ${SDLPPLIBRARY}: ${OBJECTFILES}
${CXX} ${CPPFLAGS} -shared -Wl,-soname,libsdlpp.so.${MAJOR}\ ${CXX} ${CXXFLAGS} -shared -Wl,-soname,libsdlpp.so.${MAJOR}\
-o ${SDLPPLIBRARY} $^ -o ${SDLPPLIBRARY} $^
ln -sf ${SDLPPLIBRARY} libsdlpp.so ln -sf ${SDLPPLIBRARY} libsdlpp.so
ln -sf ${SDLPPLIBRARY} libsdlpp.so.${MAJOR} ln -sf ${SDLPPLIBRARY} libsdlpp.so.${MAJOR}
endif endif
ifeq ($(UNAME_S),Darwin) ifeq ($(UNAME_S),Darwin)
${SDLPPLIBRARY}: ${OBJECTFILES} ${SDLPPLIBRARY}: ${OBJECTFILES}
${CXX} ${CPPFLAGS} -dynamiclib -install_name ${SDLPPLIBRARY}\ ${CXX} ${CXXFLAGS} -dynamiclib -install_name ${SDLPPLIBRARY}\
-current_version ${MAJOR}.${MINOR} $^ -lSDL2 -lSDL2_image -lSDL2_gfx -lSDL2_ttf -o $@ -current_version ${MAJOR}.${MINOR} $^ -lSDL2 -lSDL2_image -lSDL2_gfx -lSDL2_ttf -o $@
endif endif
ifeq ($(UNAME_S),Windows)
${SDLPPLIBRARY}: ${OBJECTFILES}
${CXX} /LD $^ /link SDL2.lib SDL2_ttf.lib SDL2_image.lib /OUT:$@ /IMPLIB:libsdlpp.lib
endif
clean: clean:
${RM} *.so* *.o *.dylib ${RM} *.so* *.${OBJEXT} *.dylib libsdlpp*
.PHONY: all clean test .PHONY: all clean test

View File

@ -7,7 +7,7 @@
#include "sdlpp_collision.hpp" #include "sdlpp_collision.hpp"
namespace SDLPP { namespace SDLPP {
class CircleColider : public CollisionPolygon { class SDLPPSCOPE CircleColider : public CollisionPolygon {
public: public:
CircleColider( double x, double y, double rad ); CircleColider( double x, double y, double rad );
virtual ~CircleColider() {} virtual ~CircleColider() {}

View File

@ -7,7 +7,7 @@
#include <memory> #include <memory>
namespace SDLPP { namespace SDLPP {
class CircleRender : public RenderObject { class SDLPPSCOPE CircleRender : public RenderObject {
public: public:
CircleRender() = delete; CircleRender() = delete;
virtual ~CircleRender(){}; virtual ~CircleRender(){};

View File

@ -5,7 +5,7 @@
#include "sdlpp_renderer.hpp" #include "sdlpp_renderer.hpp"
namespace SDLPP { namespace SDLPP {
class CollisionPolygon { class SDLPPSCOPE CollisionPolygon {
public: public:
CollisionPolygon( double x, double y ); CollisionPolygon( double x, double y );
virtual ~CollisionPolygon() {} virtual ~CollisionPolygon() {}
@ -36,9 +36,9 @@ protected:
SDL_Color sdl_outline = { 0, 0, 0, 0 }; SDL_Color sdl_outline = { 0, 0, 0, 0 };
}; };
bool infinityIntersection( const SDLPP::CollisionPolygon &infinite, SDLPPSCOPE bool infinityIntersection( const SDLPP::CollisionPolygon &infinite,
const SDLPP::CollisionPolygon &other ); const SDLPP::CollisionPolygon &other );
bool intersects( const SDLPP::CollisionPolygon &p1, SDLPPSCOPE bool intersects( const SDLPP::CollisionPolygon &p1,
const SDLPP::CollisionPolygon &p2 ); const SDLPP::CollisionPolygon &p2 );
} // namespace SDLPP } // namespace SDLPP
#endif #endif

View File

@ -1,3 +1,16 @@
#ifndef SDLPPSCOPE
#ifdef _WIN32
#ifdef DLLEXPORT
#define SDLPPSCOPE __declspec( dllexport )
#else
#define SDLPPSCOPE __declspec( dllimport )
#endif
#else
#define SDLPPSCOPE
#endif
#endif
#ifndef SDLPP_HPP_COMMON #ifndef SDLPP_HPP_COMMON
#define SDLPP_HPP_COMMON #define SDLPP_HPP_COMMON
@ -22,17 +35,17 @@
namespace SDLPP { namespace SDLPP {
int hex2num( char c ); SDLPPSCOPE int hex2num( char c );
bool init(); SDLPPSCOPE bool init();
bool init( uint32_t SDL_OPTIONS ); SDLPPSCOPE bool init( uint32_t SDL_OPTIONS );
bool init( uint32_t SDL_OPTIONS, int IMAGE_OPTIONS ); SDLPPSCOPE bool init( uint32_t SDL_OPTIONS, int IMAGE_OPTIONS );
std::tuple< int, int, int, int > getColorsHEX( const std::string &color ); SDLPPSCOPE std::tuple< int, int, int, int > getColorsHEX( const std::string &color );
SDL_Color getSDLColorHEX( const std::string &color ); SDLPPSCOPE SDL_Color getSDLColorHEX( const std::string &color );
std::tuple< int, int, int, int > getColorsSDLColor( const SDL_Color &color ); SDLPPSCOPE std::tuple< int, int, int, int > getColorsSDLColor( const SDL_Color &color );
SDL_Color getSDLColorTuple( const std::tuple< int, int, int, int > &tuple ); SDLPPSCOPE SDL_Color getSDLColorTuple( const std::tuple< int, int, int, int > &tuple );
bool getSDLEvent( SDL_Event &e ); SDLPPSCOPE bool getSDLEvent( SDL_Event &e );
} // end of namespace SDLPP } // end of namespace SDLPP
#endif #endif

View File

@ -6,7 +6,7 @@
#include <iostream> #include <iostream>
namespace SDLPP { namespace SDLPP {
class Font { class SDLPPSCOPE Font {
public: public:
Font() = delete; Font() = delete;
Font( const std::string &font, int size ); Font( const std::string &font, int size );

View File

@ -5,7 +5,7 @@
#include "sdlpp_renderobject.hpp" #include "sdlpp_renderobject.hpp"
namespace SDLPP { namespace SDLPP {
class LineRenderer : public RenderObject { class SDLPPSCOPE LineRenderer : public RenderObject {
public: public:
LineRenderer() = delete; LineRenderer() = delete;
virtual ~LineRenderer(){}; virtual ~LineRenderer(){};

View File

@ -7,7 +7,7 @@
#include <limits> #include <limits>
namespace SDLPP { namespace SDLPP {
class RectColider : public CollisionPolygon { class SDLPPSCOPE RectColider : public CollisionPolygon {
public: public:
RectColider( double x, double y, double w, double h ); RectColider( double x, double y, double w, double h );
virtual ~RectColider() {} virtual ~RectColider() {}

View File

@ -6,7 +6,7 @@
#include "sdlpp_rectcolider.hpp" #include "sdlpp_rectcolider.hpp"
namespace SDLPP { namespace SDLPP {
class RectangleRender : public RenderObject { class SDLPPSCOPE RectangleRender : public RenderObject {
public: public:
RectangleRender() = delete; RectangleRender() = delete;
virtual ~RectangleRender(){}; virtual ~RectangleRender(){};

View File

@ -7,7 +7,7 @@
#include <iostream> #include <iostream>
namespace SDLPP { namespace SDLPP {
class Renderer { class SDLPPSCOPE Renderer {
public: public:
Renderer() = delete; Renderer() = delete;
Renderer( Window &window ); Renderer( Window &window );

View File

@ -10,9 +10,9 @@
#include <vector> #include <vector>
namespace SDLPP { namespace SDLPP {
class Scene; class SDLPPSCOPE Scene;
class RenderObject { class SDLPPSCOPE RenderObject {
public: public:
RenderObject( const std::shared_ptr< Renderer > &r ) : renderer( r ) {} RenderObject( const std::shared_ptr< Renderer > &r ) : renderer( r ) {}
virtual ~RenderObject() {} virtual ~RenderObject() {}

View File

@ -11,7 +11,7 @@
#include "sdlpp_renderobject.hpp" #include "sdlpp_renderobject.hpp"
namespace SDLPP { namespace SDLPP {
class Scene { class SDLPPSCOPE Scene {
public: public:
Scene( std::shared_ptr< Renderer > &r ); Scene( std::shared_ptr< Renderer > &r );
void addObject( const std::shared_ptr< RenderObject > &obj ); void addObject( const std::shared_ptr< RenderObject > &obj );

View File

@ -8,7 +8,7 @@
#include <string> #include <string>
namespace SDLPP { namespace SDLPP {
class TextRenderer : public RectangleRender { class SDLPPSCOPE TextRenderer : public RectangleRender {
public: public:
TextRenderer() = delete; TextRenderer() = delete;
TextRenderer( double x, double y, double w, double h, TextRenderer( double x, double y, double w, double h,

View File

@ -8,7 +8,7 @@
#include "sdlpp_renderer.hpp" #include "sdlpp_renderer.hpp"
namespace SDLPP { namespace SDLPP {
class Texture { class SDLPPSCOPE Texture {
public: public:
Texture() = delete; Texture() = delete;
Texture( std::shared_ptr< Renderer > &renderer, Texture( std::shared_ptr< Renderer > &renderer,

View File

@ -6,7 +6,7 @@
#include <iostream> #include <iostream>
namespace SDLPP { namespace SDLPP {
class Window { class SDLPPSCOPE Window {
public: public:
Window(); Window();
Window( const std::string &window_name ); Window( const std::string &window_name );