Cmake __top__ Download -

cmake --version # Option 1: apt (older version) sudo apt update sudo apt install cmake Option 2: Official binary (latest) wget https://github.com/Kitware/CMake/releases/download/v3.29.3/cmake-3.29.3-linux-x86_64.tar.gz tar -xzf cmake-3.29.3-linux-x86_64.tar.gz sudo mv cmake-3.29.3-linux-x86_64 /opt/cmake sudo ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake macOS # Homebrew brew install cmake Or download the .dmg from cmake.org Part 2: Post-Download — Developing with CMake Once CMake is installed, here’s how to use it effectively in a C++ project . Step 1: Basic Project Structure MyProject/ ├── CMakeLists.txt ├── src/ │ └── main.cpp └── build/ (created later) Step 2: Write CMakeLists.txt cmake_minimum_required(VERSION 3.15) project(MyApp VERSION 1.0.0 LANGUAGES CXX) C++ standard set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) Add executable add_executable(my_app src/main.cpp) Optional: set output directory set_target_properties(my_app PROPERTIES RUNTIME_OUTPUT_DIRECTORY $CMAKE_BINARY_DIR/bin ) Step 3: Build the Project Out-of-source build (recommended) cd MyProject mkdir build cd build cmake .. cmake --build . On Windows (Visual Studio generator) mkdir build cd build cmake .. -G "Visual Studio 17 2022" cmake --build . --config Release Step 4: Run Your App # Linux/macOS ./bin/my_app Windows .\bin\Release\my_app.exe Part 3: Post-Build — Advanced CMake Techniques 1. Add a Library # In CMakeLists.txt add_library(my_lib STATIC src/lib.cpp) target_include_directories(my_lib PUBLIC include) target_link_libraries(my_app PRIVATE my_lib) 2. Find External Packages (e.g., OpenCV) find_package(OpenCV REQUIRED) target_link_libraries(my_app PRIVATE $OpenCV_LIBS) 3. Set Installation Rules install(TARGETS my_app DESTINATION bin) install(FILES README.md DESTINATION .) Then run:

Then:

cmake --install . --prefix /usr/local Create CMakePresets.json : cmake download