83 lines
2.4 KiB
CMake
83 lines
2.4 KiB
CMake
# Project Setup
|
|
cmake_minimum_required(VERSION 3.21)
|
|
project(
|
|
projet
|
|
VERSION 0.0.1
|
|
DESCRIPTION "api for etheryo blog"
|
|
HOMEPAGE_URL "https://www.etheryo.fr/"
|
|
LANGUAGES CXX C
|
|
)
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
set(TARGET app)
|
|
|
|
# CPM Setup
|
|
set(CPM_DOWNLOAD_VERSION 0.38.7)
|
|
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
|
|
|
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
|
|
message(STATUS "Downloading CPM.cmake")
|
|
file(DOWNLOAD https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake ${CPM_DOWNLOAD_LOCATION})
|
|
endif()
|
|
|
|
include(${CPM_DOWNLOAD_LOCATION})
|
|
|
|
# Source files
|
|
set(SOURCES "${PROJECT_SOURCE_DIR}/src")
|
|
add_executable(${TARGET}
|
|
${SOURCES}/dotenv.cpp
|
|
${SOURCES}/json.cpp
|
|
${SOURCES}/main.cpp
|
|
)
|
|
|
|
# Add Dependencies
|
|
find_package(Boost 1.64 COMPONENTS system date_time REQUIRED)
|
|
|
|
# Crow CPP
|
|
CPMAddPackage(
|
|
NAME crowcpp
|
|
GITHUB_REPOSITORY CrowCpp/Crow
|
|
GIT_TAG v1.1.0
|
|
)
|
|
|
|
if(crowcpp_ADDED)
|
|
target_include_directories(${TARGET} PUBLIC "${crowcpp_SOURCE_DIR}/include")
|
|
endif()
|
|
|
|
# Lib Pqxx
|
|
CPMAddPackage(
|
|
NAME libpqxx
|
|
GITHUB_REPOSITORY jtv/libpqxx
|
|
GIT_TAG 7.9.0
|
|
)
|
|
|
|
if(libpqxx_ADDED)
|
|
target_include_directories(${TARGET} PUBLIC "${libpqxx_SOURCE_DIR}/include")
|
|
target_include_directories(${TARGET} PUBLIC "${libpqxx_BINARY_DIR}/include")
|
|
target_link_libraries(${TARGET} PRIVATE pqxx)
|
|
endif()
|
|
|
|
# Copying the ressource folder to the build
|
|
add_custom_target(CopyRes ALL
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/res
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/res
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
${CMAKE_SOURCE_DIR}/res
|
|
${CMAKE_BINARY_DIR}/res
|
|
COMMENT "Copying and deleting resources to build directory"
|
|
VERBATIM
|
|
)
|
|
add_dependencies(${TARGET} CopyRes)
|
|
|
|
# Including the include folder
|
|
target_include_directories(${TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include")
|
|
|
|
# Compilation depending on the platform
|
|
if(MSVC)
|
|
target_compile_options(${TARGET} PUBLIC /W3 /WX /DEBUG )
|
|
elseif(${CMAKE_CXX_COMPILER} STREQUAL "/usr/bin/x86_64-w64-mingw32-g++")
|
|
target_compile_options(${TARGET} PUBLIC -Wall -Wextra -Wpedantic -Werror -static-libgcc -static-libstdc++)
|
|
else()
|
|
target_compile_options(${TARGET} PUBLIC -Wall -Wextra -Wpedantic -Werror -Wno-unused-but-set-variable)
|
|
endif()
|