{"id":15136920,"url":"https://github.com/hwhsu1231/cmake-conan-setup","last_synced_at":"2025-10-23T11:32:03.675Z","repository":{"id":157091459,"uuid":"554985584","full_name":"hwhsu1231/cmake-conan-setup","owner":"hwhsu1231","description":"CMake toolchain for integration with Conan using cmake-conan","archived":false,"fork":false,"pushed_at":"2023-03-17T08:20:16.000Z","size":735,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-02-06T07:58:09.884Z","etag":null,"topics":["c","cmake","cmake-toolchain","conan","cpp","package-manager"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hwhsu1231.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-20T18:46:36.000Z","updated_at":"2024-03-05T03:03:57.000Z","dependencies_parsed_at":"2024-02-27T04:48:00.772Z","dependency_job_id":null,"html_url":"https://github.com/hwhsu1231/cmake-conan-setup","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwhsu1231%2Fcmake-conan-setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwhsu1231%2Fcmake-conan-setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwhsu1231%2Fcmake-conan-setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwhsu1231%2Fcmake-conan-setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hwhsu1231","download_url":"https://codeload.github.com/hwhsu1231/cmake-conan-setup/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237821677,"owners_count":19371805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cmake","cmake-toolchain","conan","cpp","package-manager"],"created_at":"2024-09-26T06:41:47.934Z","updated_at":"2025-10-23T11:31:58.341Z","avatar_url":"https://github.com/hwhsu1231.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cmake-conan-setup\n\nCMake toolchain for integration with Conan using [cmake-conan](https://github.com/conan-io/cmake-conan), [`conan-setup.cmake`](./conan-setup.cmake).\n\n\u003e NOTE:\n\u003e\n\u003e - Since [CMakeDeps](https://docs.conan.io/en/latest/reference/conanfile/tools/cmake/cmakedeps.html) and [CMakeToolchain](https://docs.conan.io/en/latest/reference/conanfile/tools/cmake/cmaketoolchain.html) will be the only two cmake-related generators supported in Conan 2.X, this project won't consider the situation using any other cmake-related generators although the demonstration is using Conan 1.X.\n\u003e - This project is INCOMPATIBLE with Conan 2.x for now since there are some bugs about `conan_cmake_autodetect()`...etc. Theoretically, this project should work with Conan 2.X after those bugs are fixed, which is the main goal of this project.\n\n## Motivation\n\nThis project aims to provide a **NONINTRUSIVE** way to integrate CMake with Conan using cmake-conan. It is because the typical usage of cmake-conan is intrusive, which uses APIs of cmake-conan inside the `CMakeLists.txt` directly. For example:\n\n\u003cdetails\u003e\u003csummary\u003eClick to expand\u003c/summary\u003e\n\n```cmake\ncmake_minimum_required(VERSION 3.9)\nproject(FormatOutput CXX)\n\nlist(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})\nlist(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})\n\nadd_definitions(\"-std=c++11\")\n\nif(NOT EXISTS \"${CMAKE_BINARY_DIR}/conan.cmake\")\n  message(STATUS \"Downloading conan.cmake from https://github.com/conan-io/cmake-conan\")\n  file(DOWNLOAD \"https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake\"\n                \"${CMAKE_BINARY_DIR}/conan.cmake\"\n                TLS_VERIFY ON)\nendif()\n\ninclude(${CMAKE_BINARY_DIR}/conan.cmake)\n\nconan_cmake_configure(REQUIRES fmt/6.1.2\n                      GENERATORS cmake_find_package)\n\nconan_cmake_autodetect(settings)\n\nconan_cmake_install(PATH_OR_REFERENCE .\n                    BUILD missing\n                    REMOTE conancenter\n                    SETTINGS ${settings})\n\nfind_package(fmt)\n\nadd_executable(main main.cpp)\ntarget_link_libraries(main fmt::fmt)\n```\n\n\u003c/details\u003e\n\nMoreover, there's an important problem that made Conan 2.X decide to deprecate cmake-conan, which is the **Chicken-And-Egg(CAE)** problem with CMakeToolchain (See more details on this [issue](https://github.com/conan-io/cmake-conan/issues/447)). Therefore, this project provides an alternative way to use cmake-conan, which can solve the CAE problem.\n\n## Usage\n\nUsers just need to do the following two things:\n\n- Prepare a conan recipe (`conanfile.txt` or `conanfile.py`) in the root source directory.\n- Specify cache variable [CMAKE_PROJECT_INCLUDE_BEFORE](https://cmake.org/cmake/help/latest/variable/CMAKE_PROJECT_INCLUDE_BEFORE.html) with [`conan-setup.cmake`](./conan-setup.cmake).\n\nAnd then, all the installation of dependencies will be **DONE** automatically when they configure their projects.\n\nYou can grab a specific version of `conan.cmake` from cmake-conan to your project alongside with `conan-setup.cmake`. Otherwise, `conan-setup.cmake` will download the lastest version of `conan.cmake` from the master branch of cmake-conan.\n\n## Mechanism\n\nThe idea of this project is inspired by this [article](https://www.qt.io/blog/qt-creator-cmake-package-manager-auto-setup) of Qt Blog, which introduces a custom toolchain file called `auto-setup.cmake` (You can check its content [here](https://code.qt.io/cgit/qt-creator/qt-creator.git/plain/src/share/3rdparty/package-manager/auto-setup.cmake)). After simplifying the file and replacing the old APIs of cmake-conan with the new one into [`conan-setup.cmake`](./conan-setup.cmake), there are 4 steps of the mechanism:\n\n1. Include `conan.cmake` and scan for conan recipes in the root source directory.\n2. Create a new `CMakeLists.txt`, in which APIs of cmake-conan are used, by calling `file(WRITE)`.\n3. Configure the generated `CMakeLists.txt` by calling `execute_process(COMMAND ${CMAKE_COMMAND})`.\n4. Include `conan_toolchain.cmake` generated by CMakeToolchain at the end of `conan-setup.cmake`.\n\nTherefore, we can include `conan_toolchain.cmake` **BEFORE** the invocation of the first `project()` command. As we can see, the mechanism successfully solves the CAE problem.\n\n## Cache Variables\n\nThere are some default or custom variables that will take effect in [`conan-setup.cmake`](./conan-setup.cmake).\n\n| Cache Variables                                                                                       | Default Value\u003c/br\u003e(if not specified) | Effects                                                                                                                                            |\n| ----------------------------------------------------------------------------------------------------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [CMAKE_CONFIGURATION_TYPES](https://cmake.org/cmake/help/latest/variable/CMAKE_CONFIGURATION_TYPES.html) | `Debug;Release`                        | If you're using Multi-Config generators, then it will run `conan install` command with all the config types listed in this variable recursively. |\n| CMAKE_CONAN_OUPTUT_FOLDER                                                                             | `conan-deps`                   | The subfolder where `conan install` command generates files inside the build directory.                                                          |\n| CMAKE_CONAN_OUTPUT_QUIET                                                                              | `false`                                | Disable the output message of running `conan install` command if we set it to `true`.                                                          |\n| CMAKE_CONAN_ERROR_QUIET                                                                               | `false`                                | Disable the error message of running `conan install` command if we set it to `true`.                                                           |\n\n## Prerequisites\n\n- CMake (at least version **3.23** for using some features needed in `CMakePresets.json`)\n- Ninja (for using `Ninja` or `Ninja Multi-Config` generator)\n- C/C++ Compilers\n\nThere are some installation guides for your reference:\n\n- [Installation Guide for Windows](docs/install-guide-windows.md)\n- [Installation Guide for Linux](docs/install-guide-linux.md)\n- [Installation Guide for MacOS](docs/install-guide-macos.md)\n\n## Configure Presets\n\nThere are some configure presets in [`CMakePresets.json`](CMakePresets.json). You can run [`cmake --list-presets`](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-list-presets) command to check all the available configure presets for your platform, and then run [`cmake --preset \u003cpreset-name\u003e`](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-preset) to configure the project.\n\n### Windows-specific Presets\n\n\u003cdetails\u003e\u003csummary\u003eClick to expand\u003c/summary\u003e\n\n```cmd\nF:\\GitRepo\\cmake-conan-setup\u003ecmake --list-presets\nAvailable configure presets:\n\n  \"win32-msvc-x64-ninja-debug\"      - Windows MSVC x64 (Ninja) Debug\n  \"win32-msvc-x64-ninja-release\"    - Windows MSVC x64 (Ninja) Release\n  \"win32-msvc-x64-nmake-debug\"      - Windows MSVC x64 (NMake Makefiles) Debug\n  \"win32-msvc-x64-nmake-release\"    - Windows MSVC x64 (NMake Makefiles) Release\n  \"win32-msvc-x64-ninja-multi\"      - Windows MSVC x64 (Ninja Multi-Config)\n  \"win32-msvc-x64-vs2019-multi\"     - Windows MSVC x64 (Visual Studio 16 2019)\n  \"win32-msvc-x86-ninja-debug\"      - Windows MSVC x86 (Ninja) Debug\n  \"win32-msvc-x86-ninja-release\"    - Windows MSVC x86 (Ninja) Release\n  \"win32-msvc-x86-nmake-debug\"      - Windows MSVC x86 (NMake Makefiles) Debug\n  \"win32-msvc-x86-nmake-release\"    - Windows MSVC x86 (NMake Makefiles) Release\n  \"win32-msvc-x86-ninja-multi\"      - Windows MSVC x86 (Ninja Multi-Config)\n  \"win32-msvc-x86-vs2019-multi\"     - Windows MSVC x86 (Visual Studio 16 2019)\n  \"win32-gcc-x64-ninja-debug\"       - Windows GCC x64 (Ninja) Debug\n  \"win32-gcc-x64-ninja-release\"     - Windows GCC x64 (Ninja) Release\n  \"win32-gcc-x64-mingw-debug\"       - Windows GCC x64 (MinGW Makefiles) Debug\n  \"win32-gcc-x64-mingw-release\"     - Windows GCC x64 (MinGW Makefiles) Release\n  \"win32-gcc-x64-ninja-multi\"       - Windows GCC x64 (Ninja Multi-Config)\n  \"win32-gcc-x86-ninja-debug\"       - Windows GCC x86 (Ninja) Debug\n  \"win32-gcc-x86-ninja-release\"     - Windows GCC x86 (Ninja) Release\n  \"win32-gcc-x86-mingw-debug\"       - Windows GCC x86 (MinGW Makefiles) Debug\n  \"win32-gcc-x86-mingw-release\"     - Windows GCC x86 (MinGW Makefiles) Release\n  \"win32-gcc-x86-ninja-multi\"       - Windows GCC x86 (Ninja Multi-Config)\n  \"win32-clangcl-x64-ninja-debug\"   - Windows ClangCL x64 (Ninja) Debug\n  \"win32-clangcl-x64-ninja-release\" - Windows ClangCL x64 (Ninja) Release\n  \"win32-clangcl-x64-ninja-multi\"   - Windows ClangCL x64 (Ninja Multi-Config)\n  \"win32-clangcl-x86-ninja-debug\"   - Windows ClangCL x86 (Ninja) Debug\n  \"win32-clangcl-x86-ninja-release\" - Windows ClangCL x86 (Ninja) Release\n  \"win32-clangcl-x86-ninja-multi\"   - Windows ClangCL x86 (Ninja Multi-Config)\n  \"win32-clang-x64-ninja-debug\"     - Windows Clang x64 (Ninja) Debug\n  \"win32-clang-x64-ninja-release\"   - Windows Clang x64 (Ninja) Release\n  \"win32-clang-x64-ninja-multi\"     - Windows Clang x64 (Ninja Multi-Config)\n  \"win32-clang-x86-ninja-debug\"     - Windows Clang x86 (Ninja) Debug\n  \"win32-clang-x86-ninja-release\"   - Windows Clang x86 (Ninja) Release\n  \"win32-clang-x86-ninja-multi\"     - Windows Clang x86 (Ninja Multi-Config)\n```\n\n\u003c/details\u003e\n\n### Linux-specific Presets\n\n### MacOS-specific Presets\n\n## Demonstrations\n\n\u003e NOTE:\n\u003e\n\u003e - You need to call `vcvarsall.bat \u003cargument\u003e` to setup environment before configuring the MSVC and ClangCL presets except those using Visaul Studio generator. (Only avaliable in `cmd.exe` not in `powershell.exe`)\n\u003e - You may need to modify the `\"environment\"` settings yourself if the Clang/LLVM or GCC/MinGW Compiler is installed on other locations.\n\n## Integration with IDEs\n\n### Visual Studio Code (CMake Tools)\n\n1. Open the project folder by Visual Studio Code.\n2. Install [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) extension.\n3. Type **\"CMake: Select Configure Preset\"** on Command Palette (`Ctrl+Shift+P`).\n4. Type **\"CMake: Configure\"** on Command Palette (`Ctrl+Shift+P`).\n\n\u003cimg src=\"docs/img/vscode-demo.gif\" width=\"800\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwhsu1231%2Fcmake-conan-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhwhsu1231%2Fcmake-conan-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwhsu1231%2Fcmake-conan-setup/lists"}