IMHO, manually writing and maintaining Makefiles is a waste of time.
These days, CMake is the de facto standard for building C++ code. Even though the syntax takes some time to get used to, it's not nearly as cryptic as Make.
For example:Then compile it using:The basics are very simple:
These days, CMake is the de facto standard for building C++ code. Even though the syntax takes some time to get used to, it's not nearly as cryptic as Make.
For example:
Code:
# CMakeLists.txt (at the root of your project)cmake_minimum_required(VERSION 3.18)project(RudolfAtHome LANGUAGES CXX)find_package(Threads REQUIRED)add_library(warnings INTERFACE)target_compile_options(warnings INTERFACE -Wall -Wextra)add_library(a "libs/lib_a.cpp")target_include_directories(a PUBLIC "libs")target_link_libraries(a PRIVATE warnings PUBLIC bcm2835 rt)add_library(b "libs/lib_b.cpp")target_include_directories(b PUBLIC "libs")target_link_libraries(b PRIVATE warnings PUBLIC Threads::Threads)add_library(c "libs/lib_c.cpp")target_include_directories(c PUBLIC "libs")target_link_libraries(c PRIVATE warnings)add_executable(application_a "src/application_a.cpp")target_link_libraries(application_a PRIVATE warnings a b c)
Code:
cmake -S . -B buildcmake --build build
- Define "targets" (libraries and executables) using add_library and add_executable;
- Set the properties of those targets (e.g. the include path);
- Use target_link_libraries to express dependencies between targets.
Statistics: Posted by tttapa — Sun Mar 31, 2024 9:00 pm