Files
toml11/en.search-data.min.ef6f129152c30a4fb49b0cc2bc7f1637a35b28fd98467446dabbe214866d2b6b.json

1 line
261 KiB
JSON
Raw Permalink Normal View History

[{"id":0,"href":"/toml11/docs/installation/","title":"installation","section":"Docs","content":" Installation # Using single_include # The ingle_include/toml.hpps is a single-file, header-only library that consolidates all the functionalities of toml11 into one file.\nThe simplest way to use it is to copy this file to a location included in your INCLUDE_PATH and then add #include \u0026lt;toml.hpp\u0026gt; to your source code.\nThe MIT license notice is included in both the comments and the toml::license_notice() function. If you are redistributing the software without releasing the source code, you must either copy the toml11 license file and include it with your distribution, or ensure that the toml::license_notice() function can be called.\nCloning toml11 and using cmake # If you place toml11 within your repository, for example by using git submodule, and you are using cmake, you can make use of it by adding add_subdirectory(toml11) to your CMakeLists.txt.\nadd_subdirectory(toml11) add_executable(main main.cpp) target_link_libraries(main PUBLIC toml11::toml11) toml11 will only run tests and install when it is the root project.\nCMake FetchContent # Using FetchContent, you can automatically download toml11 to your build directory.\ninclude(FetchContent) FetchContent_Declare( toml11 GIT_REPOSITORY https://github.com/ToruNiina/toml11.git GIT_TAG v4.4.0 ) FetchContent_MakeAvailable(toml11) add_executable(main main.cpp) target_link_libraries(main PRIVATE toml11::toml11) CMake Package Manager (CPM) # After adding cpm to your project, you can use toml11 by doing:\ninclude(cmake/CPM.cmake) CPMAddPackage(\u0026#34;gh:ToruNiina/toml11@4.4.0\u0026#34;) # OR CPMAddPackage( NAME toml11 GITHUB_REPOSITORY \u0026#34;ToruNiina/toml11\u0026#34; VERSION 4.4.0 OPTIONS \u0026#34;TOML11_PRECOMPILE ON\u0026#34; # to pre-compile \u0026#34;TOML11_ENABLE_ACCESS_CHECK ON\u0026#34; # to use value.accessed() ) add_executable(main main.cpp) target_link_libraries(main PUBLIC toml11::toml11) Installing using cmake # After cloning toml11, you can install it using cmake.\n$ cmake -B ./build/ -DTOML11_BUILD_TESTS=ON $ cmake --install ./build/ --prefix=/opt/toml11 If you want to run the test programs before installation, make sure to set -DTOML11_BUILD_TESTS=ON first.\nOnce the installation is complete, you can use it as follows:\nfind_package(toml11) add_executable(main main.cpp) target_link_libraries(main PRIVATE toml11::toml11) Compiling with cmake to Create a Static Library # By defining -DTOML11_PRECOMPILE=ON when running cmake, you can precompile some of the functions in toml11, thereby reducing the overall compile time.\n$ cmake -B ./build/ -DTOML11_PRECOMPILE=ON When linking the library, use target_link_libraries in CMake\ntarget_link_libraries(your_target PUBLIC toml11::toml11) or pass -DTOML11_COMPILE_SOURCES to the compiler to suppress header-only features.\nHowever, since toml11 supports multiple C++ versions and may switch types based on the value of __cplusplus, there is a possibility of link failures if the version used during build differs from the version used during usage. If you encounter issues, set the required version using CMAKE_CXX_STANDARD during compilation. If this is difficult, use it as a header-only library as usual.\nThe find_package(toml11) command defines TOML11_INCLUDE_DIR. Even if you install it as a precompiled library, you can still use it as a header-only library by adding TOML11_INCLUDE_DIR to target_include_directories and avoiding the use of target_link_libraries.\nfind_package(toml11) add_executable(main main.cpp) # Include only, do not link target_include_directories(main PRIVATE ${TOML11_INCLUDE_DIR}) Compiling Examples # You can compile the examples/ directory by setting -DTOML11_BUILD_EXAMPLES=ON.\n$ cmake -B ./build/ -DTOML11_BUILD_EXAMPLES=ON $ cmake --build ./build/ The executable binaries for the examples will be generated in the examples/ directory.\nRunning Tests # To build the tests, set -DTOML11_BUILD_TESTS=ON.\n$ git submodule update --init --recursive $ cmake -B ./build/ -DTOML11_BUILD_TESTS=ON $