Modern CMake simplifies the process of building C++ projects by using a target-based approach. This means that instead of manually specifying include directories and source files for each target, you can create and manage targets more easily, resulting in cleaner and more maintainable CMake files.
Here is a basic example of how to write a simple CMakeLists.txt using modern target-based CMake:
cmake_minimum_required(VERSION 3.10)
# Define the project name
project(MyProject)
# Create a library target
add_library(MyLibrary src/mylibrary.cpp)
# Specify include directories for the library
target_include_directories(MyLibrary PUBLIC include)
# Create an executable target
add_executable(MyExecutable src/main.cpp)
# Link the library to the executable
target_link_libraries(MyExecutable PRIVATE MyLibrary)
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?