CXX CMake compiler prefix with executable not working - c++

I am following Parasoft code coverage to run it on my source code : https://docs.parasoft.com/display/CPPTEST1040/Instrumenting+and+Building+Instrumented+Source+Code
I have defined CXX as an environment variable in my new conan profile.
[env]
CXX="cpptestcc -compiler gcc_5-64 -line-coverage -workspace /home/test/proj -- c++"
As I wanted to run the Parasoft code coverage on my Conan based project.
conan install . -pr=myprofile
conan build .
The problem is that, I am not able to prepend the CXX compiler with parasoft code coverage. Running into CXX compiler broken as it is not taking the complete CXX as defined in the conan profile.
I have seen lot of links in stackoverflow related to this: How to prefix CMake Compiler?
Nothing works in my case. Please help me in defining the CXX with an executable prepended to CXX.
Thanks a lot.

Related

How to find and link CUDA libraries using CMake 3.15?

I'm using CMake 3.15-rc3 on my Unix-like system.
I need to link a program I'm building with several of the CUDA libraries, including cublas, cufft, cusolver, curand, nppicc, nppial, nppist, nppidei, nppig, nppitc, npps.
Based on what I found online, I need to do something like this:
add_executable(test benchmark.cpp)
find_package(CUDALibs)
target_link_libraries(test CUDA::cudart CUDA::cublas CUDA::cufft CUDA::cusolver CUDA::curand CUDA::nppicc CUDA::nppial CUDA::nppist CUDA::nppidei CUDA::nppig CUDA::nppitc CUDA::npps)
When I run make I get the following error:
CMake Warning at CMakeLists.txt:27 (find_package):
By not providing "FindCUDALibs.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "CUDALibs",
but CMake did not find one.
Could not find a package configuration file provided by "CUDALibs" with any
of the following names:
CUDALibsConfig.cmake
cudalibs-config.cmake
Add the installation prefix of "CUDALibs" to CMAKE_PREFIX_PATH or set
"CUDALibs_DIR" to a directory containing one of the above files. If
"CUDALibs" provides a separate development package or SDK, be sure it has
been installed.
So looks like I need a CUDALibsConfig.cmake file. Where do I get this file and how to I tell cmake to use it?
If I use the following it works:
find_package(CUDA REQUIRED)
target_link_libraries(run_benchmarks tf libmxnet.so ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cublas_LIBRARY} ${CUDA_npp_LIBRARY})
But according to this find_package(cuda) is deprecated, so I want to learn the proper usage.
Edit
I tried what was suggested in one of the responses.
I added CUDA to the project LANGUAGES:
project(
test_project
DESCRIPTION "Test project"
LANGUAGES CXX CUDA
)
And then I used find_package( FindCUDAToolkit REQUIRED)
However, when I run cmake I get the following errors:
 nchafni   dev  …  sample_code  benchmarks  build  1  cmake ..
