Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
CMake and template generator refactor for conan package (#35)
Browse files Browse the repository at this point in the history
- Updated CMake file to install generated export header file
- Updated installation procedure in root CMake file

- Updated path to template generation command in root CMake
- Updated regular expressions in `TemplateLoader` to include wider range of characters

* Changed `Enjin-CPP-SDK` references to `enjin-cpp-sdk` in `README.md`

- Updated `.gitignore` to ignore `conanfile.py` at project root
- Moved `conanfile.py` to `.conan` folder
- Updated windows workflow to run on 2019 instead of latest
  • Loading branch information
BishopJohnson committed Mar 1, 2022
1 parent 004f445 commit c908a0e
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 92 deletions.
34 changes: 34 additions & 0 deletions .conan/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from conans import ConanFile, CMake, tools


class EnjinCPPSDK(ConanFile):
settings = "os", "compiler", "arch", "build_type"
generators = "cmake"
options = {
"with_default_http_client": [True, False],
"with_default_ws_client": [True, False],
}
default_options = {
"with_default_http_client": False,
"with_default_ws_client": False,
}

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
if tools.get_env("CONAN_RUN_TESTS", True):
cmake.test()

def requirements(self):
if self.options.with_default_http_client:
self.requires("cpp-httplib/0.8.5")
self.options["cpp-httplib"].with_openssl = True

if self.options.with_default_ws_client:
self.requires("ixwebsocket/11.0.4")

self.requires("gtest/1.10.0")
self.requires("rapidjson/1.1.0")
self.requires("spdlog/1.8.2")
self.options["spdlog"].header_only = True
4 changes: 2 additions & 2 deletions .conan/profiles/workflows/ubuntu-latest
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ compiler.version=9
os=Linux
os_build=Linux
[options]
enable_default_http_client=True
enable_default_ws_client=False
with_default_http_client=True
with_default_ws_client=False
[build_requires]
[env]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ compiler=Visual Studio
compiler.version=16
build_type=Release
[options]
enable_default_http_client=True
enable_default_ws_client=True
with_default_http_client=True
with_default_ws_client=True
[build_requires]
[env]
2 changes: 1 addition & 1 deletion .github/workflows/Build & Test Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Setup Conan
run: |
conan install . -if ./build --build missing --profile ./.conan/profiles/workflows/ubuntu-latest
conan install ./.conan -if ./build --build missing --profile ./.conan/profiles/workflows/ubuntu-latest
- name: Run CMake
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Build & Test Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions: read-all
jobs:
build-and-test:
timeout-minutes: 20
runs-on: windows-latest
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Setup Conan
run: |
conan install . -if ./build --build missing --profile ./.conan/profiles/workflows/windows-latest
conan install ./.conan -if ./build --build missing --profile ./.conan/profiles/workflows/windows-2019
- name: Run CMake
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CMakeSettings.json
*/conanbuildinfo.txt
*/conanbuildinfo.cmake
*/conan.lock
/conanfile.py

### Vcpkg
vcpkg/
Expand Down
53 changes: 26 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ endif ()
setup_output_directories()

# Command to generate template constants
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TemplateConstants.cpp"
COMMAND template_generator "${CMAKE_CURRENT_BINARY_DIR}/TemplateConstants.cpp" "${PROJECT_SOURCE_DIR}/src/graphql/templates"
set(ENJINSDK_TEMPLATES_DIR "${CMAKE_CURRENT_LIST_DIR}/src/graphql/templates")
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TemplateConstants.cpp"
COMMAND template_generator "${CMAKE_CURRENT_BINARY_DIR}/TemplateConstants.cpp" "${ENJINSDK_TEMPLATES_DIR}"
DEPENDS template_generator
COMMENT "Generating TemplateConstants source file"
)
COMMENT "Generating TemplateConstants source file from resources at: ${ENJINSDK_TEMPLATES_DIR}")

# Add supporting executables and libraries
add_subdirectory(utils)
Expand All @@ -71,7 +70,7 @@ if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU" OR ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra)
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
target_compile_options(${PROJECT_NAME} PRIVATE /EHsc /MTd /W2 /c)
target_compile_options(${PROJECT_NAME} PRIVATE /EHsc /MTd /W2 /c /wd4996)
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_EXPORTS)
endif ()
endif ()
Expand Down Expand Up @@ -131,42 +130,41 @@ set_version_macro()

