How to add autotools-based project as biicode block? - c++

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!

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")

CMake GLOB not returning any source files?

I am trying to automatically have my Makefiles written for my C++ project using CMake with GLOB. The code and headers are however located in two separate folders.
/Users/username/Coding/Major Projects/ProjectName/Backend
and
/Users/username/Coding/Major Projects/ProjectName/Terminal
The backend has platform independent code. Just a bunch of c and c++ source files. And the Terminal folder has some code that uses the objects specified in Backend to run some tests on them. The reason these are in separate folders is that the Backend code is Multiplatform. So an Xcode project imports it etc. The Terminal folder has the testing code because that is the only one that is trying to compile it into a linux binary.
Anywho, I have the following CMakeList.txt file that I am trying to build to generate the Makefile.
cmake_minimum_required(VERSION 2.8.9)
project(terminalTest)
set(MainSource "/Users/username/Coding/Major Projects/ProjectName/Backend")
set(TerminalSource "/Users/username/Coding/Major Projects/ProjectName/Terminal")
#Bring the headers, such as Student.h into the project
include_directories(${MainSource} ${TerminalSource})
#Can manually add the sources using the set command as follows:
#set(SOURCES src/mainapp.cpp src/Student.cpp)
#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "./{${MainSource},${TerminalSource}}/*.cpp")
add_executable(terminalTest ${SOURCES})
And the result of this when I run this from the CMake GUI is a successful configure but an error No SOURCES given to target: terminalTest meaning that my file() command is not working properly.
I think it could have something to do with the fact that I have spaces in my paths but that doesn't seem to do it either. By the way I am putting this file in the Terminal folder and attempting to build from Terminal/Build.
Is there any way to debug and see what sources the GLOB command is bringing in? Can I actually do a multi directory GLOB like this?
Your file(GLOB ...) path looks malformed. You can list the paths to your sources separately in this command to grab all the source files in both directories.
file(GLOB SOURCES
${MainSource}/*.cpp
${TerminalSource}/*.cpp
)

cmake + cpp: No such file or directory

I've I'm trying to build this "Hello World" wxWidgets example on Linux, using the following cmake script:
cmake_minimum_required (VERSION 2.6)
project (wxL)
find_package(wxWidgets 3.0.0 REQUIRED
COMPONENTS base core net xml html adv qa richtext
)
file(GLOB SOURCES "src/*.cpp")
add_executable(wxL ${SOURCES})
Building the project yields this error:
src/wxL.cpp:3:10: fatal error: wx/wxprec.h: No such file or directory
The file specified in the include, wx/wxprec.h can be found on disk at this location:
/usr/include/wx-3.0/wx/wxprec.h
Furthermore, another program that I have built from source includes the same file (also using cmake) and builds just fine.
So, how do I use cmake to tell the compiler that the file should be included from somewhere in the system directories?
I know I'm missing something basic, but I can't figure out what.
Although you've found the package, your executable does not know anything about it.
For the executable to compile correctly, it needs to find header files for your package together with the .so / .a files. Following example should get you started:
include_directories(${wxWidgets_INCLUDE_DIRS})
add_executable(wxL <add-source-files-here>)
target_link_libraries(wxL ${wxWidgets_LIBRARIES}) // links wxWidgets libraries to your executable
Please note that using glob is not a recommended way of adding source files to your project.

CMake not building a library when added as a subdirectory

I added the xgboost library as a git submodule of my project and I'm trying to add it to cmake as a subdirectory. Unfortunately it's not working. A simple hello world project with the following CMakeLists.txt replicates the error that I'm getting.
cmake_minimum_required(VERSION 3.2)
project(foo)
add_subdirectory(xgboost)
add_executable(${PROJECT_NAME} foo.cpp)
target_link_libraries(${PROJECT_NAME} xgboost)
After building the library there is nothing in the xgboost/lib directory so I get the following error.
clang: error: no such file or directory:
'/Users/.../myproject/xgboost/lib/libxgboost.dylib'
I think that the problem is generated in their CMakeLists file since they have two different targets. Maybe cmake is choosing the wrong target but I'm not familiar enough with cmake to figure it out. The following code is from xgboost's CMakeLists.
# Executable
add_executable(runxgboost $<TARGET_OBJECTS:objxgboost> src/cli_main.cc)
set_target_properties(runxgboost PROPERTIES
OUTPUT_NAME xgboost
)
set_output_directory(runxgboost ${PROJECT_SOURCE_DIR})
target_link_libraries(runxgboost ${LINK_LIBRARIES})
# Shared library
add_library(xgboost SHARED $<TARGET_OBJECTS:objxgboost>)
target_link_libraries(xgboost ${LINK_LIBRARIES})
set_output_directory(xgboost ${PROJECT_SOURCE_DIR}/lib)
#Ensure these two targets do not build simultaneously, as they produce outputs with conflicting names
add_dependencies(xgboost runxgboost)
My questions in order of importance are:
Is there any way to fix it without modifying xgboost's CMakeLists.txt file?
Is it reasonable to try to add xgboost to my project as a git submodule?
Is there any reason cmake is not instructing to build the library?
Note: There were several edits to this question since I tried to narrow down the problem and to provide more information.
(I would love to ask for few things beforehand in the comment section, but I have too low reputation to do so, so I will just give it a shot ;))
I have few suspects, and one of them is ${CMAKE_SOURCE_DIR} of the submodule's root CMakeLists.txt. Although the paths are set properly when you run that CMakeLists.txt alone, cmake gets confused the moment you add it as your subdirectory. Have you looked into another directories for your output binaries?
First I would suggest testing this hypothesis, and then I would suggest writing similar, but separate CMakeLists.txt file for xgboost library, and then substitute it in the project temporarily. Unfortunately the CMakeLists.txt filename is hardcoded and there is no possibility to have two files of that kind in one directory; so it seems that the answer to 1) is, that you rather have to change the file.
For the 2): as long as it does not require huge additional logic in your CMakeLists.txt, it makes sense. Other viable option is to create an install target, which you can use to install your xgboost library locally (using CMAKE_INSTALL_PREFIX(doc) variable), and then add the installation path to your CMAKE_LIBRARY_PATH(doc).

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

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.