cmake with git for windows, MinGW and make - cmake

Firstly, I have installed MinGW from https://sourceforge.net/projects/mingw/files/ and the mingw32-gcc-g++ and mingw32-gcc-objs with it. I have added C:\MinGW\bin to my path.
Secondly, I have installed Git for windows (not really important, the result is the same on cmd.exe).
Thirdly, I have installed the complete package "make" with http://gnuwin32.sourceforge.net/packages/make.htm
After that, I have installed cmake 3.5.1 with the .msi.
But when I run cmake ../src the result is :
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:5 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:5 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also "C:/Users/pauka/Dropbox/ETUDE/SRI/S8/STA_Stage/sources/tests/bin/CMakeFiles/CMakeOutput.log".
See also "C:/Users/pauka/Dropbox/ETUDE/SRI/S8/STA_Stage/sources/tests/bin/CMakeFiles/CMakeError.log".
So cmake can't find gcc or g++. But when I run gcc -version, the output is good... What should I configure for cmake ?
My CMakeLists.txt is :
# Ajustez en fonction de votre version de CMake
cmake_minimum_required (VERSION 2.8)
# Nom du projet
project (main)
find_package (OpenCV REQUIRED)
# Exécutable "main", compilé à partir du fichier main.cpp
add_executable (tracking_color tracking_color.cpp)
add_executable (feuille feuille.cpp)
add_executable (detect_circles detect_circles.cpp)
add_executable (segmentation segmentation.cpp)
add_executable (watershed_perso watershed_perso.cpp)
add_executable (main main.cpp utils.h)
add_executable (info_coins info_coins.cpp)
# main sera linké avec les bibliothèques d'OpenCV
target_link_libraries (tracking_color ${OpenCV_LIBS})
target_link_libraries (feuille ${OpenCV_LIBS})
target_link_libraries (detect_circles ${OpenCV_LIBS})
target_link_libraries (segmentation ${OpenCV_LIBS})
target_link_libraries (watershed_perso ${OpenCV_LIBS})
target_link_libraries (info_coins ${OpenCV_LIBS})
target_link_libraries (main ${OpenCV_LIBS})

Ok, shame on me,
I had to restart my computer and select "MinGW Makefiles" in the CMake GUI. Click Configure, and after that Generate.
Next, you must not use Git for windows because there is sh.exe and it's a cmake bug.
PS: to use OpenCV, you must compile it :
cd C:\opencv
mkdir my_build
cd my_build
cmake -G "MinGW Makefiles" ../sources
mingw32-make # took 2 hours on my computer
and next add, C:\opencv\my_build and C:\opencv\my_build\bin to the system path.

You can try setting manually the cxx path, see CMAKE_C_COMPILER from link which tells you more or less link this:
CXX=C:\path\to\g++ cmake ..
But, I would recommend you to see why cmake doesn't recognize your cxx compiler. I would double check your environment paths.

Maybe not the best answer but get things going. Install Bash On Ubuntu On Windows and install cmake and make using sudo apt-get install cmake and sudo apt-get install build-essential if you don't already have them installed. However, Bash On Ubuntu On Windows only comes with Windows 10 and for accessing a specific drive you should use /mnt/c instead of C:\
Follow this official tutorial to install Bash On Ubuntu On Windows.
mona#DESKTOP-0JQ770H:/mnt/c$ cmake -version
cmake version 2.8.12.2
mona#DESKTOP-0JQ770H:/mnt/c$ make -version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Additionally, of course you can install git in Bash On Ubuntu On Windows
sudo apt-get install git
mona#DESKTOP-0JQ770H:/mnt/c$ git --version
git version 1.9.1
though I don't suggest using a Linux-based git for pushing to github for a Windows specific SDK/code. I would still stick to Git Bash for dealing with git.
*I used to use CMAKE GUI for dealing with CMake in Windows 10 and then port my stuff to Visual Studio. That is also a neat solution depending on your codebase.

Related

How to build the psa-arch-tests with the cmake and armclang in the cygwin?