####################################################################################################################
### Target sources
include(GNUInstallDirs)

target_sources(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/TemplateConstants.cpp")
target_include_directories(${PROJECT_NAME}
PUBLIC
"$<INSTALL_INTERFACE:include>"
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/include")
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>/${PROJECT_NAME}")

add_subdirectory(src)

####################################################################################################################
### Install library and export package
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

if (WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif ()

install(DIRECTORY "include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.hpp")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_utils
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(FILES "${PROJECT_SOURCE_DIR}/include/*" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(EXPORT ${PROJECT_NAME}
FILE ${PROJECT_NAME}.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
# Generate package files
include(CMakePackageConfigHelpers)

configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
Expand All @@ -175,12 +173,12 @@ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Con
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

# Exports target from build tree
export(EXPORT ${PROJECT_NAME}
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.cmake"
NAMESPACE ${PROJECT_NAME}::)
install(EXPORT ${PROJECT_NAME}
FILE "${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

####################################################################################################################
### Setup tests
Expand All @@ -197,6 +195,7 @@ endif ()
### Unset variables
unset(ENJINSDK_INCLUDE_HTTP_CLIENT_IMPL)
unset(ENJINSDK_INCLUDE_WEBSOCKET_CLIENT_IMPL)
unset(ENJINSDK_TEMPLATES_DIR)
unset(ENJINSDK_USING_CONAN)
unset(ENJINSDK_BUILD_SHARED CACHE)
unset(ENJINSDK_BUILD_TESTS CACHE)
Expand Down
2 changes: 1 addition & 1 deletion Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/enjinsdk.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/enjinsdkTargets.cmake")

check_required_components(enjinsdk)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ To have the SDK build its default HTTP and websocket clients use the `ENJINSDK_B
To utilize this SDK you may clone it into your project tree with:

```console
$ git clone https://github.com/enjin/Enjin-CPP-SDK.git
$ git clone https://github.com/enjin/enjin-cpp-sdk.git
```

Then use the following in your project's CMakeLists file:

```cmake
add_subdirectory(Enjin-CPP-SDK)
add_subdirectory(enjin-cpp-sdk)
target_link_libraries(my_target PRIVATE enjinsdk::enjinsdk)
```

Expand All @@ -75,8 +75,8 @@ target_link_libraries(my_target PRIVATE enjinsdk::enjinsdk)
Alternatively, on Linux you may include the SDK in your project by cloning and building it with the following commands:

```console
$ git clone https://github.com/enjin/Enjin-CPP-SDK.git
$ cmake ./Enjin-CPP-SDK [options] && make -j -C ./Enjin-CPP-SDK
$ git clone https://github.com/enjin/enjin-cpp-sdk.git
$ cmake ./enjin-cpp-sdk [options] && make -j -C ./enjin-cpp-sdk
```

From here, you may use CMake's `find_package()` function to find `enjinsdk` and link the library, `enjinsdk::enjinsdk`
Expand Down
51 changes: 0 additions & 51 deletions conanfile.py

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/templategenerator/TemplateLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class TemplateLoader {
std::shared_ptr<std::map<std::string, Template>> fragments;

static constexpr char BACK_SLASH_REGEX[] =
R"(^(?:[a-zA-Z\\:-]*schemas\\)(?:player|project|shared)\\(fragment|mutation|query)\\(?:[a-zA-Z]+)\.gql$)";
R"(^(?:[\w\W]*schemas\\)(?:player|project|shared)\\(fragment|mutation|query)\\(?:[a-zA-Z]+)\.gql$)";
static constexpr char FORWARD_SLASH_REGEX[] =
R"(^(?:[a-zA-Z/:-]*schemas/)(?:player|project|shared)/(fragment|mutation|query)/(?:[a-zA-Z]+)\.gql$)";
R"(^(?:[\w\W]*schemas/)(?:player|project|shared)/(fragment|mutation|query)/(?:[a-zA-Z]+)\.gql$)";

void load_raw_resources();

Expand Down
1 change: 1 addition & 0 deletions src/models/AccessToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include "enjinsdk/models/AccessToken.hpp"

#include "rapidjson/document.h"

namespace enjin::sdk::models {
Expand Down

0 comments on commit c908a0e

Please sign in to comment.