From 3f6fceabd685f4c538ba5d1411d1abca4666941e Mon Sep 17 00:00:00 2001 From: cobrapitz <12397702+cobrapitz@users.noreply.github.com> Date: Thu, 6 Apr 2023 20:48:50 +0200 Subject: [PATCH] inital commit --- cmake/CMakeSettings.cmake | 14 +++++++++++ cmake/FetchBoost.cmake | 46 +++++++++++++++++++++++++++++++++++ cmake/FetchCURL.cmake | 17 +++++++++++++ cmake/FetchGoogleTest.cmake | 18 ++++++++++++++ cmake/FetchNlohmannJSON.cmake | 18 ++++++++++++++ cmake/Options.cmake | 0 cmake/Utils.cmake | 11 +++++++++ 7 files changed, 124 insertions(+) create mode 100644 cmake/CMakeSettings.cmake create mode 100644 cmake/FetchBoost.cmake create mode 100644 cmake/FetchCURL.cmake create mode 100644 cmake/FetchGoogleTest.cmake create mode 100644 cmake/FetchNlohmannJSON.cmake create mode 100644 cmake/Options.cmake create mode 100644 cmake/Utils.cmake diff --git a/cmake/CMakeSettings.cmake b/cmake/CMakeSettings.cmake new file mode 100644 index 0000000..949ff1a --- /dev/null +++ b/cmake/CMakeSettings.cmake @@ -0,0 +1,14 @@ + +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) + + # Export compile command -> better tool integration. + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + set(CMAKE_VERBOSE_MAKEFILE ON) + + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + + set_property(GLOBAL PROPERTY USE_FOLDERS ON) +endif() diff --git a/cmake/FetchBoost.cmake b/cmake/FetchBoost.cmake new file mode 100644 index 0000000..d24dde2 --- /dev/null +++ b/cmake/FetchBoost.cmake @@ -0,0 +1,46 @@ +# Additional infos: +# - https://github.com/boostorg/cmake#using-boost-with-fetchcontent +# +# Find all components: +# set(Boost_DEBUG ON) # before adding include(cmake/FetchBoost.cmake) in CMakeLists.txt +# (https://stackoverflow.com/questions/29989512/where-can-i-find-the-list-of-boost-component-that-i-can-use-in-cmake) +# +# Linking: +# target_link_libraries(${PROJECT_NAME} PRIVATE +# Boost::dll +# Boost:: +# ) + +if (NOT DEFINED BOOST_GIT_TAG) + message(FATAL_ERROR "BOOST_GIT_TAG is not defined.\n see https://github.com/boostorg/boost and grab a release tag.\n example: set(BOOST_GIT_TAG boost-1.81.0)") +endif() + + +if (NOT DEFINED BOOST_INCLUDE_LIBRARIES) + message(FATAL_ERROR "BOOST_INCLUDE_LIBRARIES is not defined. \n example: set(BOOST_INCLUDE_LIBRARIES thread filesystem system program_options dll pfr).") +endif() + +####################################################################################################################### +# Boost options +####################################################################################################################### + +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) + +set(BOOST_ENABLE_CMAKE ON) + + +####################################################################################################################### +# Fetch boost from github +####################################################################################################################### + +FetchContent_Declare( + Boost + GIT_REPOSITORY https://github.com/boostorg/boost.git + GIT_TAG ${BOOST_GIT_TAG} +) + +include(${CMAKE_SOURCE_DIR}/cmake/Utils.cmake) +print_git_tag(${BOOST_GIT_TAG}) + diff --git a/cmake/FetchCURL.cmake b/cmake/FetchCURL.cmake new file mode 100644 index 0000000..94a7cdb --- /dev/null +++ b/cmake/FetchCURL.cmake @@ -0,0 +1,17 @@ +# usage: +# FetchContent_MakeAvailable(curl) +# target_link_libraries(${PROJECT_NAME} PRIVATE libcurl) + +if (NOT DEFINED CURL_GIT_TAG) + message(FATAL_ERROR "CURL_GIT_TAG is not defined.\n see https://github.com/curl/curl and grab a release tag.\n example: set(CURL_GIT_TAG curl-8_0_1)") +endif() + + +FetchContent_Declare( + curl + GIT_REPOSITORY https://github.com/curl/curl.git + GIT_TAG ${CURL_GIT_TAG} +) + +include(${CMAKE_SOURCE_DIR}/cmake/Utils.cmake) +print_git_tag(${CURL_GIT_TAG}) diff --git a/cmake/FetchGoogleTest.cmake b/cmake/FetchGoogleTest.cmake new file mode 100644 index 0000000..48bb00d --- /dev/null +++ b/cmake/FetchGoogleTest.cmake @@ -0,0 +1,18 @@ +# usage: +# FetchContent_MakeAvailable(googletest) +# target_link_libraries(${PROJECT_NAME} PRIVATE googletest) +# +# further reading: https://google.github.io/googletest/quickstart-cmake.html + +if (NOT DEFINED GOOGLE_TEST_GIT_TAG) + message(FATAL_ERROR "GOOGLE_TEST_GIT_TAG is not defined.\n see https://github.com/google/googletest and grab a release tag.\n example: set(GOOGLE_TEST_GIT_TAG v1.13.0)") +endif() + +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG ${GOOGLE_TEST_GIT_TAG} +) + +include(${CMAKE_SOURCE_DIR}/cmake/Utils.cmake) +print_git_tag(${GOOGLE_TEST_GIT_TAG}) diff --git a/cmake/FetchNlohmannJSON.cmake b/cmake/FetchNlohmannJSON.cmake new file mode 100644 index 0000000..1dd7949 --- /dev/null +++ b/cmake/FetchNlohmannJSON.cmake @@ -0,0 +1,18 @@ +# usage: +# FetchContent_MakeAvailable(json) +# target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json) + +if (NOT DEFINED NLOHMANN_JSON_GIT_TAG) + message(FATAL_ERROR "NLOHMANN_JSON_GIT_TAG is not defined.\n see https://github.com/nlohmann/json and grab a release tag.\n example: set(NLOHMANN_JSON_GIT_TAG v3.11.2)") +endif() + + +FetchContent_Declare( + json + GIT_REPOSITORY https://github.com/nlohmann/json + GIT_TAG ${NLOHMANN_JSON_GIT_TAG} +) + + +include(${CMAKE_SOURCE_DIR}/cmake/Utils.cmake) +print_git_tag(${NLOHMANN_JSON_GIT_TAG}) diff --git a/cmake/Options.cmake b/cmake/Options.cmake new file mode 100644 index 0000000..e69de29 diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake new file mode 100644 index 0000000..0037317 --- /dev/null +++ b/cmake/Utils.cmake @@ -0,0 +1,11 @@ + +# Writes the filename to ${CURRENT_FILENAME} +macro(print_git_tag GIT_TAG) + + # get current filename + set(_CURRENT_FILENAME "") + get_filename_component(_CURRENT_FILENAME ${CMAKE_CURRENT_LIST_FILE} NAME) + + # print message + message(STATUS "${_CURRENT_FILENAME}:> Fetching Version-[${GIT_TAG}]") +endmacro() \ No newline at end of file