Build project from ExternalProject_Add using dockcross - cmake

I am trying to build tinyxml2 using ExternalProject_Add. It works fine on my main system (Arch Linux), but I have some issues when running it inside dockcross (more specifically, dockcross/linux-armv6).
The following minimal CMakeLists.txt works (configure and build) from dockcross:
cmake_minimum_required(VERSION 3.1)
project(external-tinyxml2)
include(ExternalProject)
ExternalProject_add(
tinyxml2
URL https://github.com/leethomason/tinyxml2/archive/7.0.1.tar.gz
PREFIX tinyxml2
)
But the following doesn't (note the added line: CONFIGURE_COMMAND ${CMAKE_COMMAND} -S<SOURCE_DIR>):
cmake_minimum_required(VERSION 3.1)
project(external-tinyxml2)
include(ExternalProject)
ExternalProject_add(
tinyxml2
URL https://github.com/leethomason/tinyxml2/archive/7.0.1.tar.gz
PREFIX tinyxml2
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S<SOURCE_DIR>
)
It actually results in the following error output:
[ 25%] No patch step for 'tinyxml2'
[ 37%] No update step for 'tinyxml2'
[ 50%] Performing configure step for 'tinyxml2'
CMake Deprecation Warning at CMakeLists.txt:11 (cmake_policy):
The OLD behavior for policy CMP0063 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Error at /usr/share/cmake-3.13/Modules/CMakeDetermineCompilerId.cmake:161 (file):
file problem creating directory: /CMakeFiles/3.13.2/CompilerIdC
Call Stack (most recent call first):
/usr/share/cmake-3.13/Modules/CMakeDetermineCompilerId.cmake:31 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
/usr/share/cmake-3.13/Modules/CMakeDetermineCCompiler.cmake:112 (CMAKE_DETERMINE_COMPILER_ID)
CMakeLists.txt:14 (project)
[... other similar errors ...]
CMake Error at /usr/share/cmake-3.13/Modules/CMakeTestCCompiler.cmake:37 (try_compile):
Failed to set working directory to /CMakeFiles/CMakeTmp/testCCompiler.c :
No such file or directory
Call Stack (most recent call first):
CMakeLists.txt:14 (project)
-- Configuring incomplete, errors occurred!
CMake Error: Cannot open file for write: /CMakeCache.txt.tmp
CMake Error: : System Error: Permission denied
CMake Error: Unable to open cache file for save. /CMakeCache.txt
CMake Error: : System Error: Permission denied
CMakeFiles/tinyxml2.dir/build.make:108: recipe for target 'tinyxml2/src/tinyxml2-stamp/tinyxml2-configure' failed
make[2]: *** [tinyxml2/src/tinyxml2-stamp/tinyxml2-configure] Error 1
make[2]: Leaving directory '/work/build'
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/tinyxml2.dir/all' failed
make[1]: *** [CMakeFiles/tinyxml2.dir/all] Error 2
make[1]: Leaving directory '/work/build'
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
make: Leaving directory '/work/build
Building tinyxml2 directly from dockcross (i.e. without using ExternalProject_Add) works well.
What could be going wrong there?

That is actually a bug in CMake, as reported (and fixed) here.
The workaround, for CMake versions that have the bug, is to run it like so (note that -S<SOURCE_DIR> becomes <SOURCE_DIR>):
ExternalProject_add(
tinyxml2
URL https://github.com/leethomason/tinyxml2/archive/7.0.1.tar.gz
PREFIX tinyxml2
CONFIGURE_COMMAND ${CMAKE_COMMAND} <SOURCE_DIR>
)

Related

How to add Ziplib library in Clion on Ubuntu

I'm trying to add ZipLip into my project using Clion on ubuntu, but I have this output:
====================[ Build | TryZip | Debug ]==================================
/home/david/Snap/clion-2019.2.4/bin/cmake/linux/bin/cmake --build
/home/david/CLionProjects/TryZip/cmake-build-debug --target TryZip -- -j 2
[ 13%] Built target bzip2
[ 31%] Built target zlib
[ 83%] Built target lzma
[ 95%] Built target ZipLib
Scanning dependencies of target TryZip
[ 97%] Linking CXX executable ../bin/TryZip
/usr/bin/ld: cannot find -lExternalLibrary/ZipLib
collect2: error: ld returned 1 exit status
CMakeFiles/TryZip.dir/build.make:102: recipe for target '../bin/TryZip' failed
make[3]: *** [../bin/TryZip] Error 1
CMakeFiles/Makefile2:109: recipe for target 'CMakeFiles/TryZip.dir/all' failed
make[2]: *** [CMakeFiles/TryZip.dir/all] Error 2
CMakeFiles/Makefile2:116: recipe for target 'CMakeFiles/TryZip.dir/rule' failed
make[1]: *** [CMakeFiles/TryZip.dir/rule] Error 2
Makefile:131: recipe for target 'TryZip' failed
make: *** [TryZip] Error 2
This is my Cmakefile.txt
cmake_minimum_required(VERSION 3.15)
project(TryZip)
if(BOOST_FILESYSTEM)
include_directories(${BOOST_INCLUDE_DIR})
link_directories(${BOOST_LIB_DIR})
add_definitions(-DUSE_BOOST_FILESYSTEM)
else()
if(MSVC)
add_definitions(-DFILESYSTEM_EXPERIMENTAL)
endif()
endif()
if(BOOST_FILESYSTEM)
if(UNIX)
find_package(Boost COMPONENTS system filesystem REQUIRED)
target_link_libraries(${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY})
endif()
endif()
add_subdirectory(ExternalLibrary/ZipLib)
link_libraries(ExternalLibrary/ZipLib)
include_directories(ExternalLibrary/ZipLib)
set(CMAKE_CXX_STANDARD 17)
add_executable(TryZip main.cpp ExternalLibrary/ZipLib/ZipFile.cpp)
target_link_libraries(TryZip ZipLib)
Can someone help me to solve this please?
My ZipLib folder is in the same folder as my cmakefile.txt file.
The call to link_libraries() appears to accept the wrong arguments in this case. The link_libraries() command takes arguments of existing CMake targets, or library names. It is also redundant with your target_link_libraries() call, as this already links ZipLib to TryZip.
Try removing the call to link_libraries(), as this CMake function is deprecated and its use is highly discouraged. The include_directories() call is similarly deprecated, in favor of the target-specific command, so consider using target_include_directories() instead.
Assuming your added sub-directory ExternalLibrary/ZipLib contains an additional CMakeLists.txt file for configuring the ZipLib target, you should not need to add the ZipFile.cpp file again. If this file is already compiled in the sub-directory into the target ZipLib, you do not need to compile it again into TryZip.
add_subdirectory(ExternalLibrary/ZipLib)
set(CMAKE_CXX_STANDARD 17)
add_executable(TryZip main.cpp)
target_include_directories(TryZip PRIVATE ExternalLibrary/ZipLib)
target_link_libraries(TryZip PRIVATE ZipLib)
EDIT: Based on your feedback, it appears ZipLib also depends on pthread but somehow it is not getting linked correctly. You might try to add the following to your ExternalLibrary/ZipLib/CMakeLists.txt file (if it doesn't already exist), to utilize CMake's FindThreads module:
find_package(Threads REQUIRED)
...
target_link_libraries(ZipLib PUBLIC Threads::Threads)

You have called ADD_LIBRARY for library pugixml without any source files

I am working on quickrank: https://github.com/hpclab/quickrank. when I compile it I get error
cmake .. -DCMAKE_CXX_COMPLIER=/usr/bin/g++ -DCMAKE_BUILD_TYPE=Release
You have called ADD_LIBRARY for library pugixml without any source files. This typically indicates a problem with your CMakeLists.txt file
-- Configuring done
CMake Error: Cannot determine link language for target "pugixml".
CMake Error: CMake can not determine linker language for target: pugixml
CMake Error: CMake can not determine linker language for target: pugixml
-- Generating done
-- Build files have been written to: /home/students/s4438236/quickrank/build_
s4438236#moss:~/quickrank/build_$ make
make[2]: *** No rule to make target `CMakeFiles/pugixml.dir/build'. Stop.
make[1]: *** [CMakeFiles/pugixml.dir/all] Error 2
make: *** [all] Error 2
I do find source file under the lib\pugixml folder, how can I fix this error?
When you call the add_library CMake command, you must provide source files for this target. If we examine the top-level CMakeLists.txt file, we see where the error is occurring:
# external libraries
file(GLOB_RECURSE pugixml_sources ${CMAKE_SOURCE_DIR}/lib/pugixml/src/*.cpp)
add_library(pugixml STATIC ${pugixml_sources})
The CMake error suggests that the pugixml_sources variable is empty, which hints that the /lib/pubixml may have also been empty. If you initially didn't run the git clone command with --recursive, you would not have gotten the pugixml submodule.
Seeing as you said the pugixml sources are now there, I would suggest deleting your CMake cache and the CMake build folder. Running CMake again from scratch will likely allow it to see the pugixml source files.

cmake error with catkin_make, ROS installation

I have created a workspace as catkin_ws. Then, catkin_make was run successful.
After I type catkin_create_pkg ros_basics_tutorials std_msgs rospy roscpp and then the all folders and files created in ros_basics_tutorials folder.
However After this command, I type cd catkin_ws
and then catkin_make
Below error is shown Cmake Error, Could NOT find cpp (missing: cpp_DIR), cmake_check_build_system' failed
Base path: /home/selcuk/catkin_ws
Source space: /home/selcuk/catkin_ws/src
Build space: /home/selcuk/catkin_ws/build
Devel space: /home/selcuk/catkin_ws/devel
Install space: /home/selcuk/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/selcuk/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/selcuk/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/selcuk/catkin_ws/devel;/opt/ros/melodic
-- This workspace overlays: /home/selcuk/catkin_ws/devel;/opt/ros/melodic
-- Using PYTHON_EXECUTABLE: /home/selcuk/python/anaconda2/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/selcuk/catkin_ws/build/test_results
CMake Error: Target gtest has dependency information when it shouldn't.
Your cache is probably stale. Please remove the entry
gtest_LIB_DEPENDS
from the cache.
CMake Error: Target gtest_main has dependency information when it shouldn't.
Your cache is probably stale. Please remove the entry
gtest_main_LIB_DEPENDS
from the cache.
CMake Error: Target gmock has dependency information when it shouldn't.
Your cache is probably stale. Please remove the entry
gmock_LIB_DEPENDS
from the cache.
CMake Error: Target gmock_main has dependency information when it shouldn't.
Your cache is probably stale. Please remove the entry
gmock_main_LIB_DEPENDS
from the cache.
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.14
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 2 packages in topological order:
-- ~~ - ros_basics_tutorials
-- ~~ - naoqi_driver
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'ros_basics_tutorials'
-- ==> add_subdirectory(ros_basics_tutorials)
-- Could NOT find cpp (missing: cpp_DIR)
-- Could not find the required component 'cpp'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
Could not find a package configuration file provided by "cpp" with any of
the following names:
cppConfig.cmake
cpp-config.cmake
Add the installation prefix of "cpp" to CMAKE_PREFIX_PATH or set "cpp_DIR"
to a directory containing one of the above files. If "cpp" provides a
separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
ros_basics_tutorials/CMakeLists.txt:10 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/selcuk/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/selcuk/catkin_ws/build/CMakeFiles/CMakeError.log".
Makefile:320: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed
I couldn't solve? How can solve it?
The error was due to anathor project folder which i canceled under the catkin_ws. I deleted it and complied again. The error solved.

Using CMake with Eclipse CDT and Cygwin on Windows

For a new project we want to use CMake. We are using Eclipse CDT as IDE and Cygwin gcc.
We generated the CMakeLists.txt and followed [this tutorial (option 2)][1].
When I try to run the described Make target to generate the Makefiles with CMake, which executes
cmake -E chdir C:/projects/eclipse_ws/MyApp/Build/ cmake -G "Unix Makefiles" ../ Run CMake
I get the error
CMake Error: The source directory "C:/projects/eclipse_ws/MyApp/Build/CMake" does not exist.
If I run the command directly from a Cygwin console it works just fine, however then I have to run make also from the Cygwin console, because the Makefiles are generated with Unix paths.
EDIT:
So I fixed this issue (see my answer below).
But I'm still having problems.
When I try to run CMake as Make target in Eclipse as suggested in the tutorial I get the following errors:
cmake -E chdir Build/ cmake -G 'Unix Makefiles' ../
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
System is unknown to cmake, create:
Platform/MINGW32_NT-6.1 to use this system, please send your config file to cmake#www.cmake.org so it can be added to cmake
Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. Please send that file to cmake#www.cmake.org.
-- Check for working C compiler: /usr/bin/gcc.exe
System is unknown to cmake, create:
Platform/MINGW32_NT-6.1 to use this system, please send your config file to cmake#www.cmake.org so it can be added to cmake
-- Check for working C compiler: /usr/bin/gcc.exe -- broken
CMake Error at /usr/share/cmake-2.8.9/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "/usr/bin/gcc.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: /cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles CMakeTmp
Run Build Command:/usr/bin/make.exe "cmTryCompileExec726566634/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec726566634.dir/build.make
CMakeFiles/cmTryCompileExec726566634.dir/build
make[1]: Entering directory
'/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp'
/usr/bin/cmake.exe -E cmake_progress_report
/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp/CMakeFiles
1
Building C object
CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj
/usr/bin/gcc.exe -o
CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj -c
/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp/testCCompiler.c
CMakeFiles/cmTryCompileExec726566634.dir/build.make:60: recipe for target
'CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj' failed
make[1]: Leaving directory
'/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp'
make[1]: *** [CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj]
Error 1
Makefile:117: recipe for target 'cmTryCompileExec726566634/fast' failed
make: *** [cmTryCompileExec726566634/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
Seems like for some reason CMake assumes I have an MinGW environment and not Cygwin.
EDIT2
MinGW system was assumed, because a Git installation was in PATH before Cygwin and Git's uname command was used (which returns MinGW).
If you check "Make Target - Same as the target name" in Eclipse's Make dialog, Eclipse will add a
Run CMake
to the command (see question), which is misinterpreted by CMake.
I just unchecked "Same as the target name".

Unknown CMake command "CHECK_INCLUDE_FILE_CXX"

I tried running cmake to generate the build tools for linux on vmime with the latest source from git hub, it generated the following errors. Thoughts??
vmime$ /usr/local/bin/cmake -G "Unix Makefiles"
CMake Error at CMakeLists.txt:20 (INCLUDE):
include could not find load file:
CheckIncludeFileCxx
-- Build type: Debug
CMake Error at CMakeLists.txt:452 (CHECK_INCLUDE_FILE_CXX):
Unknown CMake command "CHECK_INCLUDE_FILE_CXX".
-- Configuring incomplete, errors occurred!
In your CMakeLists.txt at line 20, you have
include(CheckIncludeFileCxx)
This should be
include(CheckIncludeFileCXX)
^^--- Uppercase
Once CheckIncludeFileCXX is properly included, the error on line 452 should also disappear, since the file defines the function CHECK_INCLUDE_FILE_CXX.
It has probably only been tested on Windows; since Windows filenames are case-insensitive this would have worked.