Last active
July 16, 2019 13:10
-
-
Save markhc/1594360f314ab9357cb4e3f9405821b2 to your computer and use it in GitHub Desktop.
fmtlib + cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required (VERSION 3.12) | |
# not strictly needed, but it helps when you forget to pass the CMAKE_TOOLCHAIN_FILE as argument to cmake | |
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) | |
set(CMAKE_TOOLCHAIN_FILE | |
"$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" | |
CACHE STRING "") | |
endif() | |
project(cmake_example CXX) | |
# finds the fmt installation | |
find_package(fmt CONFIG REQUIRED) | |
add_executable(main main.cpp) | |
target_compile_features(main PUBLIC cxx_std_17) | |
# links with fmt. Some magic happens here | |
target_link_libraries(main fmt::fmt) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assuming you're in the directory with both of these files | |
mkdir build | |
cd build | |
# replace path below with your own instalattion folder ofc | |
cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/markhc/Coding/vcpkg/scripts/buildsystems/vcpkg.cmake |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fmt/printf.h> | |
int main() { | |
fmt::print("{}, {}. {} {}\n", "Hello", "there", 42, 3.1415); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment