Install QGLViewer using Cmake's ExternalProject_Add - cmake

I would like to install QGLViewer as an external from source code in a cmake build environment. This is what I have tried so far:
set(QGLViewer_VERSION 2.5.2)
set(QGLViewer_URL_REMOTE "http://www.libqglviewer.com/src/libQGLViewer-${QGLViewer_VERSION}.tar.gz")
ExternalProject_Add(QGLViewer
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/qglviewer
URL ${QGLViewer_URL_REMOTE}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND qmake PREFIX="${CMAKE_CURRENT_BINARY_DIR}/external/qglviewer" QGLVIEWER_STATIC=yes
BUILD_COMMAND make
)
cmake works just fine.
However, when running make, I get a bunch of compilation errors. make is finding the headers installed in my system instead of the ones of the build project directory:
make[4]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
Project MESSAGE: Warning: unknown QT: widgets
In file included from /usr/include/QGLViewer/manipulatedFrame.h:26:0,
from /usr/include/QGLViewer/manipulatedCameraFrame.h:26,
from /usr/include/QGLViewer/camera.h:26,
from /usr/include/QGLViewer/qglviewer.h:26,
from animation.h:23,
from animation.cpp:23:
/usr/include/QGLViewer/frame.h:139:3: error: ‘signals’ does not name a type
/usr/include/QGLViewer/frame.h:404:10: error: expected ‘:’ before ‘slots’
/usr/include/QGLViewer/frame.h:404:10: error: ‘slots’ does not name a type
NaN

The solution is to specify to perform the qmake on the file QGLViewer/QGLViewer.pro instead of the default .pro file located in the root folder libQGLViewer-2.5.2/
ExternalProject_Add(QGLViewer
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/qglviewer
URL ${QGLViewer_URL_REMOTE}
DOWNLOAD_DIR ${QGLViewer_DSTDIR}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND qmake QGLViewer/QGLViewer.pro QGLVIEWER_STATIC=yes PREFIX=${CMAKE_CURRENT_BINARY_DIR}/external/qglviewer
BUILD_COMMAND make
)

Related

ExternalProject_Add for Makefile project error during build

I am trying to add Postgresql as a dependency for my project for which I am using ExternalProject module to download the source from github and build, but the build step fails when running from cmake (cmake --build .). Configure step seems to succeed and if I go to the Build directory under EP_BASE and do a make it runs successfully. I get the following error during build:
<...>/Source/postgresql_external/src/common/relpath.c:21:10: fatal error: catalog/pg_tablespace_d.h: No such file or directory
21 | #include "catalog/pg_tablespace_d.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[5]: *** [<builtin>: relpath.o] Error 1
make[4]: *** [Makefile:42: all-common-recurse] Error 2
make[3]: *** [GNUmakefile:11: all-src-recurse] Error 2
My external project add looks like the following:
ExternalProject_Add(postgresql_external
GIT_REPOSITORY https://github.com/postgres/postgres.git
GIT_TAG REL_12_4
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR>
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
)
This is running on Ubuntu 20.04 LTS, with cmake 3.16.3, gcc 9.3.0
try
ExternalProject_Get_Property(postgresql_external install_dir)
include_directories(${install_dir}/include)
I guess, you haven't propagate include directory to your target yet, but it is evtl. known to your system (thus successful call of manually called make)
Try the following code, it works for me. PotgreSQL uses MAKELEVEL variable to generate header files via perl. When you call make directly it works as expected. But it seems that cmake adds more levels to PotgreSQL's root make, so headers are not generated.
CONFIGURE_COMMAND ./configure <your options>
BUILD_IN_SOURCE 1
BUILD_COMMAND $(MAKE) MAKELEVEL=0

How to set CMake variable to include directory

