Disable testing in cmake - testing

The tests of a project that I try to build fail to build (missing libraries). The tests themselves are not important, but prevents me from building and installing the essential files. So I want to do this as a quick-fix.
How do I do to turn of the build of the tests in a cmake project? Should I edit the CMakeLists.txt file in the root or in the subdirectory tests? How should I edit it?
There are one issuing of the command ENABLE_TESTING(). I tried to comment that one out, but it didn't help. Also tried to rename the subdirectory tests. Did not help either. This was only true for a special case where "implicit" tests were being built.

Ok, it worked by editing the CMakeLists.txt to turn off all the flags BUILD_TESTING, BUILD_TESTING_STATIC and BUILD_TESTING_SHARED.
This can most easily be accomplished with this sed command:
sed --in-place=.BACKUP 's/\(BUILD_TESTING[A-Z_]*\) ON/\1 OFF/' CMakeLists.txt
(In one cases there were "implicit" tests that had to be taken care of in a more elaborate way.)

Related

Best way to call Cargo from CMake?

I found this: https://github.com/AndrewGaspar/cmake-cargo but couldn't make it work
Anyway, if I were to use a Makefile instead of CMake, I'd simply create a rule that watches for the .rs files to change and recompile.
I couldn't find a solution for calling Cargo from Cmake (not the other way around) so I'm opening one here.
How can I make my CMakeLists.txt watch for .rs file changes and recompile by calling cargo build?
I'm the author of the linked project in the OP. I apologize for the sorry state it was in when you found it, but in the last month or so I've invested a bunch of time to really flesh it out, and gave it a more inspiring name: https://github.com/AndrewGaspar/corrosion
I hope you could check out the latest README and let me know if you can get it working for your scenario. And if not, please file an issue, letting me know where in the documentation you ran into issues.
Following recommendations, I simply added the command cargo build as a dependency to my library
add_library(libsmoltcp_cpp ${libsmoltcp_cpp_sources})
add_custom_target(
lib_smol_tcp_rust
COMMAND cargo build
)
add_dependencies(libsmoltcp_cpp lib_smol_tcp_rust)

CMake in QtCreator 4.3 shows many automatic targets, how to remove/hide them?

I just switched to the last version of QtCreator (4.3.1) and the project explorer now shows many targets like ContinuousBuild, ContinuousConfigure, NightlyBuild, ExperimentalCoverage etc.
How can I remove all of these (or at least hide them) ?
I don't even know where this is generated in CMake.
Seems to be related to this question Hide automatically generated CTest targets except that I am not using CLion.
You are probably using somewhere:
include(CTest)
According to the documentation:
Configure a project for testing with CTest/CDash
All those targets are pulled in by the combination of the two, CTest and CDash (almost all of them are due to the latter actually).
If you don't know why they are there and for what they can be used, probably you are using the wrong command.
If all what you want is to use only CTest, add tests with add_test and run them with make test, replace the line above with this one:
enable_testing()
The documentation is quite clear indeed:
Enable testing for current directory and below.
Clean up the build directory and run cmake from scratch from within QtCreator. All the targets you mentioned should disappear.
I had exactly the same problem in a project of mine when I updated QtCreator a couple of months ago. You can see in the history of the project the commit that solved the issue. Pretty short indeed.

Using CMake to generate multiple Code Composer build configurations

My goal is to use a script/CMake to create a "Debug" build configuration and a "Release" build configuration that can be switched between within Code Composer Studio's UI (using the "Build Configuration -> Set Active..." option).
Currently,
A script is ran that runs CMake with desired commands (toolchain, etc). A Code Composer Studio project is generated (as described in CMakeLists.txt)
CCS project is imported into CCS
The problem is this only generates a "Debug" build configuration. Is it possible to add a command to CMakeLists.txt, or to cmake command line, or even ccs command line that allows multiple build configurations to be generated?
The only difference between the two will basically be defining NDEBUG, and possibly changing optimization level.
I had this same question...then realized I am the one who originally asked this ~4 years ago! Anyways, I found a way to do this:
Using Code Composer, create the build configuration(s) as you want them to behave. When done, copy the .cproject file to a cproject.in "template". CMake will use this template to generate an identical .cproject for any future cmake builds. Make sure to replace any hardcoded values (ex: project name) with proper cmake variables.
For me, my CMakeLists.txt called configure_file(path/to/cproject.in ${CMAKE_SOURCE_DIR}/.cproject #ONLY).
Also be sure to delete your CMakeCache and CMakeFiles if they already exist...I believe those were preventing me from seeing the resulting change.

How can I configure CMake generated Eclipse project's Build Command and Project Paths?

Our project uses CMake to configure our code. We use Ninja along with a distributed build system. A number of people on our team use Eclipse CDT. We run CMake with the "Eclipse CDT4 - Ninja" generator and the result is generally pretty good.
The issues is that any time a CMake file is changed and you ask Eclipse to build the code it regenerate the eclipse project file overwriting any manual changes you've made to the project.
For example the default build command that it provides the eclipse project is /usr/bin/ninja when in fact I want to take advantage of our distributed build system and set the build command to /usr/bin/ninja -j16. It would be nice if I could have the project file that CMake generates automatically include this setting change.
The other setting I am most interested in preserving is the C/C++ Project Paths->Source. As a general rule we place our CMake build directory as a sibling to the main project directory i.e. ./project ./build. We want to include some files in the build directory in the Eclipse index to make code completion and other tools work better. The default project doesn't include the build directory in source path and thus it does not get indexed.
Is there some way to remedy these issues?
I found a solution to build command issue.
When you run cmake to generate the eclipse project include the additional argument:-DCMAKE_ECLIPSE_NINJA_ARGUMENTS=-j100. I haven't confirmed but I believe a similar command is required for eclipse make projects -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-j100.
Unfortunately this feature is poorly documented and I have not found a solution to my other issue.

CMake/CTest & gcovr: filename extensions?

After compiling with CMake with flags --coverage, and running my boost unit test programs, files with extension .cpp.gcda and .cpp.gcno are created. If I then run gcovr it claims it cannot find the .gcno files (error message ".gcno:cannot open graph file"). I could possibly move all output files but that would be really awkward/silly.
Related problems of other people could be solved by using CTest but as I am using Jenkins I'd like to stick to gcovr and use the cobertura xml output.
Ps. Maybe I should simply ask: how should I combine CMake with gcovr?
This is the solution we are using for the same setup inside jenkins: http://www.semipol.de/archives/320. You can simply grab the CMake macro from the linked RSC library for your own purposes.
Apart from that read something about a slightly changed format of the coverage files in recent gcc versions and it seems gcovr didn't keep up with that. But I cannot remember where I read this.