Skip to content

Commit

Permalink
cmake update 3
Browse files Browse the repository at this point in the history
  • Loading branch information
xtreme8000 committed Aug 23, 2019
1 parent 546120a commit 35559ab
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 32 deletions.
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
cmake_minimum_required(VERSION 2.8)
project(BetterSpades C)

add_subdirectory(src)
set(BETTERSPADES_MAJOR 0)
set(BETTERSPADES_MINOR 1)
set(BETTERSPADES_PATCH 4)

option(ENABLE_TOUCH "Enable touch support including ingame overlay" OFF)
option(ENABLE_ANDROID_FILE "Use SDL's file functions" OFF)
option(ENABLE_OPENGLES "Build for OpenGL ES" OFF)
option(ENABLE_SDL "Build against SDL backend" OFF)
option(ENABLE_GLFW "Build against GLFW3 backend" ON)
option(ENABLE_SOUND "Enable sound support using OpenAL" ON)

if((ENABLE_ANDROID_FILE OR ENABLE_TOUCH OR ENABLE_OPENGLES) AND NOT ENABLE_SDL)
message(FATAL_ERROR "Enable SDL to use ENABLE_ANDROID_FILE, ENABLE_TOUCH or ENABLE_OPENGLES")
endif()
if(ENABLE_SDL AND ENABLE_GLFW)
message(FATAL_ERROR "Only one backend must be selected")
endif()
if(NOT ENABLE_SDL AND NOT ENABLE_GLFW)
message(FATAL_ERROR "Enable SDL or GLFW")
endif()