When trying to build this library with Cmake from the Developer Command Prompt for VS, I get this error
CMake Error at cmake/FindEigen.cmake:77 (MESSAGE):
Failed to find Eigen - Could not find eigen3 include directory, set
EIGEN_INCLUDE_DIR to path to eigen3 include directory, e.g.
/usr/local/include/eigen3.
I'd like find out what was intended of me here: am I to set EIGEN_INCLUDE_DIR with a command line argument or by editing the make file?
I've tried cmake -D EIGEN_INGLUDE_DIR=C:\Users\a\Downloads\eigen-3.3.7\eigen-3.3.7 . but received the same error.
cmake -D EIGEN_INGLUDE_DIR=C:\Users\a\Downloads\eigen-3.3.7\eigen-3.3.7 . failed without creating any files (cmake .. at least started building) and gave me this error
CMake Error: The source "C:/Users/a/Downloads/RpolyPlusPlus-master/RpolyPlusPlus-master/build/CMakeLists.txt" does not match the source "C:/Users/a/Downloads/RpolyPlusPlus-master/RpolyPlusPlus-master/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.
So I just ended up adding this to the .cmake file:
# TODO: Add standard Windows search locations for Eigen.
LIST(APPEND EIGEN_CHECK_INCLUDE_DIRS
/usr/local/include
/usr/local/homebrew/include # Mac OS X
/opt/local/var/macports/software # Mac OS X.
/opt/local/include
/usr/include
C:\\Users\\a\\Downloads\\eigen-3.3.7) <---------------------------------------

CMakeLists.txt not in root directory, can't do an automatic build

I have an issue with a repository not having its CMakeLists in the root directory, namely https://github.com/lz4/lz4
The CMakeLists.txt is in the subfolder contrib/cmake_unofficial.
I already checked similar questions on SO (Is it possible to have cmake build file (CMakeLists.txt) not in root in CLion, cmake - CMakeLists.txt is not in root folder (but is included in source)), but they only provide alternatives, and not a solution applicable to my situation.
Heres the cmake module I came up with:
if(ENABLE_LZ4)
message(STATUS "Using LZ4.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_LZ4")
# Enable ExternalProject CMake module
include(ExternalProject)
set(LZ4_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/lz4)
set(LZ4_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib)
# Download and install lz4
ExternalProject_Add(
lz4
GIT_REPOSITORY https://github.com/lz4/lz4.git
GIT_TAG dev
SOURCE_DIR ${LZ4_SOURCE_DIR}
BINARY_DIR ${LZ4_BINARY_DIR}
INSTALL_COMMAND ""
CMAKE_ARGS
${LZ4_SOURCE_DIR}/contrib/cmake_unofficial
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
)
# Get lz4 source and binary directories from CMake project
ExternalProject_Get_Property(lz4 source_dir binary_dir)
# Create a liblz4 target to be used as a dependency by the program
add_library(liblz4 IMPORTED SHARED GLOBAL)
add_dependencies(liblz4 lz4)
include_directories(
${LZ4_SOURCE_DIR}/lib
)
set(LZ4_LIB ${LZ4_BINARY_DIR}/liblz4.so)
else()
message(STATUS "Not using LZ4.")
set(LZ4_LIB "")
endif()
Here the complete error output:
[ 0%] Performing update step for 'lz4'
Current branch dev is up to date.
[ 1%] Performing configure step for 'lz4'
CMake Error: The source directory "/****/build/lz4" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
CMakeFiles/lz4.dir/build.make:105: recipe for target 'lz4-prefix/src/lz4-stamp/lz4-configure' failed
make[2]: *** [lz4-prefix/src/lz4-stamp/lz4-configure] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/lz4.dir/all' failed
make[1]: *** [CMakeFiles/lz4.dir/all] Error 2
Makefile:94: recipe for target 'all' failed
make: *** [all] Error 2
I tried adding the path 'contrib/cmake_unofficial' to the CMAKE_ARGS variable (as seen in the module above), but it does not work (seems to be ignored?).
I also tried using PATCH_COMMAND to copy the CMakeLists.txt to the root before the build starts, but the relative paths of the file get messed up.
In other words, i need the cmake command to be called to build the library to be : cmake contrib/cmake_unofficial.
I also tried using CONFIGURE_COMMAND for this, but keep getting a file not found error for some reason (even though the path is correct).
The module has some other issues too, but I'm only interested in the non-root CMakeLists.
Thanks in advance!
ExternalProject separates download and source directories:
DOWNLOAD_DIR - a directory where downloading step is performed
SOURCE_DIR - a directory used as a source one when configuration step is performed
When use git for extract the project, note that git clone is called from the download directory, where it creates new directory with a project sources.
set(LZ4_DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/lz4)
# Set a source dir based on the download one.
set(LZ4_SOURCE_DIR ${LZ4_DOWNLOAD_DIR}/lz4/contrib/cmake_unofficial)
set(LZ4_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib)
# Download and install lz4
ExternalProject_Add(
lz4
DOWNLOAD_DIR ${LZ4_DOWNLOAD_DIR} # Set download directory explicitely
GIT_REPOSITORY https://github.com/lz4/lz4.git
GIT_TAG dev
SOURCE_DIR ${LZ4_SOURCE_DIR}
BINARY_DIR ${LZ4_BINARY_DIR}
...
)
Probably not the correct way to do it, but this seems to work for me.
I used the CONFIGURE_COMMAND to call cmake on the correct directory.
Then use BUILD_COMMAND to call make
So essentially, it breaks down to this:
ExternalProject_Add(
lz4
GIT_REPOSITORY https://github.com/lz4/lz4.git
GIT_TAG dev
SOURCE_DIR ${LZ4_SOURCE_DIR}
BINARY_DIR ${LZ4_BINARY_DIR}
CONFIGURE_COMMAND cmake ${LZ4_SOURCE_DIR}/contrib/cmake_unofficial
BUILD_COMMAND make
INSTALL_COMMAND ""
CMAKE_ARGS
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
)

