Cap'n Proto CMake support: CAPNP_LIB_CAPNP-JSON is NOTFOUND - c++

Why do I have to set
set(CAPNP_LIB_CAPNP-JSON "")
in my CMakeLists.txt in order to not get an error? Error as follows:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CAPNP_LIB_CAPNP-JSON (ADVANCED)
linked by target "client" in directory <...>
linked by target "server" in directory <...>
The way I'm using capnproto CMake support is by copying the cmake file included in the capnproto source into my project and including it manually. (Is there a better / standard way to do this? Feels hackish.) The rest is just taken from the CMake file's instructions.
CMake snippet:
# so capnp cmake plugin is found
set(CapnProto_DIR "${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake")
# for some reason there is some json lib or something that isn't found?
#set(CAPNP_LIB_CAPNP-JSON "")
find_package(CapnProto REQUIRED)
include_directories(${CAPNP_INCLUDE_DIRS})
add_definitions(${CAPNP_DEFINITIONS})
set(CAPNPC_SRC_PREFIX "src/capnp")
# capnp out of source config
set(CAPNPC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CAPNPC_OUTPUT_DIR})
# gen cpp
capnp_generate_cpp(CAPNP_SRCS CAPNP_HDRS
src/capnp/schema.capnp
)
CMake 3.6.2, building using CLion's integrated build commands. capnp is installed via homebrew, latest version.
Why am I getting the error about the JSON bit? What is that about?
Also, is there a better way for including the official Cap'n Proto CMake file? It seemed to not get distributed with the header and library files when installing via homebrew.

It turns out json encoding/decoding support is an as yet (Oct 2016) unreleased feature of Cap'n Proto and trying to use the .cmake file from the master branch with the last released version produces this conflict.
Possible solutions:
1) Use workaround posted in the question, i.e.
set(CAPNP_LIB_CAPNP-JSON "") # add this before next line
find_package(CapnProto REQUIRED)
2) Use the released version of the .cmake script here: FindCapnProto.cmake
3) Build and install Cap'n Proto from source, use with latest .cmake script.

Related

Crow microframework - CMake Error: The following variables are used in this project, but they are set to NOTFOUND

