I'm trying to run a project for an example of the Oat++ framework by loading libraries using conan.
My algorithm of actions:
conan install . --output-folder=build --build=missing
(after this command, the conan_toolchain.cmake file is created in the ./build)
cmake .. -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake
I am a beginner in this topic, I will be glad of any help!
conanfile.txt:
[requires]
oatpp/1.3.0
oatpp-swagger/1.3.0
oatpp-websocket/1.3.0
oatpp-openssl/1.3.0
[generators]
CMakeToolchain
CMakeDeps
CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
set(project_name my-project)
project(${project_name})
include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake)
set(CMAKE_CXX_STANDARD 17)
add_library(${project_name}-lib
src/AppComponent.hpp
src/controller/MyController.cpp
src/controller/MyController.hpp
src/dto/DTOs.hpp
)
## link libs
find_package(oatpp REQUIRED)
find_package(oatpp-swagger REQUIRED)
find_package(oatpp-websocket REQUIRED)
find_package(oatpp-openssl REQUIRED)
target_include_directories(${project_name}-lib PUBLIC
${CMAKE_BINARY_DIR}/conan_deps/include
)
target_link_libraries(${project_name}-lib
oatpp::oatpp
oatpp::oatpp-swagger
oatpp::oatpp-websocket
oatpp::oatpp-openssl
)
target_include_directories(${project_name}-lib PUBLIC src)
## add executables
add_executable(${project_name}-exe
src/App.cpp
test/app/MyApiTestClient.hpp
)
target_link_libraries(${project_name}-exe ${project_name}-lib)
add_dependencies(${project_name}-exe ${project_name}-lib)
add_executable(${project_name}-test
test/tests.cpp
test/app/TestComponent.hpp
test/app/MyApiTestClient.hpp
test/MyControllerTest.cpp
test/MyControllerTest.hpp
)
target_link_libraries(${project_name}-test ${project_name}-lib)
add_dependencies(${project_name}-test ${project_name}-lib)
set_target_properties(${project_name}-lib ${project_name}-exe ${project_name}-test PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
enable_testing()
add_test(project-tests ${project_name}-test)
The structure of the OATTP_STARTER project:
./build
./src
./test
CMakeLists.txt
conanfile.txt
In directories ./src and ./test have other directories and project files.
At the cmake build stage with the command
cmake .. -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake
I get an error:
CMake Warning:
Ignoring extra path from command line:
".cmake"
-- Building for: Visual Studio 17 2022
CMake Error at C:/Program Files/CMake/share/cmake-3.29/Modules/CMakeDetermineSystem.cmake:152 (message):
Could not find toolchain file: build/conan_toolchain
Call Stack (most recent call first):
CMakeLists.txt:5 (project)
-- Configuring incomplete, errors occurred!
================================================================
The above problem has been solved (namely, the cmake build error has disappeared). However, another problem has appeared
C:\Users\h4thq\prjcts\oat2\oatpp-starter\build>cmake --build . --config Release
MSBuild version 17.10.4+10fbfbf2e for .NET Framework
1>Checking Build System
Building Custom Rule C:/Users/h4thq/prjcts/oat2/oatpp-starter/CMakeLists.txt
MyController.cpp
C:\Users\h4thq\prjcts\oat2\oatpp-starter\src\dto\DTOs.hpp (4.10): error C1083: Unable to open file enable: oa
http/macro/codegen.hpp: No such file or directory, [C:\Users\h4thq\prjcts\oat2\oatpp-starter\build\my-project-lib.vc
xprog]
This time I tried to find information about this case, but I couldn't. As far as I understand, conan files seem to be unavailable. Do you have any thoughts on this?
In my case, @drodri's advice helped:In command line you might also quote -DCMAKE_TOOLCHAIN_FILE="build/conan_toolchain.cmake", as it seems this is a terminal command line parsing issue