Programování v C++

Demonstrace: CMake, Cross-platform C++ projects

Cílem je pouze CMake a povědomí o cross-platform projektech a překladu. Package manager je spíše pro informaci, navíc znáte z jiných programovacích jazyků.

Demonstrace: CMakeproject

Create a "CMake project" using Visual Studio. We could use with VisualStudio but instead we use command line. We run "Developer Command Prompt" to get the MS compiler to path.

Demonstrace: vcpkg

We need to obtain vcpkg, it can be installed with MSVC.


# Clone repository
git clone https://github.com/microsoft/vcpkg.git .
# Run the bootstrap script and disable metrics.
.\bootstrap-vcpkg.bat -disableMetrics
    

Once ready we can start integration. Keep in mind env variables are set only for a session.


# Set paths.
set VCPKG_ROOT=C:\Programs\Vcpkg-2024.11.16
set PATH=%PATH%;%VCPKG_ROOT%

# Enable integration with build system.
# We also get information about how to run cmake projects.
vcpkg integrate install
    
When using Cmake we need to pass option to let it know we have vcpkg:

cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%/scripts/buildsystems/vcpkg.cmake
    

Demonstrace: sfml

We are going to use manifest mode with sflm library.


# Initialize local manifest vcpkg.json and vcpkg-configuration.json.
vcpkg new --name my-application --version 1.0.0

# Add library : https://vcpkg.link/ports/sfml
vcpkg add port sfml

# Install libraries from manifest.
# It may take some time, libraries are installed to './vcpkg_installed/' directory.
# The "target_link_libraries(main .." must much "add_executable(main ...".
vcpkg install
    

Make sure that the target "main" in target_link_libraries matches target in "add_executable". See SFML tutorial "Opening and managing an SFML window" to get some code using SFML.


# Configure
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%/scripts/buildsystems/vcpkg.cmake
# Build
cmake --build build
    

See Install and use packages with CMake in Visual Studio.