Here is the full error message:
Error CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
C:/Users/DELL/source/repos/CMakeProject1/CMakeProject1/CROW_INCLUDE_DIRS
used as include directory in directory C:/Users/DELL/source/repos/CMakeProject1/CMakeProject1 C:\Users\DELL\source\repos\CMakeProject1\ used as include directory in directory C
I am trying to use the Crow microframework but can't seem to make it work. I have downloaded the Crow package off of Github : https://github.com/ipkn/crow and used CMake to run a hello world from the Crow port. This is what I got in my .txt file
cmake_minimum_required (VERSION 3.8)
find_path(CROW_INCLUDE_DIRS "crow.h")
add_executable (CMakeProject1 "example_with_all.cpp" "crow_all.h")
target_include_directories(CMakeProject1 PRIVATE ${CROW_INCLUDE_DIRS})
My header file is crow_all.h which contains all the libraries and this is where the error is located. The compiler does not recognize all the "#include" used in this header file. I believed it would work because I had downloaded the entire Github repo and included it in my files.
My cpp file just includes the header file and does a Hello World.
I am a beginner at CMake, thank you for the help!
You should check out https://github.com/CrowCpp/Crow. It's an actively maintained version of the framework with a new build system (you should be able to just link it via CMake)
P.S. I suggest you use the master branch since it has quite a few improvements over the latest release.
Wow, crow's build is so broken that its own instructions fail on my system... it also hasn't been updated since 2017 (five years...). Assuming you still want to use it, I would just copy their amalgamated header, crow_all.h, into my source tree under, say, third_party/crow/crow_all.h and then write:
cmake_minimum_required(VERSION 3.22)
project(example)
add_executable(app "example_with_all.cpp")
target_include_directories(app PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/third_party/crow")

Could not find a package configuration file provided by "boost_atomic"

I am compiling C/C++ to wasm with emscripten. And need boost library as well. Pretty new to emscripten and wasm
After installing emscripten and boost. I ran the following command
emconfigure cmake -DBoost_DEBUG=1
-Dboost_headers_DIR=../boost_1_71_0/build/lib/cmake/boost_headers-1.71.0
-DBoost_DIR=../boost_1_71_0/build/lib/cmake/Boost-1.71.0 -Dboost_program_options_DIR=../boost_1_71_0/build/lib/cmake/boost_program_options-1.71.0
-Dboost_system_DIR=../boost_1_71_0/build/lib/cmake/boost_system-1.71.0 -Dboost_thread_DIR=../boost_1_71_0/build/lib/cmake/boost_thread-1.71.0 -Dboost_unit_test_framework_DIR=../boost_1_71_0/build/lib/cmake/boost_unit_test_framework-1.71.0
-DZLIB_INCLUDE_DIR=${HOME}/.emscripten_ports/zlib/zlib-version_1 -DZLIB_LIBRARY=${HOME}/.emscripten_cache/asmjs -DBUILD_TESTING=0 -DBoost_USE_STATIC_LIBS=ON -DBoost_USE_STATIC_RUNTIME=ON -DBUILD_EXEC=OFF -DBUILD_TESTING=OFF ..
I get the following error
CMake Error at /home/../boost_1_71_0/build/lib/cmake/boost_thread-1.71.0/boost_thread-config.cmake:91 (find_package):
Could not find a package configuration file provided by "boost_atomic"
(requested version 1.71.0) with any of the following names:
boost_atomicConfig.cmake
boost_atomic-config.cmake
Add the installation prefix of "boost_atomic" to CMAKE_PREFIX_PATH or set
"boost_atomic_DIR" to a directory containing one of the above files. If
"boost_atomic" provides a separate development package or SDK, be sure it
has been installed.
The boost_atomic-config.cmake is at /home/../boost_1_71_0/build/lib/cmake/boost_atomic-1.71.0/boost_atomic-config.cmake. How should I set the boost_atomic_DIR path to this file, as required above?
I added a flag -Dboost_atomic_DIR=/path/to/.cmake/file in the above command and it worked.

find_package with specified version in configuration script name

I need to use mangrove (mongo ODM lib over mongo-c-driver and mongo-cxx-driver) and included this into my project as CMake ExternalProject_Add command, with a dependency on mongo-c-driver/mongo-cxx-driver
mongocxx generates CMake configuration scripts with a names like :
libmongocxx-config.cmake
libmongocxx-config-version.cmake
and no issues to find these by mangrove with that script:
set(LIBMONGOCXX_REQUIRED_VERSION 3.1.3)
set(LIBMONGOCXX_REQUIRED_ABI_VERSION v_noabi)
find_package(libmongocxx ${LIBMONGOCXX_REQUIRED_VERSION} REQUIRED)
However mongo-c-driver generates those scripts with a name which incudes ABI version into file names.
libmongoc-1.0-config.cmake
libmongoc-1.0-config-version.cmake
and similar CMake code:
set(LIBMONGOC_REQUIRED_VERSION 1.7.0)
set(LIBMONGOC_REQUIRED_ABI_VERSION 1.0)
find_package(LibMongoC ${LIBMONGOC_REQUIRED_VERSION} REQUIRED)
can't find out the scripts.
Of course, if I manually remove the version from file names, it can find those files, but I'd like to fix the problem in a script and on mangove side.
So the question about CMake techniques :
Is there an ability to specify the version of package which will automatically used by (inside CMake scripts names) find_package command to look for?
According to find_package documentation, the version is embedded inside the libmongocxx-config-version.cmake file.
This means that if you want to get the package libmongoc-1.0-config.cmake, you should use:
find_package(libmongoc-1.0 ${LIBMONGOC_REQUIRED_VERSION} REQUIRED)

Building tensorflow serving client with cmake

I searched for the best way to do this, but I was unable to find a clear answer.
Was anyone able to build a tensorflow-serving client using cmake?
I am having difficulties with generating CPP files from proto, since they are needed for prediction service. Those proto files also include proto files from tensorflow.
so far I have come up with this:
project(serving C CXX)
find_package(Protobuf REQUIRED)
file(GLOB_RECURSE proto_files RELATIVE ${serving_SOURCE_DIR}/tensorflow/
"${serving_SOURCE_DIR}/tensorflow/*.proto")
set(PROTOBUF_GENERATE_CPP_APPEND_PATH OFF)
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${proto_files})
add_library(tf_protos ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(tf_protos PUBLIC ${PROTOBUF_LIBRARIES})
Cmake builds successfully but the make command gives me an error:
No rule to make target '../tensorflow/tools/proto_text/test.proto', needed by 'tensorflow/tools/proto_text/test.pb.cc'. Stop.
To overcome the problem of .proto includes not being found I used command
set(PROTOBUF_GENERATE_CPP_APPEND_PATH OFF)
which was explained here: https://groups.google.com/forum/#!topic/protobuf/eow2fNDUHvc
My current folder structure is
serving/
CmakeLists.txt
tensorflow/
tensorflow_serving/
apis/
Folder apis contains .proto files that are needed in the client implementation and they include .proto files from the folder tensorflow.
Is this even the right way to go?
Any help/advice would be much appreciated.
I was able to get it to work in the layout you have where the CMakeLists.txt file is placed in the same level as the serving repository here. You'll need to install Tensorflow too though (using tensorflow_cc).
However, you probably don't want to muck with a fork of the official tensorflow/serving repository so I went a step further and moved the CMakeLists.txt out so you can just submodule the official repository. I made an example here
The gist is that the protobuf CMake submodule expects proto files to be laid out in the same directory from which it's called. I made some modifications to the submodules to let us call it from a level above serving and to ensure it invokes the compiler with the include paths in the right order to support the nested structure of the proto files in serving/tensorflow_serving/apis/* (and placing it accordingly in the specified build directory)
Hopefully someone else with better knowhow can make this better!
These worked for me.
https://github.com/wardsng/inception_cmake
https://github.com/FloopCZ/tensorflow_cc
You can choose a private install directory instead of the default, e.g. /usr/local/...
cmake -DCMAKE_INSTALL_PREFIX= ..

How to add autotools-based project as biicode block?

I need to use log4cpp in my project and I'd like to add this library as biicode block.
I read the documentation and tried to prepare the library for biicode.
I get the source of log4cpp from sourceforge's git here.
log4cpp already has CMakeLists.txt, but when I tried to compile it with cmake on ubuntu linux, there was error: missing file log4cpp/config.h.
Apparently, log4cpp is autotools-based project and needs to run ./autogen.sh and then ./configure to prepare project for compilation on Ubuntu linux. When I called this commands, log4cpp/config.h file is appeared and I was able to compile project with cmake.
Then I added this code to CMakeLists.txt:
if (BIICODE)
include(biicode.cmake)
return()
endif()
and in biicode.cmake I added this code:
# remove tests targets
LIST(REMOVE_ITEM BII_BLOCK_EXES tests_testCategory tests_testConfig tests_testDLL tests_testDailyRollingFileAppender tests_testErrorCollision tests_testFilter tests_testFixedContextCategory tests_testNDC tests_testNDCMain tests_testNTEventLog tests_testPattern tests_testPriority tests_testPropConfig tests_testProperties tests_testPropertyConfig tests_testRollingFileAppender tests_test_convenience tests_testbench tests_testmain)
# remove unnecessary files from lib
LIST(REMOVE_ITEM BII_LIB_SRC
tests/Clock.cpp
tests/Clock.hh
tests/NDCTest.hh
)
ADD_BII_TARGETS()
Now I was able to build block with bii build. But when I published this block to biicode and tried to use it in other sample project, when I run bii find, biicode download log4cpp, but not all sources (for example, RollingFileAppender.cpp is not available after downloading).
My sample project that use log4cpp:
#include "log4cpp/Category.hh"
int main()
{
log4cpp::Category::getInstance("application");
return 0;
}
And I was need to add this section to biicode.conf file of sample project:
[includes]
log4cpp/*: halex2005/log4cpp/include
So, my questions is:
How I can prepare autotools-based project to be the biicode block in right way?
How to run ./auto-gen.sh and ./configure on bii configure command?
How to force biicode to download full list of sources for biicode block?
Thanks in advance!