Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6531127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:50:25+00:00 2026-05-25T09:50:25+00:00

I’m new to CMake and I’m using the Google Test Framework. I’ve looked for

  • 0

I’m new to CMake and I’m using the Google Test Framework. I’ve looked for more complex examples of combining CMake and the Google testing framework, but I’ve not turned up much luck. I was hoping that someone could provide their opinion on the setup I’ve arrived at and answer a question for me. Here’s the basic project structure:

ProjectFolder
-CMakeLists.txt
/build
/include
  -all my .h files
/src
  -CMakeLists.txt
  -all my .cpp files
/tests
  -CMakeLists.txt
  /gtest
    -Google’s CMakeLists.txt
  /mocks
    -CMakeLists.txt
    -cpp and h files for mocks

In a nutshell the root cmake file adds src and tests as subdirectories. The src cmake file globs the cpp files into a library. The tests cmake file adds mocks and gtest as subdirectories. The mock cmake file globs all of its cpp files into a second library. Finally the cmake file in the tests folder links the src library, google libraries, and the mocks libraries with the unit test executables.

What I eventually get are several executables: objA_unittest, objB_unittest, etc

A few things:

  1. To build all of this and still keep my project directory fairly clean I cd into the build folder and run “cmake ..” This seems to work really well and I was planning on configuring vim to always run make out of this folder. Does anyone have any tips or or see any problems with this approach?

  2. I’m not fond of the idea of having to nest the google library in my project folder (particularly if I eventually have several projects that use it), but as it seems to be highly suggested that you not precompile the google libraries I can see no way around this. However, if anyone does know of a better way, I would love to hear it.

  3. Running the tests. I like that all I have to do is run “make test” to execute all of my unit tests with ctest. However, I’ve discovered that I don’t like the output very much. Each unit test executable contains several different unit tests. Running these directly provides Google’s very verbose feedback. If one of the tests in an executable fails I know exactly what test fails and why. Previously, I used a makefile and at the end of the makefile I simply executed all of the tests. I first attempted to fix this by creating a custom build target in cmake. However, it only executes the first command. I either need a way to get more verbose output from CTest OR I need a way to automatically output a bash script or something similar from CMake to execute each unit test executable. In other words, I have the cmake file set up now so I only have to add the unit test in one place to generate the executable, and I don’t want to have to remember to add it to a second place if I can avoid it. Does anyone have any experience that would be helpful in this point?

Thanks very much in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:50:25+00:00Added an answer on May 25, 2026 at 9:50 am
    1. It is actually a recommended cmake practice called out-of-source build
    2. AFAIK it is not recommended to install recompiled googletest libraries in the system. So there should not be any problem if you compile it as shared or static library as part of your project build. I have used googletest 1.6.0 this way without problems on Windows, Linux, OSX and Android.
    3. I’m not sure about CTest but custom target is definitely able to run all tests for you. Here is a short solution I can suggest:

    Add following lines into your top level CMakeLists.txt (before adding any tests):

    add_custom_target(test)
    macro(run_test test_target)
      add_custom_target(${test_target}_runtest
          COMMAND ${test_target} #cmake 2.6 required
          DEPENDS ${test_target}
          WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
      add_dependencies(test ${test_target}_runtest)
    endmacro()
    

    Next for each test add a single line to append your test to the test target:

    #add_executable(mytest ${mysources})
    run_test(mytest)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.