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.
Related
I have a project that compiles right when I configure it from the command line:
cmake .. -DCMAKE_GENERATOR="MinGW Makefiles"
generator is set to MinGW Makefiles
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/jose/Documents/ApD_PRG/test_v2/Build
But surprisingly it doesn't when I asjust it at the beginning of the CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set (CMAKE_GENERATOR "MinGW Makefiles" CACHE INTERNAL "" FORCE)
message("generator is set to ${CMAKE_GENERATOR}")
set(CMAKE_PROJECT_NAME "testProject")
...
$ cmake ..
-- Building for: Visual Studio 14 2015
generator is set to MinGW Makefiles
-- Selecting Windows SDK version to target Windows 10.0.18363. <--------- HERE!!!
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/jose/Documents/ApD_PRG/test_v2/Build
It automatic gets the Windows SDK, and the project doesn't compile any more.
Please, somebody so kind to help me in the avoid of the Windows SDK inclusion from CMakeLists.txt?
Thanks in advance
pd: I need this way, because I want that eclipse automatic select the right compiler on import
It doesn't work because you simply cannot set the generator from within the CMakeLists.txt file.
From the documentation (emphasis mine)
The value of this variable should never be modified by project code. A generator may be selected via the cmake(1) -G option, interactively in cmake-gui(1), or via the CMAKE_GENERATOR environment variable.
Since I'm not familiar with Eclipse I cannot guarantee that it works, but you can try to set the CMAKE_GENERATOR env-variable to MinGW Makefiles when using CMake 3.15 or later.
However, there is a good chance that
the CMake plugin you're using needs to be aware of the generator being used in order to be able to parse the build output, and as such manually adds -G <generator> for the generator configured in the plugin to the CMake invocation, thus overriding the value set in the env-variable, or
the Eclipse plugin only knows how to handle the output of the default generator, but also doesn't enforce it with -G <generator>, in which case you setting a different generator might cause it to fail to parse the build output for errors / warnings.
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.
I have a CMake project that works fine on Linux with g++.
On Windows (10, Creators Update) CMake runs fine and generates relevant files.
So I opened TestProject.sln solution file and for a test run, I ran 'Local Windows Debugger' and got this error.
Error LNK1104 cannot open file 'jsoncpp.lib'
This is how I've setup this project.
.
|-root
| |- src
| |- lib
| |- bin
| |- app
| |- include
| |- extras
| |- jsoncpp
|-build
I'm not really sure what could be wrong here.
I have jsoncpp added as a submodule.
I did
git submodule update --init --recursive
and there is a jsoncpp.lib file in
root\lib\Debug
This is my CMakeLists.txt
cmake_minimum_required (VERSION 3.13)
project (TestProject)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/root/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/root/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/root/bin)
set(SOURCE_DIR ${PROJECT_SOURCE_DIR}/root/src)
set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/root/include)
set(EXTRAS_DIR ${PROJECT_SOURCE_DIR}/root/extras)
set(PROJECT_MAIN_DIR ${PROJECT_SOURCE_DIR}/root/app)
set(SOURCES
${INCLUDE_DIR}/Combinations.hpp
${INCLUDE_DIR}/Lib.hpp
${SOURCE_DIR}/Lib.cpp
)
add_executable(TestProject ${PROJECT_MAIN_DIR}/Main.cpp ${SOURCES})
add_subdirectory(${EXTRAS_DIR}/jsoncpp jsoncpp)
target_link_libraries(TestProject jsoncpp)
set_target_properties(TestProject PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_STANDARD 17
CXX_EXTENSIONS OFF
)
This is CMake's output
Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.17134.
The C compiler identification is MSVC 19.16.27026.1
The CXX compiler identification is MSVC 19.16.27026.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- 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: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
JsonCpp Version: 1.8.4
Looking for C++ include clocale
Looking for C++ include clocale - found
Looking for localeconv
Looking for localeconv - found
Looking for C++ include sys/types.h
Looking for C++ include sys/types.h - found
Looking for C++ include stdint.h
Looking for C++ include stdint.h - found
Looking for C++ include stddef.h
Looking for C++ include stddef.h - found
Check size of lconv
Check size of lconv - done
Performing Test HAVE_DECIMAL_POINT
Performing Test HAVE_DECIMAL_POINT - Success
Found PythonInterp: C:/Users/USERNAME/emacs-26.1-x86_64/bin/python2.exe (found suitable version "2.7.14", minimum required is "2.6")
Configuring done
Generating done
I'm not very familiar with Visual Studio but looking at the error, it says 'cannot open' and not 'couldn't find' so my first thought was maybe it's a permission issue.
So I booted up VS with Admin Privileges but the error continued.
I thought maybe there's some compiler issue so I used nmake.exe as a compiler (after generating nmake makefiles) but no luck there either.
I'm not sure if it's a linker issue since CMake was able to find and link jsoncpp library so I doubt CMake made a mistake building the Makefile.
I'm not sure how I should go about debugging the issue.
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.
I've been trying to get the Point Cloud Library properly installed on my system. I would like to be able to get the basic tutorial working so that I know everything is correct and I can move on.
This has so far been a case of dealing with problem after problem of which this is the latest.
When I run cmake it errors and outputs:
-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- 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
CMake Error at CMakeLists.txt:3 (find_package):
By not providing "FindPCL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "PCL", but
CMake did not find one.
Could not find a package configuration file provided by "PCL" (requested
version 1.3) with any of the following names:
PCLConfig.cmake
pcl-config.cmake
Add the installation prefix of "PCL" to CMAKE_PREFIX_PATH or set "PCL_DIR"
to a directory containing one of the above files. If "PCL" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/matt/hdd_home/pcl/tutorials/build/CMakeFiles/CMakeOutput.log".
I've installed PCL v1.8 from the Ubuntu repository but I've also installed python-vtk because it provides the package libvtkRenderingPythonTkWidgets which removes an error I was facing previously (see here). Installation of python-vtk I believe removes some of the packages bundled in libpcl-dev (PCL v1.8); I don't know whether this is relevant to the issue.
I'm not 100% sure that PCLConfig.cmake or pcl-config.cmake are even on my system. Maybe there has been an issue with the installation?
Any help is much appreciated!