add_subdirectory(src)
2 changes: 1 addition & 1 deletion cmake/Modules/Findenet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (enet_FOUND)
IMPORTED_LOCATION ${enet_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${enet_INCLUDE_DIR}
)
target_include_directories(enet::enet INTERFACE ${enet_INCLUDE_DIR})
#target_include_directories(enet::enet INTERFACE ${enet_INCLUDE_DIR})
if (WIN32)
set_target_properties(enet::enet PROPERTIES
INTERFACE_LINK_LIBRARIES "ws2_32;winmm"
Expand Down
45 changes: 45 additions & 0 deletions cmake/Modules/Findglfw3.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#.rst:
# Findglfw3
# -------
#
# Finds the glfw3 library
#
# This will define the following variables::
#
# glfw3_FOUND - True if the system has the glfw3 library
#
# and also the following imported target:
#
# glfw3::glfw3
#
find_package(PkgConfig)
pkg_check_modules(PC_glfw3 QUIET glfw3)

find_path(glfw3_INCLUDE_DIR
NAMES GLFW/glfw3.h
PATHS ${PC_glfw3_INCLUDE_DIRS} ../../deps
PATH_SUFFIXES GLFW
)
find_library(glfw3_LIBRARY
NAMES glfw
PATHS ${PC_glfw3_LIBRARY_DIRS} ../../deps
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(glfw3
FOUND_VAR glfw3_FOUND
REQUIRED_VARS
glfw3_LIBRARY
glfw3_INCLUDE_DIR
)

if (glfw3_FOUND)
add_library(glfw3::glfw3 STATIC IMPORTED)
set_target_properties(glfw3::glfw3 PROPERTIES
IMPORTED_LOCATION ${glfw3_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${glfw3_INCLUDE_DIR}
)
endif (glfw3_FOUND)
56 changes: 49 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ macro(download_file_if_it_doesnt_exist filename url)
list(GET stat 0 success)
list(GET stat 1 error)
if (NOT ${success})
message(STATUS "Downloaded ${filename} succesfully")
message(STATUS "Downloaded ${filename} successfully")
else()
file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/${filename})
message(FATAL_ERROR "Failed to download ${filename} (${error})")
Expand All @@ -24,6 +24,7 @@ download_file_if_it_doesnt_exist(parson.h https://raw.githubusercontent.com/kgab
download_file_if_it_doesnt_exist(http.h https://raw.githubusercontent.com/mattiasgustavsson/libs/master/http.h)
download_file_if_it_doesnt_exist(log.h https://raw.githubusercontent.com/xtreme8000/log.c/master/src/log.h)
download_file_if_it_doesnt_exist(log.c https://raw.githubusercontent.com/xtreme8000/log.c/master/src/log.c)
download_file_if_it_doesnt_exist(../deps/libdeflate.h https://raw.githubusercontent.com/ebiggers/libdeflate/master/libdeflate.h)
download_file_if_it_doesnt_exist(../bsresources.zip http://aos.party/bsresources.zip)

list(APPEND CLIENT_SOURCES aabb.c)
Expand Down Expand Up @@ -63,6 +64,31 @@ add_executable(client ${CLIENT_SOURCES})
target_compile_definitions(client PRIVATE DR_WAV_IMPLEMENTATION)
target_compile_definitions(client PRIVATE LOG_USE_COLOR)

if(ENABLE_TOUCH)
target_compile_definitions(client PRIVATE USE_TOUCH)
endif()
if(ENABLE_ANDROID_FILE)
target_compile_definitions(client PRIVATE USE_ANDROID_FILE)
endif()
if(ENABLE_OPENGLES)
target_compile_definitions(client PRIVATE OPENGL_ES)
endif()
if(ENABLE_SDL)
target_compile_definitions(client PRIVATE USE_SDL)
endif()
if(ENABLE_GLFW)
target_compile_definitions(client PRIVATE USE_GLFW)
endif()
if(ENABLE_SOUND)
target_compile_definitions(client PRIVATE USE_SOUND)
endif()

target_compile_definitions(client PRIVATE BETTERSPADES_MAJOR=${BETTERSPADES_MAJOR})
target_compile_definitions(client PRIVATE BETTERSPADES_MINOR=${BETTERSPADES_MINOR})
target_compile_definitions(client PRIVATE BETTERSPADES_PATCH=${BETTERSPADES_PATCH})
target_compile_definitions(client PRIVATE BETTERSPADES_VERSION="v${BETTERSPADES_MAJOR}.${BETTERSPADES_MINOR}.${BETTERSPADES_PATCH}")


set_target_properties(
client PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${BetterSpades_SOURCE_DIR}/build/BetterSpades
Expand All @@ -72,16 +98,32 @@ set_target_properties(
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${BetterSpades_SOURCE_DIR}/deps)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${BetterSpades_SOURCE_DIR}/cmake/Modules)
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(OpenAL REQUIRED)
if(ENABLE_GLFW)
find_package(glfw3 REQUIRED)
target_link_libraries(client glfw3::glfw3)
endif()
if(ENABLE_SDL)
find_package(SDL REQUIRED)
target_link_libraries(client ${SDL_LIBRARY})
endif()
if(ENABLE_SOUND)
find_package(OpenAL REQUIRED)
target_link_libraries(client ${OPENAL_LIBRARY})
endif()
find_package(enet REQUIRED)
find_package(deflate REQUIRED)
find_package(Threads REQUIRED)
find_package(GLEW REQUIRED)
if(NOT ENABLE_OPENGLES)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
target_link_libraries(client GLEW::GLEW)
else()
find_package(OpenGL REQUIRED COMPONENTS EGL)
target_link_libraries(client OpenGL::EGL)
endif()

target_link_libraries(client ${CMAKE_THREAD_LIBS_INIT} glfw GLEW OpenGL::GL ${OPENAL_LIBRARY} enet::enet deflate::deflate m)
include_directories(client ${OPENAL_INCLUDE_DIRS})
target_link_libraries(client ${CMAKE_THREAD_LIBS_INIT} ${OPENGL_LIBRARIES} enet::enet deflate::deflate m)
include_directories(client ${OPENAL_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR} ${OPENGL_EGL_INCLUDE_DIRS})

add_custom_command(
TARGET client
Expand Down
22 changes: 4 additions & 18 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,16 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#define BETTERSPADES_VERSION "v0.1.4"

#define BETTERSPADES_PATCH 4
#define BETTERSPADES_MINOR 1
#define BETTERSPADES_MAJOR 0

#define USE_GLFW
#define USE_SOUND
//#define USE_SDL

//for android define these:
//#define USE_TOUCH
//#define USE_ANDROID_FILE

#ifndef OPENGL_ES
#define GLEW_STATIC
#include <GL/glew.h>

#include <enet/enet.h>
#else
#ifdef USE_SDL
#include "SDL2/SDL_opengles.h"
#include <SDL2/SDL_opengles.h>
#endif
#include "enet/enet.h"
#include <enet/enet.h>

void glColor3f(float r, float g, float b);
void glColor3ub(unsigned char r, unsigned char g, unsigned char b);
Expand All @@ -49,11 +35,11 @@
#endif

#ifdef USE_GLFW
#include "GLFW/glfw3.h"
#include <GLFW/glfw3.h>
#endif

#ifdef USE_SDL
#include "SDL2/SDL.h"
#include <SDL2/SDL.h>
#endif

#include <stdlib.h>
Expand Down
10 changes: 7 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void chat_showpopup(const char* msg, float duration, int color) {
chat_popup_color = color;
}

void drawScene(float dt) {
void drawScene() {
if(settings.ambient_occlusion) {
glShadeModel(GL_SMOOTH);
} else {
Expand All @@ -85,7 +85,11 @@ void drawScene(float dt) {
chunk_draw_visible();

if(settings.smooth_fog) {
glFogi(GL_FOG_MODE,GL_EXP2);
#ifdef OPENGL_ES
glFogx(GL_FOG_MODE,GL_EXP2);
#else
glFogi(GL_FOG_MODE,GL_EXP2);
#endif
glFogf(GL_FOG_DENSITY,0.015F);
glFogfv(GL_FOG_COLOR,fog_color);
glEnable(GL_FOG);
Expand Down Expand Up @@ -231,7 +235,7 @@ void display(float dt) {
if(!network_map_transfer) {

glx_enable_sphericalfog();
drawScene(dt);
drawScene();

grenade_update(dt);
tracer_update(dt);
Expand Down
6 changes: 6 additions & 0 deletions src/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ void texture_init() {
texture_create(&texture_ui_alert,"png/ui/alert.png");
texture_filter(&texture_ui_alert,TEXTURE_FILTER_LINEAR);

#ifdef USE_TOUCH
texture_create(&texture_ui_knob,"png/ui/knob.png");
texture_filter(&texture_ui_knob,TEXTURE_FILTER_LINEAR);
texture_create(&texture_ui_joystick,"png/ui/joystick.png");
texture_filter(&texture_ui_joystick,TEXTURE_FILTER_LINEAR);
#endif

unsigned int* pixels = malloc(64*64*sizeof(unsigned int));
CHECK_ALLOCATION_ERROR(pixels)
Expand Down
4 changes: 2 additions & 2 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ void window_init() {
glfwSetScrollCallback(hud_window->impl,window_impl_mousescroll);
glfwSetCharCallback(hud_window->impl,window_impl_textinput);

if(glfwRawMouseMotionSupported())
glfwSetInputMode(hud_window->impl,GLFW_RAW_MOUSE_MOTION,GLFW_TRUE);
// if(glfwRawMouseMotionSupported())
// glfwSetInputMode(hud_window->impl,GLFW_RAW_MOUSE_MOTION,GLFW_TRUE);
}

void window_fromsettings() {
Expand Down

0 comments on commit 35559ab

Please sign in to comment.