Skip to content

Instantly share code, notes, and snippets.

@caiorss
Created June 1, 2020 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caiorss/76b8540d8a358ab0c740709962e1e511 to your computer and use it in GitHub Desktop.
Save caiorss/76b8540d8a358ab0c740709962e1e511 to your computer and use it in GitHub Desktop.
Cmake with CMake.CPM module
#include <iostream>
#include <spdlog/spdlog.h>
#include <cppcodec/base32_crockford.hpp>
#include <cppcodec/base64_rfc4648.hpp>
int main(int argc, char** argv)
{
SPDLOG_TRACE("Entering function");
spdlog::info("Starting server OK.");
spdlog::info("Received request from 192.168.10.1 at port 9090");
spdlog::info("Sending response to client 192.168.100.1 connection ID 10");
using base32 = cppcodec::base32_crockford;
using base64 = cppcodec::base64_rfc4648;
std::string secret = "SGVsbG8gd29ybGQgQ01ha2UgQ1BNIHdpdGggYmFzZTY0IGVuY29uZGluZy4=";
std::vector<uint8_t> decoded = base64::decode(secret);
std::string text(decoded.begin(), decoded.end());
std::cout << " =>> Decoded text = " << text << std::endl;
SPDLOG_TRACE("Exit application");
return 0;
}
cmake_minimum_required(VERSION 3.9)
project(Simple_Cmake_Project)
#========== Global Configurations =============#
#----------------------------------------------#
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ------------ Download CPM CMake Script ----------------#
## Automatically donwload and use module CPM.cmake
file(DOWNLOAD https://raw.githubusercontent.com/TheLartians/CPM.cmake/v0.26.2/cmake/CPM.cmake
"${CMAKE_BINARY_DIR}/CPM.cmake")
include("${CMAKE_BINARY_DIR}/CPM.cmake")
#----------- Add dependencies --------------------------#
CPMAddPackage(
NAME spdlog
URL "https://github.com/gabime/spdlog/archive/v1.3.1.zip"
# -->> Only enable this, if the library does not use CMake.
# The library uses only Makefile, GNU autotools and so on.
# In other words, does not have a CMakeLists.txt at root directory.
# DOWNLOAD_ONLY YES
)
CPMAddPackage(
NAME cppcodec
GITHUB_REPOSITORY tplgy/cppcodec
GIT_TAG v0.2
#VERSION 0.2
OPTIONS
"BUILD_TESTING OFF"
)
include_directories( ${cppcodec_SOURCE_DIR}/ )
message([TRACE] " spdlog source = ${spdlog_SOURCE_DIR} ")
message([TRACE] " cppcodec source = ${cppcodec_SOURCE_DIR} ")
#----------- Set targets -------------------------------#
add_executable(app1 app1.cpp)
target_link_libraries(app1 cppcodec spdlog::spdlog)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment