googletest project structure on Linux - googletest

Is it a good idea to keep googletest source code (say googletest-release-1.8.1.tar.gz) as a part of a C++ project and build it every time the test target is invoked?
My Linux distribution has both gtest and gmock but not all distributions have them. Moreover, nowadays both gtest and gmock are under single repo umberella https://github.com/google/googletest and therefore I'm not sure how gtest and gmock will look like in the future. Having googletest source code as a part of a project would probably solve my concerns. But I'm not sure whether it is inline with the C++ best practices. I could not find any recommended ways doing that in Linux.

Building googletest as a prerequisite of your test target is common practice.
For CMake-managed projects, Googletest documents how to incorporate in an existing CMake project.
For autotools managed projects, How can I use Google Test with my project that builds via autotools?
has a well-regarded solution on SO.
Building googletest as a prerequisite of a project test suite ensures that the googletest code
with which a downstream user of your project builds and runs your tests is the same code
that you built and ran upstream. It ensures that googletest is built with the same compilation
and linkage options as the code under test.
These advantages come at an acceptable cost because Googletest is a cheap build-target whose only dependencies
are the C++ toolchain and pthreads (and even pthreads is optional).

Related

Is Gradle the Equivalent of a Compiler?

From what I know, Gradle is a build automation system that combines and describes the app's project structure, configuration and dependencies to output an APK. Does this mean that the Gradle is equivalent to a compiler?
If they aren't equivalents, then what are the differences and how do they relate?
Gradle is not equivalent to the compiler. Compilers primarily meant for translating the high-level language(i.e. java) into machine code or other intermediate code representation like bytecode. wheres Gradle is a build system that packages the code for you and makes it ready for compilation. If you take an example from android, under the hood, Gradle downloads the defined dependencies and packages everything for you without messing up and simplifies the development flow. It does all the dependencies management for the project. Gradle output is not the translated code, instead, you can say it's arranged code. finally Gradle is not equivalent of any compiler.
There is a similar question on StackOverflow Post. Rather putting post multiple times, you can accept satisfactorily answer, so moderators can remove the duplicate/unaccepted one.

CMake targeting multiple platforms in a single build

I am now working on my c++ project. I would like to use CMake targeting multiple platforms in a single build. From the post here
How to make CMake targeting multiple platforms in a single build
It mentioned that we can automate this by having an enclosing build script which invokes CMake once for each target platform and performs several out-of-source builds to distinct binary directories. The enclosing script could also be written in CMake(ExternalProject). I have no idea how to write this automation in Cmake ExternalProject. Could anyone suggest me an idea or give me an example on it?

Are cmake scripts generally written by hand?

I need to create a cmake project which should be able to be built on linux and windows. So I looked into cmake Tutorials and all of them told me to setup the build process by hand. Bit looking at other projects made with cmake, the scripts seam like they were created by a computer (no formatting no comments). So I was wondering if there was a more automated aproach or tool that can be used for cmake files. Or are most cmake scripts really written by hand?
Yes, CMakeLists.txt are generally written by hand. Generated are SomeProjectConfig.cmake modules, which contain exported targets and information how the project was built. These modules are used by find_package command when you want to use SomeProject from your own project.

Using KDevelop during development of a shared library

I'm trying to use KDevelop as an IDE for development of a C++ shared library. An earlier posts here indicate that I need to edit a CMake makefile for doing that. This is quite painful and very time consuming as it means converting our custom gmake-oriented build system into something of CMake.
Is there any other way for doing that?
KDevelop doesn't force you to use a specific buildsystem like many other IDEs do. CMake is just the default as it's very well integrated and many if not all KDE projects use cmake.
You can use a different build system by choosing "Custom Buildsystem" or "Custom Makefile Project Manager".
Custom Makefile Project Manager simply calls "make" - your current build system should work this that.

Maintain a cmake project (from Eclipse CDT4)

I'm having some difficulties with cmake (2.8.7) and Eclipse + CDT (3.7.1). I'm using a CMakeBuilder (http://www.cmakebuilder.com/), which I found via the search function here. Actually I thought, that'd be it.
Problem is that it does not provide any import function either: So I need cmake to generate Eclipse CDT4 Makefiles initially, which requires me to maintain two separate build systems and to work on copies. One for deployment, one for development.
Furthermore I'd need to copy my changes over into the original project, file by file, because I can just work on copies, that cmake generates together with the Makefiles. At the end: twice the work. Double-check integration each time.
Is there anything one can do to work directly on a cmake project from Eclipse (or another sane IDE)? Mainly I need good C++ editing (very large set of libs, so the paths are a major problem, and cmake searches for these on every platform). I could maintain cmake on my own, but Eclipse (and other IDEs) miss a useful import settings. Some IDE would be nice though. ;)
Best,
Marius
As I remember KDevelop4 has native support. In other hand: why don't edit CMakeLists.txt directly as a simple script (from an editor*) and use the official GUI? I haven't used Eclipse with CMake, but in Visual Studio the solution is generated automatically after editing any of project or solution CMakeLists.txt file. I expect something similar from Eclipse, too.
Eclipse CDT4 Generator
More info.
*: Notepad++ has highlight for CMake files.