8000 GitHub - jadler/cmake-scripts
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jadler/cmake-scripts

Repository files navigation

CMake Scripts

CMake-Scripts

A collection of scripts for cmake projects. These scripts cover the most common cases of building projects.

It is possible to configure most of the projects with a few lines.

CMAKE_MINIMUM_REQUIRED (VERSION 3.9 FATAL_ERROR)

PROJECT ("MyProject" VERSION 1.0.0 LANGUAGES C CXX)

SET (TARGET_NAME mylib)
ADD_LIBRARY (${TARGET_NAME} SHARED)

INCLUDE (CMake-config)

Features

Project Types
Can build the most common types of projects, Normal Libraries, Interface Libraries and Binary Executables.
Unit tests
Can compile and execute tests files inside test/src directory. This scripts use the Catch2 framework.
Config.cmake
Generate <Project>Config.cmake and <Project>ConfigVersion.cmake files automatically that can be used with FIND_PACKAGE
NAMESPACE
Define the namespace for this project setting the NAMESPACE variable.

Project structure

To be able to build projects with these scripts it is necessary to follow the following folder structure:

├── CMakeLists.txt
├── include
│   ├── bar
│   │   └── bar.hpp
│   └── foo.hpp
├── src
│   ├── foobar.hpp
│   ├── foo.cpp
│   └── main.cpp
└── test
    └── src
        ├── main.cpp
        ├── test.cpp
        └── test.hpp
CMakeLists.txt
The cmake configuration file, in the root of the project directory.
include
All header files within this directory will be public and available to developers. On *nix systems this files will be installed in the include directory. The structure defined here will be maintained at installation.
src
Directory containing the source code, the header files defined here will not be exposed to developers.
test/src
The same as above but for tests. All files here will be used to generate a single binary test file.

Building, testing and packaging.

In order to build the project, some variables must be defined on the command line or added to the CMakeLists.txt file. These variables are CMAKE_MODULE_PATH which must point to the location path of these scripts and NAMESPACE, if no NAMESPACE is specified, the project name will be used. If there you want to generate the package of the project, then it is necessary to define the variable CPACK_GENERATOR.

To generate the scripts for compilation and prepare them to be packaged in one of the supported formats, execute:

$ cmake -S <source_dir> -B <build_dir> -D NAMESPACE=jadl -D CMAKE_MODULE_PATH=<path_to_scripts> -D CPACK_GENERATOR=7Z

It is now possible to compile, test and package the solution in one single line.

cmake --build <build_dir> --target all --target test --target package

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

0