Trying to build the hello world example, but the cmake always complain
By not providing "Findaws-lambda-runtime.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"aws-lambda-runtime", but CMake did not find one.
Environment
OS : ubuntu18.04.3 LTS,64bits
install curl by : sudo apt-get install libcurl4-openssl-dev
install cmake by ubuntu software(cmake version 3.16.1)
Steps to build and install aws lambda cpp
git clone https://github.com/awslabs/aws-lambda-cpp.git
cd aws-lambda-cpp
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=${PWD}/install
make -j2
sudo make install
CmakeLists.txt(omit another part, want to make sure find_package works first)
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(aws_cpp_test LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/")
list(APPEND CMAKE_MODULE_PATH "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
find_package(aws-lambda-runtime REQUIRED)
add_executable(${PROJECT_NAME} "main.cpp")
I do not use the ec2 to build the project, how could I tell the cmake where should it find the aws-lambda-runtime?
Edit :
Based on the suggestion of Yevhenii Mamontov, I change the CMakeLists.txt to
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(aws_cpp_test LANGUAGES CXX)
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH}")
#check the prefix paths are correct or wrong
foreach(path ${CMAKE_PREFIX_PATH})
message("Path: " ${path})
endforeach(path)
find_package(aws-lambda-runtime REQUIRED)
But it come with different error message
CMake Error at
/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/aws-lambda-runtime-config.cmake:6
(include): include could not find load file:
/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/#CMAKE_PROJECT_NAME#-targets.cmake
I tried with different paths
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install")
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install/lib/aws-lambda-runtime/cmake")
and tried to do not add any new path, but all of them give the same error messages
Edit 2 :
Find a way to make it work
Remove the contents of /home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/aws-lambda-runtime-config.cmake
set path as set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install/lib/aws-lambda-runtime/cmake")
However, this solution is awkward, should ask the cmake do not search from the path "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake" first
Edit 3:
The solution I written in Edit 2 do not work. It fail when I add
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} PUBLIC AWS::aws-lambda-runtime)
Error messages are
Target "aws_cpp_test" links to target "AWS::aws-lambda-runtime" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
Could you try to set CMAKE_PREFIX_PATH just before the find_package?
Something like this:
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH}")
The first set() creates a variable with the path to your lib cmake folder.
The second set() appends to CMAKE_PREFIX_PATH one more path to search for any package that you've indicated in find_package().
Find out the solution, all you need to do are set the path of the aws library installed.
Example:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(encoder LANGUAGES CXX)
set(AWS_LAMBDA_CMAKE ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdLibs/aws-lambda-cpp/build/install/)
set(AWS_LAMBDA_CPP_SDK ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdLibs/aws-sdk-cpp/build/install/)
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH};${AWS_LAMBDA_CPP_SDK}")
find_package(CURL REQUIRED)
find_package(aws-lambda-runtime REQUIRED)
find_package(AWSSDK COMPONENTS s3)
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME}
${CURL_LIBRARIES}
AWS::aws-lambda-runtime
${AWSSDK_LINK_LIBRARIES})
aws_lambda_package_target(${PROJECT_NAME})
You may need to install following libs on your ubuntu if you haven't
sudo apt-get install zlib1g-dev libssl-dev libcurl4-openssl-dev
I got the same error, the answer marked as solution worked pretty well, but I also found tha this works:
set(aws-lambda-runtime_DIR /lib/aws-lambda/lib64/aws-lambda-runtime/cmake/)
I am using CMake 3.13 and had the lambda runtime installed on "/lib/aws-lambda" when running tha cmake as instructed by the installation instructions:
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/lib/aws-lambda
Related
Context:
I have a cpp program built on MacOS 12.6 with the following CMakeLists.txt file.
cmake_minimum_required(VERSION 3.19.0)
project(cpp-test VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_executable(cpp-test main.cpp)
add_library(test-helpers main.cpp ${PROJECT_SOURCE_DIR}/helpers.hpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
# this is super important in order for cmake to include the vcpkg search/lib paths!
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
# find library and its headers
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket/IXWebSocket.h)
find_library(IXWEBSOCKET_LIBRARY ixwebsocket)
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)
# include headers
include_directories(${IXWEBSOCKET_INCLUDE_DIR} ${CURL_INCLUDE_DIR})
# Cmake will automatically fail the generation if the lib was not found, i.e is set to NOTFOUND
target_link_libraries(
${PROJECT_NAME} PRIVATE
${IXWEBSOCKET_LIBRARY}
OpenSSL::SSL
OpenSSL::Crypto
${CURL_LIBRARIES}
"-framework Foundation"
"-framework Security"
"-lz"
)
This compiles just fine. However, when I try to pull it into my Ubuntu VM and try to build it /build> cmake .., I get the following errors
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of "cpp-test":
"IXWEBSOCKET_INCLUDE_DIR-NOTFOUND"
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of
"test-helpers":
"IXWEBSOCKET_INCLUDE_DIR-NOTFOUND"
-- Generating done
What I have tried...
I have installed vcpkg and created my symlink ln -s /path/to/vcpkg /usr/local/bin/vcpkg.
I have installed ixwebsocket via vcpkg install ixwebsocket, but it seems that the CMAKE_TOOLCHAIN_FILE is not being parsed correctly.
I'm a bit lost, any help would be appreciated
This is not a great answer to the issue, but I ended up resolving it by building ixwebsocket via CMake instead.
It seems that vcpkg was not compatible with the linux distro in my VM.
Before saying anything: Yes, I googled and searched for a long time before asking this here so 99% the solution of other similar questions doesn't work for me.
I have an opengl application that uses the following libraries:
glfw
imgui
glad
stb
assimp
glm
filebrowser (an extension of imgui for dialog boxes)
all these libraries are in a folder called external each one in its dir.
Moreover, glfw, assimp, glm are git submodules of my repo so they're downloaded when i clone my repo with git clone --recursive mygitrepo.
You can have a better understanding of the structure of the project looking at my git repo.
My idea was to use the add_subdirectories to make them compile with their own CMakeLists and my main one looks like this:
cmake_minimum_required(VERSION 3.21.3)
project(Reskinner)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
add_executable(${PROJECT_NAME} Main.cpp)
add_subdirectory(external/glfw)
add_subdirectory(external/assimp)
add_subdirectory(external/glad)
add_subdirectory(external/imgui)
add_subdirectory(external/stb)
add_subdirectory(external/glm)
add_subdirectory(external/FileBrowser)
add_subdirectory(src)
find_package(OpenGL REQUIRED)
target_include_directories(${PROJECT_NAME}
PUBLIC external/glfw/include
PUBLIC external/assimp/include
PUBLIC external/glm
PUBLIC external
PUBLIC src
)
target_link_libraries(${PROJECT_NAME} glfw glad imgui stb glm Engine assimp FileBrowser)
The project was developed with visual studio on windows and I want to compile it on linux without using visualstudio. The cmake doesn't give me any errors but when i run the make command it gives me this error:
#include <assimp/quaternion.h> there's no file or directory with this name.
like i didn't put the assimp include folder in the cmake (but i did).
Do you have any idea how to make it works? I want to make a bash script to install all the dependencies and tools needed like xorg-dev, build-essential, git, cmake, make etc. So if there's any simple fix using some bash commands it's ok for me.
I figured out how to fix it. I just installed conan and used it to download and find assimp. So I removed assimp, glm, glfw and glad from 'external' folder and just added a conanfile.txt.
Here the conanfile.txt:
[requires]
assimp/5.2.2
glfw/3.3.7
glm/0.9.9.8
glad/0.1.35
[generators]
cmake_find_package
cmake_paths
my main CMakeLists.txt now it's as following:
cmake_minimum_required(VERSION 3.21.3)
project(Reskinner)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
add_executable(${PROJECT_NAME} Main.cpp)
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
# Retrieve conan.cmake
if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/master/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
endif ()
include("${CMAKE_BINARY_DIR}/conan.cmake")
conan_cmake_run(CONANFILE "conanfile.txt" BASIC_SETUP UPDATE BUILD missing)
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
find_package(OpenGL REQUIRED)
find_package(glad REQUIRED)
find_package(glfw3 REQUIRED)
find_package(glm REQUIRED)
find_package(assimp REQUIRED)
add_subdirectory(external/stb)
add_subdirectory(external/imgui)
add_subdirectory(external/FileBrowser)
add_subdirectory(src)
file(MAKE_DIRECTORY
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Shaders")
function(install_file_to_bin file_name)
file(INSTALL "${CMAKE_SOURCE_DIR}/Shaders/${file_name}" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Shaders")
endfunction()
install_file_to_bin(1.model_loading.fs)
install_file_to_bin(1.model_loading.vs)
install_file_to_bin(4.1.fshader.fs)
install_file_to_bin(4.1.vshader.vs)
install_file_to_bin(animated_model_loading.fs)
install_file_to_bin(animated_model_loading.gs)
install_file_to_bin(animated_model_loading.vs)
install_file_to_bin(bb.vs)
install_file_to_bin(bb.fs)
install_file_to_bin(default.frag)
install_file_to_bin(default.fs)
install_file_to_bin(default.geom)
install_file_to_bin(default.vert)
install_file_to_bin(default.vs)
install_file_to_bin(floor.fs)
install_file_to_bin(floor.vs)
install_file_to_bin(framebuffer.frag)
install_file_to_bin(framebuffer.vert)
install_file_to_bin(grey_model.fs)
install_file_to_bin(grey_model.vs)
install_file_to_bin(hover.fs)
install_file_to_bin(hover.vs)
install_file_to_bin(influence_of_single_bone.fs)
install_file_to_bin(influence_of_single_bone.vs)
install_file_to_bin(mouse_shader.fs)
install_file_to_bin(mouse_shader.vs)
install_file_to_bin(normal_visualizer.fs)
install_file_to_bin(normal_visualizer.gs)
install_file_to_bin(normal_visualizer.vs)
install_file_to_bin(no_lighting_shader.fs)
install_file_to_bin(no_lighting_shader.vs)
install_file_to_bin(num_bones_visualization.fs)
install_file_to_bin(num_bones_visualization.vs)
install_file_to_bin(screen_shader.fs)
install_file_to_bin(screen_shader.vs)
install_file_to_bin(selected.fs)
install_file_to_bin(selected.vs)
install_file_to_bin(smooth_lighting_shader.fs)
install_file_to_bin(smooth_lighting_shader.vs)
install_file_to_bin(wireframe.vs)
install_file_to_bin(wireframe.fs)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE 1)
set(CMAKE_LINK_WHAT_YOU_USE 1)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
include_directories(
${OpenGL_INCLUDE_DIRS}
${glad_INCLUDE_DIRS}
${glfw3_INCLUDE_DIRS}
${glm_INCLUDE_DIRS}
${assimp_INCLUDE_DIRS}
external
src
)
target_link_libraries(${PROJECT_NAME}
${OpenGL_LIBRARIES}
${glad_LIBRARIES}
${glfw3_LIBRARIES}
${glm_LIBRARIES}
stb
${assimp_LIBRARIES}
imgui
FileBrowser
Engine
)
Some notes that can be usefull for other people having this troubles:
Assimp has some linking problem when used with conan because it seems that it doesn't download everything but just what you need so it works for the #include but it complains in the linking phase. Adding the following 3 rows fixed the problem:
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE 1)
set(CMAKE_LINK_WHAT_YOU_USE 1)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
I have a script to install everything you need on linux and install the stuff with conan, launch the cmake etc.. Even if I install the conan packages with the command conan install .. [...] I need the conan.cmake file so the lines at the beginning looking for the conan.cmake files fixed a lot of problems
The shell scripts is the following:
#!/bin/bash
sudo apt-get update
sudo apt-get install git
sudo apt-get install xorg-dev
sudo apt-get install make
sudo apt-get install cmake
sudo apt-get install build-essential
cd build
rm -rf *
conan install .. --settings os="Linux" --settings compiler="gcc" --settings compiler.version=11 --build missing
cmake -S .. -B . -D CMAKE_BUILD_TYPE=Release
make
cd build
Hope this can help you
I am trying to manually setup a CMake project that uses QT6 on Ubuntu 20.04 LTS.
This is what the CMakeLists.txt looks like:
cmake_minimum_required(VERSION 3.16)
project(Button, LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_PREFIX_PATH "home/ilmu011/Qt/6.2.3/gcc64")
find_package(Qt6 REQUIRED COMPONENTS Widgets)
add_executable(Button
main.cpp
)
However, CMake states that it doesn't find the QT6 installation. It is installed under home/ilmu011/Qt/6.2.3/gcc64. But I get an error message:
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt6", but
CMake did not find one.
Could not find a package configuration file provided by "Qt6" with any of
the following names:
Qt6Config.cmake
qt6-config.cmake
Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
to a directory containing one of the above files. If "Qt6" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/ilmu011/Desktop/Button/build/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:176: cmake_check_build_system] Error 1
It tells me to set the CMAKE_PREFIX_PATH to the QT6 location, which I did here, but it still doesn't work. I searched around for a solution and found this post:
CMAKE_PREFIX_PATH doesn't help CMake in finding Qt5
It says since the error message also states that eventually a separate development package is required that would eventually provide the "qt6-config.cmake" that CMake complains is not there, I should try installing these two things:
sudo apt-get install qtbase5-dev
sudo apt-get install qtdeclarative5-dev
However, these are for QT5 and that didn't work. How can I get CMake to detect QT6?
On ubuntu, the package qt6-base-dev provides Qt6Config.cmake. With this, cmake finds the qt6 libraries installed with apt, without helping it with the option CMAKE_PREFIX_PATH.
sudo apt install qt6-base-dev
I'm setting up a c++ project, which uses cmake and has two build type:
debug, having a cmake-build-debug folder
release, having a cmake-build-release folder
I want to add plog through cmake, so I installed it successfully by defining a conanfile.txt:
[requires]
plog/1.1.5
[generators]
cmake
then, I conan install . on my root and I edited my CMakeLists.txt like this:
set(CMAKE_VERBOSE_MAKEFILE ON)
cmake_minimum_required(VERSION 3.17)
project(test)
set(CMAKE_CXX_STANDARD 20)
set(CXX_EXTENSIONS OFF)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(LLVM_ENABLE_WARNINGS ON)
endif()
# ADDED ROW
include(conanbuildinfo.cmake)
add_executable(primo main.cpp io.cpp io.h)
# ADDED ROW
target_link_libraries(plog ${CONAN_LIBS})
the problem is that cmake complaints about the last row:
CMake Error at CMakeLists.txt:15 (target_link_libraries):
Cannot specify link libraries for target "plog" which is not built by this
project.
I'm new to cmake so maybe I've configured it badly. What seems to be the problem?
I am trying to run the example given in protobuf repo here, the c++ version. I have successfully installed the library and am able to run the Makefile. But on running the CMakeLists.txt, I get this error:
CMake Error at CMakeLists.txt:9 (find_package):
Could not find a package configuration file provided by "protobuf" with any
of the following names:
protobufConfig.cmake
protobuf-config.cmake
Add the installation prefix of "protobuf" to CMAKE_PREFIX_PATH or set
"protobuf_DIR" to a directory containing one of the above files. If
"protobuf" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/home/cortana/Projects/CppProjects/proto/build/CMakeFiles/CMakeOutput.log".
See also "/home/cortana/Projects/CppProjects/proto/build/CMakeFiles/CMakeError.log".
I have updated my LD_LIBRARY_PATH but this error is still there. How do I remove this error?
EDIT:
CMakeLists.txt:
# Minimum CMake required
cmake_minimum_required(VERSION 2.8.12)
# Project
project(protobuf-examples)
include(FindProtobuf)
# Find required protobuf package
find_package(protobuf CONFIG REQUIRED)
if(protobuf_VERBOSE)
message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}")
endif()
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
set(CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
${THIRDPARTY_DIR}/protobuf-3.1.0
)
include_directories(${ProtobufIncludePath})
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
if(MSVC AND protobuf_MSVC_STATIC_RUNTIME)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach()
endif()
foreach(example add_person list_people)
set(${example}_SRCS ${example}.cc)
set(${example}_PROTOS addressbook.proto)
#Code Generation
if(protobuf_MODULE_COMPATIBLE) #Legacy Support
protobuf_generate_cpp(${example}_PROTO_SRCS ${example}_PROTO_HDRS ${${example}_PROTOS})
list(APPEND ${example}_SRCS ${${example}_PROTO_SRCS} ${${example}_PROTO_HDRS})
else()
foreach(proto_file ${${example}_PROTOS})
get_filename_component(proto_file_abs ${proto_file} ABSOLUTE)
get_filename_component(basename ${proto_file} NAME_WE)
set(generated_files ${basename}.pb.cc ${basename}.pb.h)
list(APPEND ${example}_SRCS ${generated_files})
add_custom_command(
OUTPUT ${generated_files}
COMMAND protobuf::protoc
ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} ${proto_file_abs}
COMMENT "Generating ${generated_files} from ${proto_file}"
VERBATIM
)
endforeach()
endif()
#Executable setup
set(executable_name ${example}_cpp)
add_executable(${executable_name} ${${example}_SRCS} ${${example}_PROTOS})
if(protobuf_MODULE_COMPATIBLE) #Legacy mode
target_include_directories(${executable_name} PUBLIC ${PROTOBUF_INCLUDE_DIRS})
target_link_libraries(${executable_name} ${PROTOBUF_LIBRARIES})
else()
target_link_libraries(${executable_name} protobuf::libprotobuf)
endif()
endforeach()
EDIT 2:
After trying for 2 hours, I couldn't fix the CMakeLists.txt provided by google examples. I wrote this basic one and it works for me:
PROJECT(protopuff)
CMAKE_MINIMUM_REQUIRED (VERSION 3.5)
SET(CMAKE_CXX_FLAGS "-g -Wall -Werror -std=c++11")
INCLUDE(FindProtobuf)
FIND_PACKAGE(Protobuf REQUIRED)
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HEADER addressbook.proto)
ADD_LIBRARY(proto ${PROTO_HEADER} ${PROTO_SRC})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}_add add_person.cc)
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}_list list_people.cc)
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME}_add proto ${PROTOBUF_LIBRARY})
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME}_list proto ${PROTOBUF_LIBRARY})
Your problem is here:
find_package(protobuf CONFIG REQUIRED)
The name should start with uppercase: Protobuf. And that is the reason why your version is working; because in there, you have used correct case (last code snippet line 6):
find_package(Protobuf REQUIRED)
Here cmake documentation for find_package
The command searches for a file called <name>Config.cmake or <lower-case-name>-config.cmake for each name specified.
in this thread fraser solved the problem but if you need to develop according to protobuf CMake config and find_package command in CMake for finding protobuf libraries. your protobuf library must be compiled with CMake and do not use configure routine .
after compile protobuf with CMake , a config file named protobuf-config.cmake will be generated into the prefix/lib/CMake/protobuf directory.
The CmakeList.txt that is provided by the OP works on Linux but it does NOT work on Windows.
There is a way to make the actual CMakeList.txt work without any changes. The problem is that it requires the CONFIG parameter and that part is not documented anywhere. We need to provide the path to that config using -Dprotobuf_DIR parameter while generating the project.
On Windows, wherever you have installed protobuf, it will have bin, cmake, include, lib folders. We need to give the path of this cmake folder as an argument, like following:
cmake -G "Visual Studio 16 2019" -A x64 -B _build2 -Dprotobuf_DIR=C:/protobuf/install/cmake
This will build a solution file in the current directory.