After Installing several softwares for building the compilation environment according to the Software Requirements Document which is in the "https://github.com/ARM-software/psa-arch-tests/blob/master/api-tests/docs/sw_requirements.md", when I compiled the source code psa-arch-tests of PSA API compliance test suite, the cygwin prompted the following error result:
luofeng66ok#DESKTOP ~/TFMB/psa-arch-tests/api-tests/build
$ cmake ../ -G"Unix Makefiles" -DTOOLCHAIN=ARMCLANG -DTARGET=tgt_dev_apis_tfm_an521 -DCPU_ARCH=armv8m_ml -DSUITE=CRYPTO -DPSA_INCLUDE_PATHS="/cygdrive/c/cygwin64/home/anpengfei/TFMB/trusted-firmware-m/interface/include/psa/crypto.h"
-- The CXX compiler identification is unknown
CMake Error in CMakeLists.txt:
No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/cygwin64/home/luofeng66ok/TFMB/psa-arch-tests/api-tests/BUILD/CMakeF
iles/CMakeOutput.log".
See also "C:/cygwin64/home/luofeng66ok/TFMB/psa-arch-tests/api-tests/BUILD/CMakeF
iles/CMakeError.log".
How to resolve this error?
CMakeError.log contains:
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: C:/cygwin64/bin/cc
Build flags:
Id flags:
The output was:
拒绝访问。
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: C:/cygwin64/bin/cc
Build flags:
Id flags: -c
The output was:
拒绝访问。
......
My installed software are:
Host Operating System: Windows 10 64bit
Scripting tools:
luofeng66ok#DESKTOP-STB70QG ~/TFMB/psa-arch-tests/api-tests/build
$ Python --version
Python 3.7.0
Cross Compiler toolchain :
luofeng66ok#DESKTOP-STB70QG ~/TFMB/psa-arch-tests/api-tests/build
$ armclang --version
Product: MDK Plus 5.29
Component: ARM Compiler 6.13.1
Tool: armclang [5d895d00]
Target: unspecified-arm-none-unspecified
Build tools :
luofeng66ok#DESKTOP-STB70QG ~/TFMB/psa-arch-tests/api-tests/build
$ cmake --version
cmake version 3.10.0-rc1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ cygcheck --version
cygcheck (cygwin) 3.1.4
and I have imported Arm Compiler in my environment variable,
At the same time, I also imported Arm Compiler by this way:
C:\cygwin64\home\luofeng66ok\.bashrc:
export PATH=/cygdrive/c/Keil/ARM/ARMCLANG/bin:$PATH
export PATH=/cygdrive/c/cmake/bin:$PATH
export PATH=/cygdrive/c/armgcc/bin:$PATH
My steps for building psa-arch-tests are:
git clone https://github.com/ARM-software/psa-arch-tests.git
git clone https://github.com/laurencelundblade/QCBOR.git (I do not why do this)
cd <TF-M base folder>
git clone https://git.trustedfirmware.org/trusted-firmware-m.git
git clone https://github.com/ARMmbed/mbed-crypto.git -b mbedcrypto-3.0.1
git clone https://github.com/ARM-software/CMSIS_5.git -b 5.5.0
git-lfs
My directory tfmb contains:
luofeng66ok#DESKTOP-STB70QG ~/tfmb
$ ls
CMSIS_5 mbed-crypto psa-arch-tests trusted-firmware-m
Start compiling psa-arch-tests
cd api-tests
mkdir BUILD
cd BUILD
cmake ../ -G"Unix Makefiles" -DTOOLCHAIN=ARMCLANG -DTARGET=tgt_dev_apis_tfm_an521 -DCPU_ARCH=armv8m_ml -DSUITE=CRYPTO -DPSA_INCLUDE_PATHS="/cygdrive/c/cygwin64/home/anpengfei/TFMB/trusted-firmware-m/interface/include/psa/crypto.h"
as the errors above shows in my cygwin, I do not why?
luofeng66ok#DESKTOP-STB70QG ~/TFMB/psa-arch-tests/api-tests/build
$ cmake ../ -G"Unix Makefiles" -DTOOLCHAIN=ARMCLANG -DTARGET=tgt_dev_apis_tfm_an521 -DCPU_ARCH=armv8m_ml -DSUITE=CRYPTO -DPSA_INCLUDE_PATHS="/cygdrive/c/cygwin64/home/anpengfei/TFMB/trusted-firmware-m/interface/include/psa/crypto.h"
-- The CXX compiler identification is unknown
CMake Error in CMakeLists.txt:
No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/cygwin64/home/luofeng66ok/TFMB/psa-arch-tests/api-tests/BUILD/CMakeF
iles/CMakeOutput.log".
See also "C:/cygwin64/home/luofeng66ok/TFMB/psa-arch-tests/api-tests/BUILD/CMakeF
iles/CMakeError.log".

Cannot configure CMake to look for Homebrew installed version of Bison

I'm running macOS 10.14 and I installed bison version 3.2 with brew, but it refuses to link:
$ brew link bison --force
Warning: Refusing to link macOS-provided software: bison
If you need to have bison first in your PATH run:
echo 'export PATH="/usr/local/opt/bison/bin:$PATH"' >> ~/.bash_profile
For compilers to find bison you may need to set:
export LDFLAGS="-L/usr/local/opt/bison/lib"
My CMakeLists.txt has the following lines:
find_package(BISON 3.2 REQUIRED)
...
message(STATUS "Found bison ${BISON_VERSION} at: ${BISON_EXECUTABLE}")
cmake fails with the following output:
Could NOT find BISON: Found unsuitable version "2.3", but required is at
least "3.2" (found /usr/bin/bison)
The system-installed bison is at version 2.3, and I know that the Homebrew-installed version is at version 3.2.
The FindBISON module apparently uses the find_program CMake directive, and I've tried adding /usr/local/opt/bison/bin to CMAKE_PROGRAM_PATH, but /usr/bin/bison is always selected first no matter what. How can I force CMake to favor the Homebrew installed version of the Bison executable?
Since some things in macos depend on the Apple-provided versions of flex and bison, homebrew installs them outside of the user's normal $PATH as a "keg". A manual solution is to make sure you (and your users) add the program's brew prefix to their path (can be found by running brew --prefix bison etc.).
An automatic solution is to put this logic in your CMake files. A couple open-source projects have worked around it like this. The earliest example of a fix for this that I could find is from this commit to STP (essential part copied below).
Be sure to clear your CMake cache when messing around with all this, as BISON_EXECUTABLE (etc.) is cached.
# On macOS, search Homebrew for keg-only versions of Bison and Flex. Xcode does
# not provide new enough versions for us to use.
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
execute_process(
COMMAND brew --prefix bison
RESULT_VARIABLE BREW_BISON
OUTPUT_VARIABLE BREW_BISON_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
set(BISON_EXECUTABLE "${BREW_BISON_PREFIX}/bin/bison")
endif()
execute_process(
COMMAND brew --prefix flex
RESULT_VARIABLE BREW_FLEX
OUTPUT_VARIABLE BREW_FLEX_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_FLEX EQUAL 0 AND EXISTS "${BREW_FLEX_PREFIX}")
message(STATUS "Found Flex keg installed by Homebrew at ${BREW_FLEX_PREFIX}")
set(FLEX_EXECUTABLE "${BREW_FLEX_PREFIX}/bin/flex")
endif()
endif()
find_package(bison REQUIRED)
find_package(flex REQUIRED)

Catkin cannot find gtest

Since yesterday none of my packages containing tests build. Catkin complains it cannot find gtest when using catkin_add_gtests(), since GTEST_FOUND is FALSE. You can see this in the error msg below, with the custom output I added to my CMakeLists. Up to yesterday, GTEST_FOUND was TRUE when catkin_add_gtests() was called.
This is the error I always get. In this case I'm trying to build a mockup package on a clean catkin workspace:
Errors << silly_pkg:cmake /home/paco/catkin_ws2/logs/silly_pkg/build.cmake.002.log
Not searching for unused variables given on the command line.
Re-run cmake no build system arguments
-- Using CATKIN_DEVEL_PREFIX: /home/paco/catkin_ws2/devel/.private/silly_pkg
-- Using CMAKE_PREFIX_PATH: /home/paco/catkin_ws2/devel;/opt/ros/kinetic
-- This workspace overlays: /home/paco/catkin_ws2/devel;/opt/ros/kinetic
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/paco/catkin_ws2/build/silly_pkg/test_results
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.11
-- GTEST_FOUND: FALSE
CMake Warning at /opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake:149 (message):
skipping gtest 'test_silly_pkg' in project 'silly_pkg' because gtest was
not found
Call Stack (most recent call first):
/opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake:79 (_catkin_add_executable_with_google_test)
/opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake:28 (_catkin_add_google_test)
CMakeLists.txt:28 (catkin_add_gtest)
CMake Error at /home/paco/catkin_ws2/src/silly_pkg/CMakeLists.txt:33 (target_link_libraries):
Cannot specify link libraries for target "test_silly_pkg" which is not
built by this project.
-- Configuring incomplete, errors occurred!
See also "/home/paco/catkin_ws2/build/silly_pkg/CMakeFiles/CMakeOutput.log".
See also "/home/paco/catkin_ws2/build/silly_pkg/CMakeFiles/CMakeError.log".
cd /home/paco/catkin_ws2/build/silly_pkg; catkin build --get-env silly_pkg | catkin env -si /usr/bin/cmake /home/paco/catkin_ws2/src/silly_pkg --no-warn-unused-cli -DCATKIN_DEVEL_PREFIX=/home/paco/catkin_ws2/devel/.private/silly_pkg -DCMAKE_INSTALL_PREFIX=/home/paco/catkin_ws2/install; cd -
I am using catkin 0.7.11, libgtest-dev 1.7.0 and cmake 3.5.1. I use ROS Kinetic with Ubuntu 16.04. The only thing I did yesterday was reinstalling ROS Kinetic, but the package versions are exactly the same. Did anybody have this problem? Do you have any ideas on what could be happening?
EDIT 3/09/18:
By comparing with a functional catkin+gtest workspace in a different computer, I found out that the main difference is in the results of /opt/ros/kinetic/share/catkin/cmake/test/gtest.cmake. In the functional workspace, line 292 evaluates to TRUE (gtest/gmock is not a target) while in my workspace it evaluates to FALSE. This is because in my workspace running find_package(GMock QUIET) (line 287) sets gmock and gtest as imported targets, which does not happen in the other computer. Why is this different?
Thanks TikO for your help!
Since you wrote that cmake does not find the libraries and that you have reinstalled Kinetic, I assume that you have a freshly installed machine or wiped out gtest libraries by accident.
If you install libgtest-dev, you only get the sources which you need to build and install like this:
sudo apt-get install libgtest-dev
mkdir /tmp/gtest_build && cd /tmp/gtest_build
cmake /usr/src/gtest
make
#copy or symlink libgtest.a and ligtest_main.a to /usr/lib folder
sudo cp *.a /usr/lib
After this routine, you should be able to build again without cmake complaining.
Optional
If you have limited rights on your machine and you are not allowed to install the libraries in that way, just copy them into some home folder like
mkdir ~/lib && cp *.a ~/lib
But be aware of the fact, that you have to call catkin in the following way:
LIBRARY_PATH=~/lib GTEST_ROOT=~/lib catkin_make
LIBRARY_PATH tells the linker where to find the libraries, while GTEST_ROOT gives cmake the location hints for it's checks.
Reference: https://github.com/tik0/gtest_ros_example
SOLUTION FOUND
gmock and gtest were being set to imported target because the suggested manual compilation of libgtest had created a FindGMock.cmake file inside /usr/share/cmake-3.5/Modules. This file was being called by the find(GMock QUIET)
in catkin_add_gtests(), therefore setting the imported target. Just deleting FindGMock.cmake solved the issue.

Use LLVM in a cmake build

I'm trying to build my own project that use LLVM. I downloaded the source code and the precompiled package on the official web site (last version).
http://releases.llvm.org/download.html
I downloaded :
LLVM source code
Clang for Windows (64-bit)
FYI, I don't build LLVM... only want to use it !
I followed the instruction here :
http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project
in the section : "Embedding LLVM in your project"
So, I added this code :
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message("LLVM_INCLUDE_DIRS=${LLVM_INCLUDE_DIRS}")
message("LLVM_DEFINITIONS=${LLVM_DEFINITIONS}")
But I got several cmake error messages, here is my output :
-- Using LLVMConfig.cmake in: C:\\Luciad_src\\libs\\LLVM\\cmake\\modules
LLVM_INCLUDE_DIRS=
LLVM_DEFINITIONS=
CMake Error at C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:31 (list):
list sub-command REMOVE_ITEM requires two or more arguments.
Call Stack (most recent call first):
C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:256 (is_llvm_target_library)
components/query/CMakeLists.txt:15 (llvm_map_components_to_libnames)
Is there a problem with my script, or the packages I use ? Any idea ?
Thanks for your help
You can have the LLVM as binary or source package.
The binary package does not include CMake support. If you compare both installations (binary on the left, source after building and installing it on the right) you can see the difference:
LLVM-5.0.0-win64.exe
<=> llvm-5.0.1.src.tar.xz (build and installed)
So you need to build and install the source package first to get CMake support. On my Windows machine I needed a cmd shell with administrator rights, a Visual Studio installation, go to the downloaded and extracted sources and do:
> mkdir mybuilddir
> cd mybuilddir
> cmake ..
> cmake --build . --config Release --target INSTALL
If I now use your CMake example I get:
-- Found LLVM 5.0.1
-- Using LLVMConfig.cmake in: C:/Program Files (x86)/LLVM/lib/cmake/llvm
LLVM_INCLUDE_DIRS=C:/Program Files (x86)/LLVM/include
LLVM_DEFINITIONS=-DLLVM_BUILD_GLOBAL_ISEL -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Configuring done

Build MPICH with CMake

I need to force my Cmake to build and link my MPI code with MPICH. My MPICH is installed using the Ubuntu Package manager, in a standard location /usr/lib/mpich/. However, CMake still looks for the OpenMPI libraries, which I do not use. How can I instruct CMake to look for MPICH instead?
Below, you can see the output of some basic diagnostics:
$ whereis openmpi
openmpi:
$ whereis mpich
mpich: /usr/lib/mpich /usr/include/mpich
$ mpicc -v
mpicc for MPICH version 3.2
Below, I also provide the Cmake script and the errors I get from cmake and the mpirun.mpich. My Cmake is 3.5.1 and I run on Ubuntu Xenial 16.04.
cmake_minimum_required(VERSION 3.0)
message (STATUS "Adding mpiService")
find_package(MPI REQUIRED)
set(CMAKE_C_COMPILER mpicc)
set(CMAKE_CXX_COMPILER mpicxx)
set(MPI_GUESS_LIBRARY_NAME MPICH2)
message(STATUS ${MPI_INCLUDE_PATH})
message(STATUS ${MPI_C_LIBRARIES})
#add_definitions(-DOMPI_SKIP_MPICXX)
add_executable(mpiService main.cpp)
set(CMAKE_VERBOSE_MAKEFILE ON)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
target_link_libraries(
mpiService
PRIVATE
${MPI_C_LIBRARIES}
)
From the Cmake STATUS I get the following output:
/usr/lib/openmpi/include/openmpi/opal/mca/event/libevent2021/libevent/usr/lib/openmpi/include/openmpi/opal/mca/event/libevent2021/libevent/include/usr/lib/openmpi/include/usr/lib/openmpi/include/openmpi
/usr/lib/openmpi/lib/libmpi.so
And when I run the binary I get the following:
ubuntu#node1:~$ mpirun.mpich -np 2 --host node1,node2 mpiService
mpiService: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
mpiService: error while loading shared libraries: libmpi.so.12: cannot open shared object file: No such file or directory
How can I instruct CMake to look for MPICH instead?
According to FindMPI documentation, you may set MPI_<lang>_COMPILER variable to the desired MPI compiler:
Set MPI_<lang>_COMPILER to the MPI wrapper (mpicc, etc.) of your
choice and reconfigure. FindMPI will attempt to determine all the
necessary variables using THAT compiler's compile and link flags.
set(MPI_CXX_COMPILER <path-to-mpich-compiler>)
find_package(MPI REQUIRED)
Alternatively, since CMake version 3.10, variable MPI_EXECUTABLE_SUFFIX can be set instead:
A suffix which is appended to all names that are being looked for. For instance you may set this to .mpich or .openmpi to prefer the one or the other on Debian and its derivatives.
set(MPI_EXECUTABLE_SUFFIX ".mpich")
find_package(MPI REQUIRED)
Herewith my current solution.
find_package(MPI REQUIRED)
# ----------------
# This is the only thing that made it work
# ----------------
set(MPI_C_LIBRARIES "/usr/lib/mpich/lib/libmpich.so")
set(MPI_INCLUDE_PATH "/usr/include/mpich")
# ----------------
add_executable(mpiService main.cpp)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
target_link_libraries(
mpiService
${MPI_C_LIBRARIES}
)
I personally do not like this solution, as I have to explicitly specify the path. Any other proposed solution was still building with OpenMPI. If I find a better alternative, I will re-post.