-- The CXX compiler identification is GNU 7.5.0
-- The CUDA compiler identification is NVIDIA 10.1.243
-- 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
-- Check for working CUDA compiler: /usr/local/cuda-10.1/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda-10.1/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
CMake Error at CMakeLists.txt:17 (find_package):
By not providing "FindFindCUDAToolkit.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"FindCUDAToolkit", but CMake did not find one.
Could not find a package configuration file provided by "FindCUDAToolkit"
with any of the following names:
FindCUDAToolkitConfig.cmake
findcudatoolkit-config.cmake
Add the installation prefix of "FindCUDAToolkit" to CMAKE_PREFIX_PATH or
set "FindCUDAToolkit_DIR" to a directory containing one of the above files.
If "FindCUDAToolkit" provides a separate development package or SDK, be
sure it has been installed.
-- Configuring incomplete, errors occurred!
What am I missing?
find_package(CUDA) is deprecated for the case of programs written in CUDA / compiled with a CUDA compiler (e.g. NVCC). The documentation page says (emphasis mine):
It is no longer necessary to use this module or call find_package(CUDA) for
compiling CUDA code. Instead, list CUDA among the languages named in
the top-level call to the project() command, or call the
enable_language() command with CUDA. Then one can add CUDA (.cu)
sources to programs directly in calls to add_library() and
add_executable().
But find_package(CUDA) was not really deprecated - as of CMake version 3.15 - for C++ code which simply uses CUDA-enabled/CUDA-bundled/CUDA-utilizing libraries.
In CMake 3.17, a new macro/command was introduced: FindCUDAToolkit() (and this, find_package(CUDAToolkit). You can't use that with your version of CMake; find_package(CUDA) will do just fine, even if it's a bit clunky and outdated.
Edit: It is actually very easy to upgrade to a newer CMake version: KitWare offer binary releases which have very little dependencies. On a Linux system they would be:
linux-vdso.so.1
libdl.so.2
librt.so.1
libpthread.so.0
libm.so.6
libc.so.6
/lib64/ld-linux-x86-64.so.2
... and you would be hard-pressed to find a system without these. Also, even when installed under an arbitrary path, CMake will be able to differentiate between its version of shared files and whatever the system version of CMake uses. So - no reason to stick with the old version.
The documentation you linked says that you need to add CUDA to the list of languages in your project() command. And to find CUDA libraries it says to use FindCUDAToolkit module, not that CUDALibs.

C++11 activation with <target_compile_feature> or <set (CMAKE_CXX_STANDARD)>

I'm using a Python library, named PyPHS, specialized in physical modeling.
To save computation during the simulation, it implements a C++ code generation feature. It uses CMake to generate an executable of a particular simulation.
It is implemented in C++ 11.
Issue
In the CMakeLists.txt file, the C++ 11 feature is activated by the following line:
target_compile_features(<project_name> PUBLIC cxx_std_11)
On my computer (CMake 3.5.1 & Ubuntu 16.04.4 Xenial Xerus), CMake throws an error: this feature is unknown:
-- The CXX compiler identification is GNU 5.4.0
-- 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
CMake Error at CMakeLists.txt:31 (target_compile_features):
target_compile_features specified unknown feature "cxx_std_11" for target
"dampedosc".
```
-- Configuring incomplete, errors occurred!
See also "/home/victorw/git/vocal-phs/python/output/dampedosc/CMakeFiles/CMakeOutput.log".
This error has not been encountered on other installs (Debian 8, Mac OSX or windows 7)
Fix
I’ve changed the CMakeLists.txt template. Here is the link to the commit, on my own fork of PyPHS.
I’ve replaced the target_compile_features(<project_name> PUBLIC cxx_std_11) by set (CMAKE_CXX_STANDARD 11)
Question
What is the difference between the two commands?
What are your insights on this matter? Did I forget to mention some information?
Thank you for your answers!
The cxx_std_11 compiler meta-feature is not available in your version of CMake. it was introduced in 3.8, so this would explain the error, CMake 3.8 release notes.
The difference between the two is that target_compile_features() can request specific features for a specific target. CMake will automatically apply the appropriate standard to the specified target. If you on the other hand set CMAKE_CXX_STANDARD, then the requested standard, if supported by CMake, is applied project wide (for all targets).
As mentioned, you can as of CMake 3.8 request an entire standard using target_compile_features(), in which case the only difference from setting CMAKE_CXX_STANDARD is that the standard is only applied to the specified target (read below).
Note that if you invoke target_compile_features with PRIVATE scope, then the requested features/standard will apply only to the specified target, if instead PUBLIC is set, then the requested features/standard will also be applied to any target that depend on that target.

Setting Up Google Mock 1.6

I'm trying to follow along with Modern C++ Programming with Test-Driven Development and to do so the book instructs readers to install
Google Mock 1.6. Trying to do I downloaded the source from here. Then according to the book I do:
mkdir build
cd build
cmake ..
make
myComputer:build me$ cmake ..
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- The C compiler identification is AppleClang 8.0.0.8000042
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:56 (add_subdirectory):
add_subdirectory given source "../gtest" which is not an existing
directory.
CMake Error at CMakeLists.txt:61 (config_compiler_and_linker):
Unknown CMake command "config_compiler_and_linker".
-- Configuring incomplete, errors occurred!
See also "/Users/me/Downloads/googlemock-release-1.6.0 3/build/CMakeFiles/CMakeOutput.log".
The ../gtest directory is indeed missing. As these are the directories:
CHANGES COPYING build include scripts
CMakeLists.txt Makefile.am build-aux make src
CONTRIBUTORS README configure.ac msvc test
Adding to the confusion are these instructions:
You will also need to build Google Test, which is nested within Google Mock.
cd $GMOCK_HOME/gtest
mkdir mybuild
cd mybuild
cmake ..
make
I looked at the README and I don't seem anything that helps resolve this issue. Any help/guidance would be super!
As you can see here, Google Mock has been absorbed into the GoogleTest project.
There are various ways to install GoogleTest, described in The GoogleTest Readme. Since you seem to be using CMake, I suggest you follow the steps under
Incorporating Into An Existing CMake Project
You can also put everything that should go into CMakeLists.txt into CMakeLists.GTest and then only put include(CmakeLists.GTest) in CMakeLists.txt.
If you want to determine a fixed version of GoogleTest that should be incorporated, you can use the GIT_TAG eg release-1.8.0´ instead ofmaster` in your CMakeLists.txt.in.
After incorporating GoogleTest in your project, you can add gtests for class Foo by creating eg FooTest.cpp that includes gtest/gtest.h and Foo.h. Therefore, you also have to put add_executable(FooTarget FooTest.cpp) and target_link_libraries(FooTarget gtest) in the corresponding CMakeLists.txt.
You can also find a short description of this, and how to integrate GoogleTests into ctest on these slides).
You need to have gtest inside gmock dir.
I initialy had same error as you, than took gtest version 1.6 from https://github.com/google/googletest and placed it in gmock root dir and succesfully built it.

Building cpp-netlib with CMake

