Skip to content

Commit

Permalink
Drop cpp14 build (drogonframework#1740)
Browse files Browse the repository at this point in the history
* Drop C++14 Support

* Update README.md

* Remove drogon::optional in favor of std::optional

* Remove drogon::filesystem in favor of std::filesystem

* Remove boost::string_view and pre-c++17 hacks

* Remove boost::any

* Remove the string_view.h and the any.h

* Remove boost lib

* Update .clang-format and ci

Co-authored-by: Omar Mohamed <[email protected]>
Co-authored-by: Ken Matsui <[email protected]>
Co-authored-by: An Tao <[email protected]>
Co-authored-by: albaropereyra22 <[email protected]>
Co-authored-by: Yoshihiro Hokazono <[email protected]>
Co-authored-by: Omar Mohamed Khallaf <[email protected]>
  • Loading branch information
7 people committed Aug 23, 2023
1 parent f361995 commit 17c8050
Show file tree
Hide file tree
Showing 259 changed files with 1,789 additions and 1,039 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ RawStringFormats:
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SeparateDefinitionBlocks: Always
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
Expand Down
48 changes: 14 additions & 34 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,20 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
buildname: 'ubuntu-20.04/gcc'
- os: ubuntu-22.04
buildname: 'ubuntu-22.04/gcc'
link: SHARED
triplet: x64-linux
compiler: gcc_64
- os: ubuntu-20.04
buildname: 'ubuntu-20.04/gcc'
- os: ubuntu-22.04
buildname: 'ubuntu-22.04/gcc'
link: STATIC
triplet: x64-linux
compiler: gcc_64
- os: ubuntu-20.04
buildname: 'ubuntu-20.04/gcc-10'
- os: ubuntu-22.04
buildname: 'ubuntu-22.04/gcc-10'
link: STATIC
triplet: x64-linux
- os: ubuntu-20.04
buildname: 'ubuntu-20.04/c++14'
link: STATIC
triplet: x64-linux
compiler: gcc_64
- os: macos-latest
buildname: 'macos/clang'
link: STATIC
Expand All @@ -112,18 +107,14 @@ jobs:
sudo apt-get install -y libjsoncpp-dev uuid-dev libssl-dev zlib1g-dev libsqlite3-dev
sudo apt-get install -y libbrotli-dev
- name: (Linux) Install gcc-10
if: matrix.buildname == 'ubuntu-20.04/gcc-10'
if: matrix.buildname == 'ubuntu-22.04/gcc-10'
run: sudo apt-get install -y gcc-10 g++-10
- name: (Linux) Install boost
if: matrix.buildname == 'ubuntu-20.04/c++14'
run: |
sudo apt-get update
sudo apt-get -y install libboost-all-dev

- name: (Linux) Install postgresql
if: matrix.os == 'ubuntu-20.04'
run: sudo apt-get -y install postgresql-all

if: matrix.os == 'ubuntu-22.04'
run: |
sudo apt-get --purge remove postgresql postgresql-doc postgresql-common postgresql-client-common
sudo apt-get -y install postgresql-all
- name: Export `shared`
run: |
[[ ${{ matrix.link }} == "SHARED" ]] && shared="ON" || shared="OFF"
Expand All @@ -132,7 +123,7 @@ jobs:
- name: Create Build Environment & Configure Cmake
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
if: matrix.buildname != 'ubuntu-20.04/gcc-10' && matrix.buildname != 'ubuntu-20.04/c++14'
if: matrix.buildname != 'ubuntu-22.04/gcc-10'
run: |
cmake -B build \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
Expand All @@ -142,7 +133,7 @@ jobs:
- name: Create Build Environment & Configure Cmake (gcc-10)
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
if: matrix.buildname == 'ubuntu-20.04/gcc-10'
if: matrix.buildname == 'ubuntu-22.04/gcc-10'
run: |
cmake -B build \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
Expand All @@ -153,17 +144,6 @@ jobs:
CC: gcc-10
CXX: g++-10

- name: Create Build Environment & Configure Cmake (C++14)
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
if: matrix.buildname == 'ubuntu-20.04/C++14'
run: |
cmake -B build \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DBUILD_TESTING=on \
-DCMAKE_CXX_STANDARD=14 \
-DBUILD_SHARED_LIBS=$shared
- name: Build
working-directory: ./build
# Execute the build. You can specify a specific target with "--target <NAME>"
Expand Down Expand Up @@ -197,7 +177,7 @@ jobs:
run: ./test.sh -t

- name: Lint
if: matrix.os == 'ubuntu-20.04'
if: matrix.os == 'ubuntu-22.04'
run: |
sudo apt install -y dos2unix
./format.sh && git diff --exit-code
78 changes: 20 additions & 58 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
set(DROGON_CXX_STANDARD ${CMAKE_CXX_STANDARD})
elseif (HAS_ANY AND HAS_STRING_VIEW AND HAS_COROUTINE)
set(DROGON_CXX_STANDARD 20)
elseif (HAS_ANY AND HAS_STRING_VIEW)
set(DROGON_CXX_STANDARD 17)
else ()
set(DROGON_CXX_STANDARD 14)
set(DROGON_CXX_STANDARD 17)
endif ()
if(USE_SUBMODULE)
target_include_directories(
Expand Down Expand Up @@ -135,69 +133,37 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/)
find_package(Filesystem COMPONENTS Final)
if(CXX_FILESYSTEM_HAVE_FS)
message(STATUS "Found std::filesystem")
else ()
message(FATAL_ERROR "Not found std::filesystem, please use a newer compiler")
endif()

# Check for C++ filesystem support
set(NEED_BOOST_FS 0)
if (DROGON_CXX_STANDARD EQUAL 14)
# With C++14, use Boost to support any and string_view
message(STATUS "use c++14")
find_package(Boost 1.61.0 REQUIRED)
message(STATUS "Using Boost filesystem, string_view and any")
message(STATUS "Boost include dir: " ${Boost_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost)
list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${Boost_INCLUDE_DIR})
set(NEED_BOOST_FS 1)
elseif (DROGON_CXX_STANDARD EQUAL 17)
# With C++17, use Boost if std::filesystem::path is missing
if (DROGON_CXX_STANDARD EQUAL 17)
message(STATUS "use c++17")

# Check for partial implementation of c++17 (Windows/OSX only?)
if (CXX_FILESYSTEM_HAVE_FS)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
try_compile(check_filesystem_path ${CMAKE_BINARY_DIR}/cmaketest
${PROJECT_SOURCE_DIR}/cmake/tests/check_has_std_filesystem_path.cc
CXX_STANDARD 17)
set(CMAKE_TRY_COMPILE_TARGET_TYPE)
if (NOT check_filesystem_path)
message(STATUS "The std::filesystem seems to be a partial implementation"
" Falling back to boost::filesystem")
set(NEED_BOOST_FS 1)
endif()
else()
set(NEED_BOOST_FS 1)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
try_compile(check_filesystem_path ${CMAKE_BINARY_DIR}/cmaketest
${PROJECT_SOURCE_DIR}/cmake/tests/check_has_std_filesystem_path.cc
CXX_STANDARD 17)
set(CMAKE_TRY_COMPILE_TARGET_TYPE)
if (NOT check_filesystem_path)
message(FATAL_ERROR "The std::filesystem seems to be a partial implementation,"
" please use a newer compiler")
endif()
else ()
message(STATUS "use c++20")
endif ()

# Workaround: 2021-08-09 Android NDK does not provide proper std::filesystem
# support. Force boost::filesystem instead.
if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
message(STATUS "WORKAROUND: Forcing boost::filesystem on Android")
set(NEED_BOOST_FS 1)
endif ()

if(NEED_BOOST_FS)
find_package(Boost 1.49.0 COMPONENTS filesystem system REQUIRED)
message(STATUS "Using Boost filesytem::path")
message(STATUS "Boost include dir: " ${Boost_INCLUDE_DIR})
include_directories(${BOOST_INCLUDE_DIRS})
message(STATUS "Boost libraries: " ${Boost_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC Boost::filesystem Boost::system)
list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${Boost_INCLUDE_DIR})
option(HAS_STD_FILESYSTEM_PATH "use boost::filesystem" OFF)
else()
option(HAS_STD_FILESYSTEM_PATH "use std::filesystem" ON)
# HACK: Needed to be compiled on Yocto Linux
if(TARGET std::filesystem)
get_property(CAN_LINK_FS TARGET std::filesystem PROPERTY INTERFACE_LINK_LIBRARIES SET)
if ( CAN_LINK_FS )
target_link_libraries(${PROJECT_NAME} PUBLIC std::filesystem)
endif()
endif()
option(HAS_STD_FILESYSTEM_PATH "use std::filesystem" ON)
# HACK: Needed to be compiled on Yocto Linux
if(TARGET std::filesystem)
get_property(CAN_LINK_FS TARGET std::filesystem PROPERTY INTERFACE_LINK_LIBRARIES SET)
if ( CAN_LINK_FS )
target_link_libraries(${PROJECT_NAME} PUBLIC std::filesystem)
endif()
endif()


# jsoncpp
find_package(Jsoncpp REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC Jsoncpp_lib)
Expand Down Expand Up @@ -316,7 +282,6 @@ set(private_headers
lib/src/AOPAdvice.h
lib/src/CacheFile.h
lib/src/ConfigLoader.h
lib/src/filesystem.h
lib/src/FiltersFunction.h
lib/src/HttpAppFrameworkImpl.h
lib/src/HttpClientImpl.h
Expand Down Expand Up @@ -720,14 +685,11 @@ set(NOSQL_HEADERS
install(FILES ${NOSQL_HEADERS} DESTINATION ${INSTALL_INCLUDE_DIR}/drogon/nosql)

set(DROGON_UTIL_HEADERS
lib/inc/drogon/utils/any.h
lib/inc/drogon/utils/apply.h
lib/inc/drogon/utils/coroutine.h
lib/inc/drogon/utils/FunctionTraits.h
lib/inc/drogon/utils/HttpConstraint.h
lib/inc/drogon/utils/optional.h
lib/inc/drogon/utils/OStringStream.h
lib/inc/drogon/utils/string_view.h
lib/inc/drogon/utils/Utilities.h)
install(FILES ${DROGON_UTIL_HEADERS}
DESTINATION ${INSTALL_INCLUDE_DIR}/drogon/utils)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

English | [简体中文](./README.zh-CN.md) | [繁體中文](./README.zh-TW.md)
### Overview
**Drogon** is a C++14/17-based HTTP application framework. Drogon can be used to easily build various types of web application server programs using C++. **Drogon** is the name of a dragon in the American TV series "Game of Thrones" that I really like.
**Drogon** is a C++17/20 based HTTP application framework. Drogon can be used to easily build various types of web application server programs using C++. **Drogon** is the name of a dragon in the American TV series "Game of Thrones" that I really like.

Drogon is a cross-platform framework, It supports Linux, macOS, FreeBSD, OpenBSD, HaikuOS, and Windows. Its main features are as follows:

Expand Down
4 changes: 0 additions & 4 deletions cmake/templates/DrogonConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ endif()
if(@MySQL_FOUND@)
find_dependency(MySQL)
endif()
if(@Boost_FOUND@)
find_dependency(Boost)
find_package(Boost COMPONENTS filesystem system)
endif()
if(@Brotli_FOUND@)
find_dependency(Brotli)
endif()
Expand Down
4 changes: 4 additions & 0 deletions drogon_ctl/CommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ class CommandHandler : public virtual drogon::DrObjectBase
{
public:
virtual void handleCommand(std::vector<std::string> &parameters) = 0;

virtual bool isTopCommand()
{
return false;
}

virtual std::string script()
{
return "";
}

virtual std::string detail()
{
return "";
}

virtual ~CommandHandler()
{
}
Expand Down
1 change: 1 addition & 0 deletions drogon_ctl/create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <iostream>
#include <memory>
using namespace drogon_ctl;

std::string create::detail()
{
return "Use create command to create some source files of drogon webapp\n\n"
Expand Down
4 changes: 4 additions & 0 deletions drogon_ctl/create.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@
#include <drogon/DrObject.h>
#include "CommandHandler.h"
using namespace drogon;

namespace drogon_ctl
{
class create : public DrObject<create>, public CommandHandler
{
public:
void handleCommand(std::vector<std::string> &parameters) override;

std::string script() override
{
return "create some source files(Use 'drogon_ctl help create' for more "
"information)";
}

bool isTopCommand() override
{
return true;
}

std::string detail() override;
};
} // namespace drogon_ctl
3 changes: 3 additions & 0 deletions drogon_ctl/create_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ void create_controller::newSimpleControllerHeaderFile(
file << "}\n";
}
}

void create_controller::newSimpleControllerSourceFile(
std::ofstream &file,
const std::string &className,
Expand Down Expand Up @@ -207,6 +208,7 @@ void create_controller::newWebsockControllerHeaderFile(
file << "}\n";
}
}

void create_controller::newWebsockControllerSourceFile(
std::ofstream &file,
const std::string &className,
Expand Down Expand Up @@ -303,6 +305,7 @@ void create_controller::newHttpControllerHeaderFile(
file << "}\n";
}
}

void create_controller::newHttpControllerSourceFile(
std::ofstream &file,
const std::string &className,
Expand Down
2 changes: 2 additions & 0 deletions drogon_ctl/create_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
#include <drogon/DrTemplateBase.h>
#include "CommandHandler.h"
using namespace drogon;

namespace drogon_ctl
{
class create_controller : public DrObject<create_controller>,
public CommandHandler
{
public:
void handleCommand(std::vector<std::string> &parameters) override;

std::string script() override
{
return "create controller files";
Expand Down
1 change: 1 addition & 0 deletions drogon_ctl/create_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static void createFilterSourceFile(std::ofstream &file,
data.insert("filename", fileName);
file << templ->genText(data);
}

void create_filter::handleCommand(std::vector<std::string> &parameters)
{
if (parameters.size() < 1)
Expand Down
2 changes: 2 additions & 0 deletions drogon_ctl/create_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include <drogon/DrObject.h>
#include "CommandHandler.h"
using namespace drogon;

namespace drogon_ctl
{
class create_filter : public DrObject<create_filter>, public CommandHandler
{
public:
void handleCommand(std::vector<std::string> &parameters) override;

std::string script() override
{
return "create filter class files";
Expand Down
Loading

0 comments on commit 17c8050

Please sign in to comment.