CMake Documentation – ARGOS
This document describes only the organization and use of the CMakeLists.txt file of the ARGOS project.
It's purpose is to allow any developer to : - understand the build structure - compile the project - add new source files - create new executables - maintain the consistency of the architecture
C++ Version and Standard
Prerequisites
- CMake ≥ 3.25.1
- C++17 compatible compiler
The C++ standard is imposed.
General Build Organization
The project relies on a central library and several executables.
All the business logic is compiled into a library (argos-core). The executables contain only entry points (main) and consume this library.
All third-party dependencies (JSON, CLI11, Boost, CGAL, Eigen) are pulled in
at configure time through FetchContent, so the project has no system
install requirement beyond a C++17 compiler and CMake.
argos-core Library
Declaration
This target represents the project's compilable business logic.Associated Files
The library's .cpp files are explicitly declared, and the algorithms are automatically retrieved via file(GLOB) :
file(GLOB algos
CONFIGURE_DEPENDS
src/algos/mesh_to_pointcloud/*.cpp
src/algos/pointcloud_to_mesh/*.cpp
)
file(GLOB structures
CONFIGURE_DEPENDS
src/structure/*.cpp
)
file(GLOB serializers
CONFIGURE_DEPENDS
src/serializer/*.cpp
)
target_sources(argos-core
PRIVATE
src/mesh/Face.cpp
src/mesh/Mesh.cpp
src/mesh/Vertex.cpp
src/mesh/TopologicMesh.cpp
# algos
${algos}
${structures}
${serializers}
)
src/algos/mesh_to_pointcloud/ and src/algos/pointcloud_to_mesh/ are automatically detected using the CONFIGURE_DEPENDS glob.
- Idem for the structure and the serializers.
Includes
This allows any target that links toargos-core to include the headers with :
C++ Library Standard
This line ensures thatargos-core and everything that uses it are compiled with C++17, in a portable and explicit way.
Executable
The main executable is declared like this :
add_executable(argos
src/main.cpp)
target_link_libraries(argos
PRIVATE argos-core CLI11::CLI11 nlohmann_json::nlohmann_json
)
Notes : - Executables do not contain business logic - All functionality must pass through argos-core
The executable is declared via add_executable and must be explicitly linked to argos-core using target_link_libraries.
Add a new executable
Steps :
1. Create a .cpp file containing a main() function in src/
2. Declare the executable in CMakeLists.txt
3. Link the executable to argos-core
Example :
add_executable(argos-new-tool
src/apps/tools/new_tool.cpp
)
target_link_libraries(argos-new-tool
PRIVATE argos-core
)
Add a new business logic file
Steps :
1. Create the header file in include/...
2. Create the implementation file in src/...
3. Declare the .cpp file in target_sources(argos-core) (CMakeLists.txt file)
Tests and Benchmarks
The project includes two optional categories :
- tests/: unit and functional tests (via GoogleTest)
- benchmark/: performance measurements
These two parts are managed as independent CMake sub-projects, each with it's own CMakeLists.txt, and are included from the root file via add_subdirectory.
Enabling/Disabling via CMake Options:
Test and benchmark compilation is controlled by CMake options :
- BUILD_TESTS: disabled by default (OFF)
- BUILD_BENCHMARKS: enabled by default (ON)
Adding a New Test
To add a new test, simply create a C++ file following the naming convention :
- test_*.cpp
Example : tests/serializer/test_NewSerializer.cpp
No modification to the root CMakeLists.txt is necessary: test_*.cpp files are automatically detected, compiled, and registered as tests via CTest. Note however that tests/CMakeLists.txt does inject some benchmark metric source files into every test target, so if your test depends on new metric files you may need to update it.
Build generation
Standard build (tests disabled, benchmarks enabled by default)
Command lines from root:
Build with tests
Build with benchmarks
Combine the options
Running Tests with CTest
Tests are run using the CTest tool, which is included with CMake.
The following commands must be run from the out build folder.
List of commands:
- ctest || simple execution
- ctest -V || execution with detailed output
- ctest -R <pattern> || run only the tests whose name matches <pattern>
Documentation (Doxygen, optional)
A third optional category can be enabled :
- BUILD_DOC: disabled by default (OFF). When enabled, the root file calls
add_subdirectory(doc), which is expected to provide a doc target that
generates the Doxygen HTML documentation. See docs/Doxygen.md
for the prerequisites and the generation command (cmake --build out --target doc).