I've downloaded the cpp-netlib source, extracted it to a folder and for some reason I'm completely lost. I read the documentation carefully, it states I have to download CMake as well, which I did. Then I set the source directory and build directories, and upon clicking the "Generate" button I got this output:
The CXX compiler identification is MSVC 19.0.23506.0
Check for working C compiler using: Visual Studio 14 2015
Check for working C compiler using: Visual Studio 14 2015 -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler using: Visual Studio 14 2015
Check for working CXX compiler using: Visual Studio 14 2015 -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/FindBoost.cmake:1657 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
CMakeLists.txt:49 (find_package)
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR)
Looking for pthread.h
Looking for pthread.h - not found
Found Threads: TRUE
CMake Error at CMakeLists.txt:131 (export):
export given target "cppnetlib-client-connections" which is not built by
this project.
Configuring incomplete, errors occurred!
See also "C:/Users/Nick/Documents/cpp-netlib/cpp-netlib-build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Nick/Documents/cpp-netlib/cpp-netlib-build/CMakeFiles/CMakeError.log"
It couldn't find the Boost libraries, and that's where I'm stuck. I installed boost, but I have no idea where to set "BOOST_ROOT". I did some research on that, tried to use the command line with the -DBOOST_ROOT option like so:
c:\Program Files>cmake -DBOOST_ROOT=/boost/boost_1_55_0
But it gives me the following error:
CMake Error: The source directory "C:/Program Files" does not appear to contain
CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
I'm really unsure as to what to do now and I feel this isn't the end of my problems... Is there anything obvious I'm missing?
You need to either run cmake from the source tree (which would contain CMakeLists.txt), or, more typically, run it from a build folder and tell it where the source tree is.
A common case would be creating a build folder next to the source tree and running cmake ../sourcedir.
You seem to have initially been using a gui; surely that provides a means to set the BOOST_ROOT variable?
Alternatively, if you just put boost in the VC++ include/lib paths (either in the vc dirs, or by setting %INCLUDE%/%LIB%), you probably would not need BOOST_ROOT. Same for OpenSSL.

Run ArUco example using Cmake

I am new to Cmake and to build projects using it. I have not used this tool before and hence have less knowledge on how it works.
I am trying to get the examples of the ArUco library run. But the README provided by the ArUco library suggests to use the Cmake to run them. I have Windows 8.1 and Visual studio 2013 and I have also downloaded and installed the Cmake3.4.0 .
After installing it I searched for examples or tutorials on Cmake, and found a few video tutorials that showed how to compile programs using cmake. But while followed the same steps I got errors. Error is as shown
I went through different questions posted in the forum but didn't find an answer. I am not sure I need to set Environment variables and paths. Some suggestions on this would be really helpful.
Thank you very much for the help.
Error:
The C compiler identification is MSVC 18.0.40629.0
The CXX compiler identification is MSVC 18.0.40629.0
Check for working C compiler using: Visual Studio 12 2013
Check for working C compiler using: Visual Studio 12 2013 -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler using: Visual Studio 12 2013
Check for working CXX compiler using: Visual Studio 12 2013 -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
CMake Error at CMakeLists.txt:5 (find_package):
By not providing "Findaruco.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "aruco", but
CMake did not find one.
Could not find a package configuration file provided by "aruco" with any of
the following names:
arucoConfig.cmake<br/>
aruco-config.cmake<br/>
Add the installation prefix of "aruco" to CMAKE_PREFIX_PATH or set
"aruco_DIR" to a directory containing one of the above files. If "aruco"
provides a separate development package or SDK, be sure it has been
installed.
Configuring incomplete, errors occurred!
See also "E:/../aruco_testproject/build/CMakeFiles/CMakeOutput.log".
I had the same issue on Mac, hope Windows users find this useful too.
Most probably you did't install aruco. Go to the aruco source folder that you dowloaded (ie ~/Downloads/aruco-2.0.14) and run following commands
cmake .
make
make install
Then you will be able to build aruco_testproject
cmake .
make
Hope this helps
Actually its pretty clear whats goin wrong. CMake cant find certain packages.
Quick and dirty solution
One solution is to do what the error message suggests:
Go into the specific CMakeLists.txt file and set the aruco_Dir variable like that
set( auruco_Dir /PATH/TO/ARUCO/WHERE/AURUCOCONFIG.CMAKE/IS/LOCATED/AS/WELL )
The true way
A better approach is to provide the Findaruco.cmake module in the CMAKE_MODULE_PATH. This is called module because it integrates with CMake's find_package mechanism (https://cmake.org/cmake/help/v3.0/command/find_package.html, Last accessed at 11.12.2015) and provides the central information about where aruco can be found in your file system. (Aruco is just exemplary here. Same goes for any other module)
What is this good for, why do I need find_packageand those modules?
Answer is simple. You have only one central place to manage and not many. Imagine the location of your pacjage changes. Do you want to fix every single CMakeLists.txt file referencing this package?
Its like basic programming paradigms
Dont repeat yourself
Dont hardcode anything