boilerplate
This commit is contained in:
79
CMakeLists.txt
Normal file
79
CMakeLists.txt
Normal file
@@ -0,0 +1,79 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# -----------------------------
|
||||
# Force Clang before project() is called
|
||||
# -----------------------------
|
||||
if(NOT DEFINED CMAKE_C_COMPILER)
|
||||
set(CMAKE_C_COMPILER clang CACHE STRING "" FORCE)
|
||||
endif()
|
||||
if(NOT DEFINED CMAKE_CXX_COMPILER)
|
||||
set(CMAKE_CXX_COMPILER clang++ CACHE STRING "" FORCE)
|
||||
endif()
|
||||
|
||||
# -----------------------------
|
||||
# Project setup
|
||||
# -----------------------------
|
||||
project(mainframe LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
# -----------------------------
|
||||
# Dependencies (local submodules / cloned repos)
|
||||
# -----------------------------
|
||||
add_subdirectory(external/spdlog)
|
||||
add_subdirectory(external/cpr)
|
||||
add_subdirectory(external/clickhouse-cpp)
|
||||
add_subdirectory(external/tomlplusplus)
|
||||
# -----------------------------
|
||||
# Executable
|
||||
# -----------------------------
|
||||
add_executable(${PROJECT_NAME} src/main.cpp)
|
||||
|
||||
# -----------------------------
|
||||
# Auto-discover include dirs under src/
|
||||
# -----------------------------
|
||||
file(GLOB_RECURSE SRC_SUBDIRS LIST_DIRECTORIES true "${CMAKE_CURRENT_SOURCE_DIR}/src/*")
|
||||
set(SRC_INCLUDES "")
|
||||
foreach(dir ${SRC_SUBDIRS})
|
||||
if(IS_DIRECTORY ${dir})
|
||||
list(APPEND SRC_INCLUDES ${dir})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# -----------------------------
|
||||
# Auto-discover all .cpp files except main.cpp
|
||||
# -----------------------------
|
||||
file(GLOB_RECURSE ALL_CPP "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
|
||||
list(REMOVE_ITEM ALL_CPP "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
|
||||
|
||||
# -----------------------------
|
||||
# Apply sources and includes
|
||||
# -----------------------------
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${ALL_CPP})
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${SRC_INCLUDES})
|
||||
|
||||
# -----------------------------
|
||||
# Link libraries
|
||||
# -----------------------------
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
spdlog::spdlog
|
||||
cpr::cpr
|
||||
clickhouse-cpp-lib
|
||||
tomlplusplus::tomlplusplus
|
||||
)
|
||||
|
||||
# -----------------------------
|
||||
# Compiler warnings (Clang/GCC)
|
||||
# -----------------------------
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
|
||||
add_compile_options(
|
||||
-Wall -Wextra -Wpedantic
|
||||
-Wconversion -Wshadow
|
||||
-Wnull-dereference
|
||||
-Wdouble-promotion
|
||||
)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user