Commit fc0789b0 authored by Philip Trettner's avatar Philip Trettner

cleaned up cmake a bit, added base64 code

parent a245238b
......@@ -21,21 +21,24 @@ set(GLOW_AUTO_PROFILING ON CACHE BOOL "If true and aion target is present, glow
set(GLOW_VALIDATION ON CACHE BOOL "If true, checks if glow is initialized and called from the correct thread (very low performance impact)")
set(GLOW_CHECK_CXX_STANDARD ON CACHE BOOL "If true, checks if C++ standard is set globally (this is strongly recommended)")
set(GLOW_EXPERIMENTAL_THREAD_AGNOSTIC OFF CACHE BOOL "If true, glow does not use thread local and leaves thread management to the user")
set(GLOW_CMAKE_REPORT OFF CACHE BOOL "If true, prints a more elaborate report in cmake")
# binary dir
if (NOT GLOW_BIN_DIR)
set(GLOW_BIN_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(GLOW_BIN_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} PARENT_SCOPE)
message("set GLOW_BIN_DIR to ${GLOW_BIN_DIR}")
message(STATUS "[glow] set GLOW_BIN_DIR to ${GLOW_BIN_DIR}")
endif()
# ==================================
# Basics
include(cmake/basic-setup.cmake)
message(STATUS "GLOW CMake Config")
message(STATUS " Operating System : ${OPERATING_SYSTEM}")
message(STATUS " Compiler : ${COMPILER}")
message(STATUS " OpenGL : ${GLOW_OPENGL_SUPPORT}")
if (GLOW_CMAKE_REPORT)
message(STATUS "GLOW CMake Config")
message(STATUS " Operating System : ${OPERATING_SYSTEM}")
message(STATUS " Compiler : ${COMPILER}")
message(STATUS " OpenGL : ${GLOW_OPENGL_SUPPORT}")
endif()
if(MSVC)
set(GLOW_LINK_TYPE STATIC CACHE STRING "" FORCE) # unfortunately, we need to link statically here
......@@ -47,7 +50,7 @@ endif()
if (GLOW_CHECK_CXX_STANDARD)
if (NOT "${CMAKE_CXX_STANDARD}" GREATER 10)
message(FATAL_ERROR "CMAKE_CXX_STANDARD is less than 11, please specify at least SET(CMAKE_CXX_STANDARD 11)")
message(FATAL_ERROR "[glow] CMAKE_CXX_STANDARD is less than 17, please specify at least SET(CMAKE_CXX_STANDARD 17)")
endif()
endif()
......@@ -186,7 +189,7 @@ endif()
# Qt if found
if(Qt5Gui_FOUND)
message(STATUS "Found Qt GUI, building with Qt support.")
message(STATUS "[glow] found Qt GUI, building with Qt support.")
target_link_libraries(glow PUBLIC ${Qt5Gui_LIBRARIES})
target_compile_definitions(glow PUBLIC GLOW_USE_QT)
endif()
......@@ -218,7 +221,7 @@ endif()
# AION
if(GLOW_AUTO_PROFILING)
if (TARGET aion)
message(STATUS "Building with aion-profiling ('aion' target found and auto-profiling active)")
message(STATUS "[glow] building with aion-profiling ('aion' target found and auto-profiling active)")
target_link_libraries(glow PUBLIC aion)
target_compile_definitions(glow PUBLIC GLOW_AION_PROFILING)
endif()
......@@ -226,33 +229,35 @@ endif()
# ==================================
# Report
message(STATUS "")
message(STATUS "**************************************")
message(STATUS "GLOW CMake Report")
message(STATUS "")
message(STATUS " Linked Libraries:")
get_target_property(GLOW_LIBS glow INTERFACE_LINK_LIBRARIES)
foreach(v ${GLOW_LIBS})
message(STATUS " * ${v}")
endforeach()
message(STATUS "")
message(STATUS " Defines:")
get_target_property(GLOW_DEFINES glow INTERFACE_COMPILE_DEFINITIONS)
foreach(v ${GLOW_DEFINES})
message(STATUS " * ${v}")
endforeach()
message(STATUS "")
message(STATUS " Compile Options:")
get_target_property(GLOW_COMPILE_OPTIONS glow INTERFACE_COMPILE_OPTIONS)
foreach(v ${GLOW_COMPILE_OPTIONS})
message(STATUS " * ${v}")
endforeach()
message(STATUS "")
message(STATUS " Include directories:")
get_target_property(GLOW_INCLUDE_DIRECTORIES glow INTERFACE_INCLUDE_DIRECTORIES)
foreach(v ${GLOW_INCLUDE_DIRECTORIES})
message(STATUS " * ${v}")
endforeach()
message(STATUS "")
message(STATUS "**************************************")
message(STATUS "")
if(GLOW_CMAKE_REPORT)
message(STATUS "")
message(STATUS "**************************************")
message(STATUS "GLOW CMake Report")
message(STATUS "")
message(STATUS " Linked Libraries:")
get_target_property(GLOW_LIBS glow INTERFACE_LINK_LIBRARIES)
foreach(v ${GLOW_LIBS})
message(STATUS " * ${v}")
endforeach()
message(STATUS "")
message(STATUS " Defines:")
get_target_property(GLOW_DEFINES glow INTERFACE_COMPILE_DEFINITIONS)
foreach(v ${GLOW_DEFINES})
message(STATUS " * ${v}")
endforeach()
message(STATUS "")
message(STATUS " Compile Options:")
get_target_property(GLOW_COMPILE_OPTIONS glow INTERFACE_COMPILE_OPTIONS)
foreach(v ${GLOW_COMPILE_OPTIONS})
message(STATUS " * ${v}")
endforeach()
message(STATUS "")
message(STATUS " Include directories:")
get_target_property(GLOW_INCLUDE_DIRECTORIES glow INTERFACE_INCLUDE_DIRECTORIES)
foreach(v ${GLOW_INCLUDE_DIRECTORIES})
message(STATUS " * ${v}")
endforeach()
message(STATUS "")
message(STATUS "**************************************")
message(STATUS "")
endif()
......@@ -15,7 +15,9 @@ endif()
set(GLAD_PATH "${GLAD_PROFILE}-${GLAD_VERSION}")
string(TOLOWER ${GLAD_PATH} GLAD_PATH)
message(STATUS "including glad ${GLAD_PATH}")
if (GLOW_CMAKE_REPORT)
message(STATUS "including glad ${GLAD_PATH}")
endif()
add_library(glad ${GLOW_LINK_TYPE}
${GLAD_PATH}/src/glad.c
......
#include "base64.hh"
#include <cctype>
static std::string_view constexpr base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static int find_base64_char(unsigned char c)
{
for (auto i = 0; i < int(base64_chars.size()); ++i)
if (base64_chars[i] == c)
return i;
return -1;
}
static bool is_base64(unsigned char c) { return (isalnum(c) || (c == '+') || (c == '/')); }
std::string glow::base64_encode(array_view<std::byte const> data)
{
std::string ret;
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
for (auto b : data)
{
char_array_3[i++] = (unsigned char)b;
if (i == 3)
{
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (i = 0; (i < 4); i++)
ret += base64_chars[char_array_4[i]];
i = 0;
}
}
if (i)
{
for (j = i; j < 3; j++)
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (j = 0; (j < i + 1); j++)
ret += base64_chars[char_array_4[j]];
while ((i++ < 3))
ret += '=';
}
return ret;
}
std::vector<std::byte> glow::base64_decode(std::string_view encoded_string)
{
int in_len = static_cast<int>(encoded_string.size());
int i = 0;
int j = 0;
int in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
std::vector<std::byte> ret;
while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
{
char_array_4[i++] = encoded_string[in_];
in_++;
if (i == 4)
{
for (i = 0; i < 4; i++)
char_array_4[i] = find_base64_char(char_array_4[i]) & 0xff;
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (i = 0; (i < 3); i++)
ret.push_back(std::byte(char_array_3[i]));
i = 0;
}
}
if (i)
{
for (j = 0; j < i; j++)
char_array_4[j] = find_base64_char(char_array_4[j]) & 0xff;
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
for (j = 0; (j < i - 1); j++)
ret.push_back(std::byte(char_array_3[j]));
}
return ret;
}
#pragma once
/*
base64.cc and base64.hh
Copyright (C) 2004-2008 René Nyffenegger
This source code is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
with modifications to fit better with glow
*/
#include <string>
#include <string_view>
#include <vector>
#include <cstdint>
#include <glow/common/array_view.hh>
namespace glow
{
std::string base64_encode(array_view<std::byte const> data);
std::vector<std::byte> base64_decode(std::string_view encoded_string);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment