For reasons that I cannot completely understand, Cmake awlays chooses the GNU compiler toolset when compiling software.
My enviroment looks like this:
which cc
/opt/cray/xt-asyncpe/4.9/bin/cc
which CC
/opt/cray/xt-asyncpe/4.9/bin/CC
echo $CC
/opt/cray/xt-asyncpe/4.9/bin/cc
echo $CXX
/opt/cray/xt-asyncpe/4.9/bin/CC
but when I use cmake I get this
Using existing /opt/cmake/2.8.4/bin/cmake
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
And it builds all the software with g++ commands. Why is this going on? How does one set the compiler?
You can also set the env vars CC and CXX much like autotools.
CC=cc CXX=CC cmake ...
Make sure you start with an empty build tree.
I'm not sure why CMake favours GCC.
However, to set the compilers, use:
cmake <path to CMakeLists.txt> -DCMAKE_C_COMPILER=/opt/cray/xt-asyncpe/4.9/bin/cc -DCMAKE_CXX_COMPILER=/opt/cray/xt-asyncpe/4.9/bin/CC
These values will be cached, so subsequent runs of CMake (if required) can simply be invoked by:
cmake .
Related
cmake build failed with
CMAKE_AR-NOTFOUND cr libperfutils.a
When i checked build folder ar is not set.
x86_64-linux\gtest-native\1.7.0-r5\build\CMakeCache.txt
CMAKE_AR:FILEPATH=CMAKE_AR-NOTFOUND
//CXX compiler.
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++
How to set ar in cmake ?
Wheni see the cmake config below output . cmake automatically finding the g++
& why it not detecting ar
-- The CXX compiler identification is GNU 4.8.4
-- Check for working CXX compiler: g++
-- Check for working CXX compiler: g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
When i check ar in machine manually its available.
/usr/bin/ar
CMake should have been able to detect /usr/bin/ar by itself, but you can manually override this, with the -D CMAKE_AR=/usr/bin/ar option.
Here's the list of useful variables:
https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/Useful-Variables
cmake ar should set in cmake lib build ,
temperorly solved the issue by manally setting in my local Cmake file
set( CMAKE_AR "${AR}" CACHE FILEPATH "Archiver" )
I am trying to run the code of PU-GAN(https://github.com/liruihui/PU-GAN),you can get the program(evaluation code) in (https://github.com/liruihui/PU-GAN).but I am failed to camake CGAL libaray. i get following error:
(tf) li#li-System-Product-Name:/media/li/1d105677-e036-4fa4-8e37-124cb400f24d/user/shenbin/PU-GAN-master/evaluation_code$ cmake .
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /home/li/anaconda3/envs/tf/bin/x86_64-conda-linux-gnu-cc
-- Check for working C compiler: /home/li/anaconda3/envs/tf/bin/x86_64-conda-linux-gnu-cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.0")
-- Found OpenMP: TRUE (found version "4.5")
-- Using header-only CGAL
-- Targetting Unix Makefiles
-- Using /usr/bin/c++ compiler.
-- Found GMP: /home/li/anaconda3/envs/tf/lib/libgmp.so
-- Found MPFR: /home/li/anaconda3/envs/tf/lib/libmpfr.so
-- Found Boost: /usr/include (found suitable version "1.58.0", minimum required is "1.48")
-- Boost include dirs: /usr/include
-- Boost libraries:
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Using gcc version 4 or later. Adding -frounding-math
-- Build type:
-- USING CXXFLAGS = ' -fopenmp '
-- USING EXEFLAGS = '-Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,-rpath,/home/li/anaconda3/envs/tf/lib -Wl,-rpath-link,/home/li/anaconda3/envs/tf/lib -L/home/li/anaconda3/envs/tf/lib '
CMake Warning at /usr/local/lib/cmake/CGAL/CGAL_enable_end_of_configuration_hook.cmake:99 (message):
=======================================================================
CGAL performance notice:
The variable CMAKE_BUILD_TYPE is set to "". For performance reasons, you
should set CMAKE_BUILD_TYPE to "Release".
Set CGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE to TRUE if you want to disable
this warning.
=======================================================================
Call Stack (most recent call first):
CMakeLists.txt:9999 (CGAL_run_at_the_end_of_configuration)
-- Configuring done
-- Generating done
-- Build files have been written to: /media/li/1d105677-e036-4fa4-8e37-124cb400f24d/user/shenbin/PU-GAN-master/evaluation_code
(tf) li#li-System-Product-Name:/media/li/1d105677-e036-4fa4-8e37-124cb400f24d/user/shenbin/PU-GAN-master/evaluation_code$ make
Scanning dependencies of target evaluation
[ 50%] Building CXX object CMakeFiles/evaluation.dir/evaluation.cpp.o
/media/li/1d105677-e036-4fa4-8e37-124cb400f24d/user/shenbin/PU-GAN-master/evaluation_code/evaluation.cpp:19:50: fatal error: CGAL/Polygon_mesh_processing/measure.h: No such file or directory
compilation terminated.
CMakeFiles/evaluation.dir/build.make:62: recipe for target 'CMakeFiles/evaluation.dir/evaluation.cpp.o' failed
make[2]: *** [CMakeFiles/evaluation.dir/evaluation.cpp.o] Error 1
CMakeFiles/Makefile2:77: recipe for target 'CMakeFiles/evaluation.dir/all' failed
make[1]: *** [CMakeFiles/evaluation.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I cannot find a way to compile any of my CGAL Programyou
It's probably a mismatch between compilers or mismatch between the CGAL library and compilers - your CMake has found the cc compiler inside your anaconda3 directory:
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /home/li/anaconda3/envs/tf/bin/x86_64-conda-linux-gnu-cc
-- Check for working C compiler: /home/li/anaconda3/envs/tf/bin/x86_64-conda-linux-gnu-cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Different versions of C and CXX - that's not good. Please do not use the old compiler from the Anaconda distribution, and make sure both C and CXX compilers belong to the same (better the most recent) package.
There is an option defined in a third party CMake file.
SET(PHYSX_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -fno-strict-aliasing ${GCC_WARNINGS}" CACHE INTERNAL "PhysX CXX")
I am trying to pass custom flags to CMAKE_CXX_FLAGS:
cmake physx/sources/compiler/cmake -B build -DCMAKE_CXX_FLAGS="-Wno-restrict -Wno-class-memaccess"
Because I have space between the two GCC warning flags, the final result ends up breaking the string:
CXX_FLAGS = "-Wno-restrict ... # Quote is not closed
and I get an error about unterminated string
WHen I use no quotes around the flag CMake variable value:
cmake physx/sources/compiler/cmake -B build -DCMAKE_CXX_FLAGS=-Wno-restrict -Wno-class-memaccess
The final result ignores the value after space, which makes sense since space will be treated as a separate variable.
Is there something that I can do to set values with space into CMake variable?
Thanks #KamilCuk,
My problem was with the Python script that was triggering the commands. I had the following line in Python:
subprocess.run(parsedCmdLine.split(' '), shell=platform.system() == 'Windows', cwd=x['sourceDir'])
Luckily, Python has a lexical utility module that resembles shell:
import shlex
subprocess.run(shlex.split(parsedCmdLine.split), shell=platform.system() == 'Windows', cwd=x['sourceDir'])
You need to quote the whole -D parameter, like:
$ cmake ../ '-DCMAKE_CXX_FLAGS=-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer'
-- The C compiler identification is GNU 11.1.0
-- The CXX compiler identification is GNU 11.1.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/baiyanh/arena/cmake/tut/build
Then the compile looks like:
$ cmake --build . -v
...
[ 50%] Building CXX object CMakeFiles/tut.dir/tut.cpp.o
/usr/bin/c++ -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -o CMakeFiles/tut.dir/tut.cpp.o -c /home/baiyanh/arena/cmake/tut/tut.cpp
...
I am trying to rebuild this on my machine:
https://github.com/sfdodge/xnet
For this I needed to install xtensor and xtensor-blas. I followed the steps and successfully installed xtensor. However, I have trouble installing xtensor-blas. I create a fresh directory and run this command
cmake /home/fatima/Downloads/xtensor-blas-master
It generates the following log:
The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- xtensor-blas v0.14.0
CMake Error at CMakeLists.txt:45 (find_package):
By not providing "Findxtensor.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "xtensor", but
CMake did not find one.
Could not find a package configuration file provided by "xtensor" with any
of the following names:
xtensorConfig.cmake
xtensor-config.cmake
Add the installation prefix of "xtensor" to CMAKE_PREFIX_PATH or set
"xtensor_DIR" to a directory containing one of the above files. If
"xtensor" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/home/fatima/Downloads/Untitled Folder 3/CMakeFiles/CMakeOutput.log".
What am I doing wrong?
I have this following (minimal) CMakeLists.txt supposed to find GLib via pkg-config and add the libs to the foo target:
cmake_minimum_required(VERSION 2.10 FATAL_ERROR)
project(foo)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLib REQUIRED glib-2.0)
add_executable(foo foo.cpp)
message(WARNING "libs:" ${GLIB_LIBRARIES})
message(WARNING "includes:" ${GLIB_INCLUDE_DIRS})
target_link_libraries(foo PUBLIC ${GLIB_LIBRARIES})
target_include_directories(foo PUBLIC ${GLIB_INCLUDE_DIRS})
No matter what I try, I get (note the Found glib-2.0 part):
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'glib-2.0'
-- Found glib-2.0, version 2.56.1
CMake Warning at CMakeLists.txt:6 (message):
libs:
CMake Warning at CMakeLists.txt:7 (message):
includes:
CMake Error at CMakeLists.txt:9 (target_include_directories):
target_include_directories called with invalid arguments
-- Configuring incomplete, errors occurred!
See also "/tmp/aaa/CMakeFiles/CMakeOutput.log".
and I cannot see, reading the CMake reference what arguments are invalid (note: this question is different from cmake target_include_directories called with invalid arguments). I also looked at CMake's FindPkgConfig documentation which gives glib as an example and I am not able to reproduce it (${GLIB_VERSION}). I tried GLIB_ and GLIB2_ prefixes and all I get is empty strings.
The messages show the variables are empty, though pkg-config reports values correctly:
$ pkg-config glib-2.0 --cflags --libs
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0
The CMake version I have is 2.10.
Can someone shed light on the issue?
I think your problem is the casing of GLIB_INCLUDE_DIRS and GLIB_LIBRARIES. They should be GLib_INCLUDE_DIRS and GLib_LIBRARIES since you specified "GLib" as the first argument of pkg_check_modules. I'm guessing that the target_include_directories() doesn't like not getting any arguments after the
PUBLIC (although it works for me in cmake 3.5).