Last active
December 4, 2019 06:29
-
-
Save Jacob-Tate/539eb08cc255c7fc0fba8770bf1d1906 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# author Jacob Ivan Tate | |
# date 10/17/2019 | |
# | |
cmake_minimum_required (VERSION 3.14) | |
#------------------------------------------------------------------------------ | |
# Project setup, versioning stuff here, change when changing the version | |
# Note: keep the project name lower case only for easy linux packaging support | |
project (server_side LANGUAGES CXX C VERSION 0.0.0) | |
#------------------------------------------------------------------------------- | |
# Setting module path and protobug paths | |
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") | |
set(WINDOWS_EXPORT_ALL_SYMBOLS ON) | |
option(VERBOSE OFF) | |
if(VERBOSE) | |
SET(CMAKE_VERBOSE_MAKEFILE ON) | |
endif() | |
message(STATUS "") | |
message(STATUS "===== ${PROJECT_NAME} Project configuration =====") | |
message(STATUS "") | |
message(STATUS "Generator: ${CMAKE_GENERATOR}") | |
#------------------------------------------------------------------------------ | |
# Server application | |
add_subdirectory(server) | |
#------------------------------------------------------------------------------- | |
# Wrap up of settings printed on build | |
message(STATUS "") | |
message(STATUS "===== Final overview for ${PROJECT_NAME} =====") | |
message(STATUS "Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} ${VERSION_TYPE} @ ${VERSION_HOST}") | |
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER}") | |
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") | |
message(STATUS " possible options: Debug Release RelWithDebInfo MinSizeRel") | |
message(STATUS " set with ` cmake -DCMAKE_BUILD_TYPE=Debug .. `") | |
message(STATUS "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# author Jacob I. Tate | |
# date 10/17/2019 | |
# version 1.0.0 | |
# | |
# Changelog | |
# 1.0.0 | |
# - Created the script | |
cmake_minimum_required(VERSION 3.14) | |
project(server CXX C) | |
#------------------------------------------------------------------------------- | |
# Importing packages | |
#------------------------------------------------------------------------------- | |
# Testing related settings | |
# NOTES: | |
# We enable CLANG_TIDY here which will allow us to run the static | |
# analysis at build time | |
# | |
if(NOT WIN32) | |
set(CMAKE_CXX_CLANG_TIDY | |
clang-tidy-8; | |
-extra-arg=-std=c++17; | |
-header-filter=.*; | |
) | |
endif() | |
#------------------------------------------------------------------------------- | |
# Logging all the things | |
message(STATUS "===== ${PROJECT_NAME} Project configuration =====") | |
message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}") | |
#------------------------------------------------------------------------------- | |
# Add the executable | |
add_executable(${PROJECT_NAME}) | |
#------------------------------------------------------------------------------- | |
# Set sources | |
# NOTES: | |
# Here we define the headers/test/source our project uses this will be stored in a variable | |
# named server_headers in this case. We place all headers in here (not needed) to ensure that | |
# our intellisense related things are able to detect and scan the files if we didnt do this we | |
# have no guarentee of that. Additionally, We dont use GLOB as it isnt safe and has unwanted side | |
# effects if certain files only exist on specific platforms | |
# | |
target_sources( ${PROJECT_NAME} | |
PRIVATE | |
main.cpp | |
PUBLIC | |
# Cpp files | |
INTERFACE | |
# Headers | |
) | |
#------------------------------------------------------------------------------- | |
# Dependencies | |
# add_dependencies(${PROJECT_NAME}) | |
#------------------------------------------------------------------------------- | |
# Set compile definitions | |
target_compile_definitions(${PROJECT_NAME} PRIVATE | |
# # Win32 | |
# $<$<BOOL:${WIN32}>:_ITERATOR_DEBUG_LEVEL=0> | |
) | |
#------------------------------------------------------------------------------- | |
# Set compile features | |
target_compile_features(${PROJECT_NAME} PRIVATE) | |
#------------------------------------------------------------------------------- | |
# Set compile options | |
target_compile_options(${PROJECT_NAME} PRIVATE | |
# # Unix | |
# $<$<BOOL:${UNIX}>:${CXX_FLAGS_DIGIPEN}> | |
# | |
# # Win32 | |
# $<$<BOOL:${WIN32}>:-Wno-c++11-narrowing> | |
) | |
#------------------------------------------------------------------------------- | |
# Set properties | |
# NOTES: | |
# We are setting our target properties here: | |
# CXX_STANDARD - Sets the compiler flag and sets everything for us (no -std=c++17) | |
# CXX_STANDARD_REQUIRED - Tell cmake if the standard isnt avaliable fail | |
# CXX_EXTENSIONS - Turn off extensions to increase portablility | |
# ARCHIVE_OUTPUT_DIRECTORY - This is where .a/.lib files are output | |
# LIBRARY_OUTPUT_DIRECTORY - This is where .dll/.so files are output | |
# RUNTIME_OUTPUT_DIRECTORY - This is where .exe/.out files are output | |
# BUILD_WITH_INSTALL_RPATH - Tells normals builds to repect rpath | |
# INSTALL_RPATH_USE_LINK_PATH - Tell installs to respect our rpath | |
# INSTALL_RPATH - This is where the .exe/.out files will search for .dll/.so | |
# | |
set_target_properties(${PROJECT_NAME} PROPERTIES | |
CXX_STANDARD 17 # set c++17 | |
CXX_STANDARD_REQUIRED ON # require c++17 | |
CXX_EXTENSIONS OFF # turn off c++ extensions from gnu | |
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib" | |
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/drivers" | |
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" | |
BUILD_WITH_INSTALL_RPATH TRUE | |
INSTALL_RPATH_USE_LINK_PATH TRUE | |
INSTALL_RPATH "\$ORIGIN/drivers:${INSTALL_RPATH}" | |
) | |
#------------------------------------------------------------------------------- | |
# Set precompile headers | |
#target_precompile_headers() | |
#------------------------------------------------------------------------------- | |
# Set include directories | |
# NOTES: | |
# Here we are defining our includes which are going to be used by out projects. | |
# Notice here we add our base directory and our inc directory. We | |
# do this so that the src directory can include as if they were in the same directory | |
# such as src/folder/main.cpp including inc/folder/include.h with | |
# #include "folder/include.h" this is much cleaner and makes it clear where files are | |
# coming from. | |
# | |
target_include_directories(${PROJECT_NAME} | |
PUBLIC | |
${CMAKE_CURRENT_BINARY_DIR} | |
${CMAKE_CURRENT_SOURCE_DIR}/inc | |
SYSTEM PUBLIC | |
${CMAKE_SOURCE_DIR}/external | |
) | |
#------------------------------------------------------------------------------- | |
# Set link libraries | |
target_link_libraries(${PROJECT_NAME} PUBLIC | |
# # Unix | |
# $<$<BOOL:${UNIX}>:stdc++fs> | |
# $<$<BOOL:${UNIX}>:pthread> | |
# $<$<BOOL:${UNIX}>:m> | |
) | |
#------------------------------------------------------------------------------- | |
# Set link options | |
target_link_options(${PROJECT_NAME} PRIVATE) | |
#------------------------------------------------------------------------------- | |
# Set link directories | |
target_link_directories(${PROJECT_NAME} PRIVATE) | |
#------------------------------------------------------------------------------- | |
# ETC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment