R3D9477 / UCMakeSkeleton

skeleton of CMake project with set of features to make building of the project's a bit quickly and easy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UCMakeSkeleton

Universal simple skeleton of project's tree, based on CMake build system.

Stucture

[ PROJECT ]
ㅤㅤㅤ|- CMakeLists.txt
ㅤㅤㅤ|- test
ㅤㅤㅤ|- lib
ㅤㅤㅤㅤㅤㅤ|- [ somelib ]
ㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- CMakeLists.txt
ㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- include
ㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- src
ㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- test
ㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- thirdparty
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- [ thirdlib ]
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- CMakeLists.txt
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- include
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- src
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ|- test

Main tasks

  • Project: CMake Build Debug
  • Project: CMake Clean Debug
  • Project: CMake Rebuild Debug
  • Project: CMake Build Release
  • Project: CMake Clean Release
  • Project: CMake Rebuild Release

Features

  • automatically applies name of directory as name of a project/library
  • automatically finds and adds needed sources and includes into the project's tree (non-recursive globbing); easy and flexible configuration process of source tree for current target: just add needed folder to list
  • automatically adds some of libraries (if possible): Boost, Qt5, Qt6
  • applies some compiler's extra flags because of safety. each compiler has a different set of flags: GCC, Clang or MSVC
  • automatically finds and adds Boost unit tests (don't use the dot symbol '.' in the name of test's source file!)
  • for MSVC automatically copies MS Visual C++ runtime libs to target building directory
  • uses Conan, automatically downloads packages from conanfile.txt before building the project

How to

  1. clone that repositoy to your local machine
  2. add HERE specific sources and includes of your current project (example you can see HERE)
  3. add some external libraries HERE. example of attaching some external libraries:
...
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# ATTACH EXTERNAL LIBRARIES BELOW...

find_package(OpenCV REQUIRED)
target_link_libraries(${OUTPUT_NAME} PUBLIC opencv::opencv)

target_link_libraries(${OUTPUT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/myOwnSDK/lib/x64/libMySDK.so")
target_include_directories(${OUTPUT_NAME} SYSTEM PUBLIC "${CMAKE_SOURCE_DIR}/myOwnSDK/include")

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS SerialPort Sql REQUIRED)
target_link_libraries(${OUTPUT_NAME} PUBLIC Qt::SerialPort)
target_link_libraries(${OUTPUT_NAME} PUBLIC Qt::Sql)
...
  1. add source of uint tests into folder test or add/change you testing configuration HERE. example of adding folder which contains set of unit tests for target:
...
#------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------
# ADD TESTS BELOW...

target_add_tests_from_folder(${OUTPUT_NAME} "test")
...
  1. if needed, you can customize safety flags for your current compiler: GCC, Clang or MSVC

Extra variables

you can use some of variables in your own configuration:

  • variable SAFETY_FLAGS - contains the list of the compiler's flags (GCC, Clang and MSVC) to make your code more safe. example of usage you can find HERE, HERE and HERE
  • variable OUTPUT_NAME - the name of the current target name (target executable file name). usually it the same as varibale PROJECT_NAME, but for Qt6 application it different: app${PROJECT_NAME}. example of usage you can find HERE, HERE, HERE, HERE and HERE

Extra functions

you can use some of functions in your own configuration:

  • function get_sources_from_dir( SOURCES_DEST_VAR INCLUDES_DEST_VAR TARGET_FOLDER_PATH ) - scans TARGET_FOLDER_PATH and adds C++ files by the mask into variables: SOURCES_DEST_VAR (list of source files) and INCLUDES_DEST_VAR (list of include paths). examples of usage you can find HERE and HERE
  • function target_add_boost( TARGET_NAME ) - adds boost library to your target (if it possible). example of usage you can find HERE
  • function target_add_Qt( TARGET_NAME ) - adds Qt to your target (if it possible). example of usage you can find HERE
  • function target_add_tests_from_folder( TARGET_NAME FOLDER_PATH ) - applies Boost unit tests from specified folder (relative or absolute path) for specified target. each source file will be used as individual testing module. examples of usage you can find HERE (for TESTS), HERE (for TESTS) and HERE (for TESTS)

Tested on

  • Linux (GCC,Clang)
  • Windows (Clang,MinGW,MSVC)

Links

About

skeleton of CMake project with set of features to make building of the project's a bit quickly and easy


Languages

Language:CMake 88.7%Language:C++ 11.3%