project PROJECT called with incorrect number of arguments

when I enter the console:
mkdir build && cd build && cmake .. && make
error occurs:
CMake Error at CMakeLists.txt: 5 (project): project PROJECT called
with incorrect number of arguments
CMake Error at CMakeLists.txt: 19 (find_package): By not providing
"FindQt5Gui.cmake" in CMAKE_MODULE_PATH this project has requested
CMake to find a package configuration file provided by "Qt5Gui", but
CMake did not find one.
Could not find a configuration file provided by "Qt5Gui" with any
of the following names:
Qt5GuiConfig.cmake
qt5gui-config.cmake
Add the installation prefix of "Qt5Gui" to CMAKE_PREFIX_PATH or set
"Qt5Gui_DIR" to a directory containing one of the above files. If
"Qt5Gui" provides a separate development package or SDK, be sure it
has been installed.
on the forums write that this is due to the fact that not installed qt5-defult and gt5-dev-tools, but before the installation and after nothing has changed what to do?

CMake & ExternalProject: Fails to find specific file

We have some dependency libraries in our repository. The main part is build with cmake. Now the cmake-makefiles shall build the dependency libraries, which do not have a cmake build system. For one specific library there is a "Makefile.squirrel" which should be used. The cmakelists.txt for that library:
cmake_minimum_required (VERSION 2.8)
include(ExternalProject)
ExternalProject_Add(squirrel,
SOURCE_DIR "./"
UPDATE_COMMAND ""
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND "make -f ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.squirrel"
INSTALL_COMMAND ""
)
However, when running make I get an error message:
[ 93%] Performing build step for 'squirrel,'
/bin/sh: make -f /home/enrico/projekte/projectname/dependencies/SQUIRREL2/Makefile.squirrel: not found
make[2]: *** [dependencies/SQUIRREL2/squirrel,-prefix/src/squirrel,-stamp/squirrel,-build] Error 127
make[1]: *** [dependencies/SQUIRREL2/CMakeFiles/squirrel,.dir/all] Error 2
make: *** [all] Error 2
ls -lA on /home/enrico/projekte/projectname/dependencies/SQUIRREL2/Makefile.squirrel shows that the file exists.
Hardcoding the file path (not an option for the solution) does not work, too.
Any ideas or hints?
Three observations:
1) You're using "squirrel," as the name of the project. Arguments to CMake functions are space separated, so the comma is part of the name you've given. (Probably not what you want.)
2) You should use:
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
rather than
SOURCE_DIR "./"
Because the "./" is simply relative to that full path name anyhow.
3) The real source of your problem is your BUILD_COMMAND value:
BUILD_COMMAND "make -f ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.squirrel"
It should read:
BUILD_COMMAND make -f ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.squirrel
If you have the quotes there, then the shell is looking for an actual file named "make -f .../Makefile.squirrel" because CMake parses arguments by spaces, but the double quotes tell CMake "this is exactly one argument that includes spaces..." If there are spaces in the expanded value of ${CMAKE_CURRENT_SOURCE_DIR} then CMake will properly double quote (or escape, depending on the platform/shell) it when it generates the command in its generated makefiles.
You could try writing a script that calls make with the correct makefile. Just export the CMAKE_CURRENT_SOURCE_DIR to an environmental variable that the script reads.