filipdutescu / modern-cpp-template

A template for modern C++ projects using CMake, Clang-Format, CI, unit testing and more, with support for downstream inclusion.
The Unlicense
1.73k stars 215 forks source link

integrade with conan, pkg not found #22

Closed navono closed 3 years ago

navono commented 3 years ago

Describe the bug Enable CONAN option in StandardSettings.cmake, then add conanfile.txt:

[requires]
fmt/7.0.3

[generators]
cmake

To Reproduce Steps to reproduce the behavior:

  1. Reload in CMake tab
  2. enter cmake-build-debug directory

    make

  3. See error

    Scanning dependencies of target ADemo_LIB [ 12%] Building CXX object CMakeFiles/ADemo_LIB.dir/src/tmp.cpp.o Checking /mnt/d/sourcecode/cpp/modern-cpp-template-navono/src/tmp.cpp ... /mnt/d/sourcecode/cpp/modern-cpp-template-navono/src/tmp.cpp:3:0: style: The function 'add' is never used. [unusedFunction]

    ^ nofile:0:0: information: Unmatched suppression: missingInclude [unmatchedSuppression]

    [ 25%] Linking CXX static library lib/libADemo_LIB.a [ 25%] Built target ADemo_LIB Scanning dependencies of target ADemo [ 37%] Building CXX object CMakeFiles/ADemo.dir/src/main.cpp.o Checking /mnt/d/sourcecode/cpp/modern-cpp-template-navono/src/main.cpp ... /mnt/d/sourcecode/cpp/modern-cpp-template-navono/src/main.cpp:7:10: fatal error: fmt/format.h: No such file or directory 7 | #include <fmt/format.h> | ^~~~~~ compilation terminated. make[2]: [CMakeFiles/ADemo.dir/build.make:82: CMakeFiles/ADemo.dir/src/main.cpp.o] Error 1 make[1]: [CMakeFiles/Makefile2:172: CMakeFiles/ADemo.dir/all] Error 2 make: *** [Makefile:160: all] Error 2


Disable Conan option, add conan integrat command and link library in root CMakeLists.txt like this:

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup(TARGETS) ... target_link_libraries( ${PROJECT_NAME} PUBLIC CONAN_PKG::fmt )

reload cmake, and make, it works.


Expected behavior make successful.


Screenshots


Desktop (please complete the following information):


Additional context Clion connect WSL2 environment.

srihari-vistrian commented 3 years ago

You should not be adding the conanfile.txt. After enabling the Conan option, you need to edit the Conan.cmake and add the packages as follows:

set(${PROJECT_NAME}_CONAN_REQUIRES "cpprestsdk/2.10.18" "boost/1.76.0" "libuv/1.41.0" "spdlog/1.8.5" "rapidjson/cci.20200410" "nlohmann_json/3.9.1" "fmt/7.1.3" "date/3.0.1" "tbb/2020.3" "catch2/2.13.6")

navono commented 3 years ago

After using conan for a while, I think conanfile is easier to manage dependencies, so close.