{"id":13419526,"url":"https://github.com/dmonopoly/gtest-cmake-example","last_synced_at":"2025-03-15T05:31:33.160Z","repository":{"id":6195052,"uuid":"7425646","full_name":"dmonopoly/gtest-cmake-example","owner":"dmonopoly","description":"Helpful example of a gtest and cmake set up for C++.","archived":false,"fork":false,"pushed_at":"2017-04-24T14:51:06.000Z","size":2008,"stargazers_count":313,"open_issues_count":3,"forks_count":124,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-07-31T22:49:49.505Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmonopoly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-03T16:18:02.000Z","updated_at":"2024-06-30T16:35:56.000Z","dependencies_parsed_at":"2022-09-04T01:51:10.542Z","dependency_job_id":null,"html_url":"https://github.com/dmonopoly/gtest-cmake-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmonopoly%2Fgtest-cmake-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmonopoly%2Fgtest-cmake-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmonopoly%2Fgtest-cmake-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmonopoly%2Fgtest-cmake-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmonopoly","download_url":"https://codeload.github.com/dmonopoly/gtest-cmake-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221541904,"owners_count":16840118,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:01:17.226Z","updated_at":"2024-10-26T14:32:07.063Z","avatar_url":"https://github.com/dmonopoly.png","language":"C++","readme":"# What is this?\nThis is an example setup of cmake with google test. I got it working after\nconsulting the google test primer, among other things. Hopefully it'll help\nsomeone get set up with C++ and google test.\n\n# Where are things?\n`build/` is where code is built - like where executables are.  \n`lib/` includes gtest-1.6.0.  \nRest of code in root:  \n-`CMakeLists.txt` must be in each subdirectory of the project  \n-`main.cpp` is just a driver file - the common place to run the normal\napplication  \n-`project1.cpp` and `project1.h` have code for the class 'Project1'  \n-`test_project1.cpp` has code to test Project1  \n\n# What do I do?\n\n## Use cmake and make\nIf you want to test it all out through the common gtest procedure, first\n**delete build/** (if present). Then...\n\nIn the project root:\n\n    mkdir build\n    cd build\n    cmake ..\n\nBy now Makefiles should be created.\nThen, to build executables and do all that linking stuff,\n\n    make\n\nTo prepare all your tests, run this:\n\n    cmake -Dtest=ON ..\n\nTo run all tests easily,\n\n    make test\n\n## Run executables\nThen you can do ./myexecutable for the generated executable, e.g.:\n\n    ./project1\n\nand if you did cmake with test=ON:\n\n    ./runUnitTests\n\n# Details\n\n## Command things\n`cmake -Dtest=ON` turns on the variable 'test', which is specified in the root\nCMakeLists.txt file. This is handy if you want to build in certain ways. Clear\ndescription\n[here](http://stackoverflow.com/questions/5998186/cmake-adding-command-line-options).\n\n## My experience\nI spent a lot of time figuring out how I wanted to reference the gtest library.  \n\n[On StackOverflow](http://stackoverflow.com/questions/9689183/cmake-googletest)\nthere are ways to download the svn repo when you cmake, but that's internet\nconnection dependent. There is also a way to set a variable for where gtest is\ninstalled on your system, but that got a bit tedious.  \n\nIn the end I opted to just have a copy of gtest locally in whatever application\nI have that uses gtest.  \n[This user's edited\nsolution](http://stackoverflow.com/questions/8507723/how-to-start-working-with-gtest-and-cmake)\nand [my own question's\nresponse](http://stackoverflow.com/questions/14148145/gtest-detects-method-only-when-the-method-is-implemented-in-h-not-in-cpp-cma/14157405#14157405)\nhelped me out.\n\n","funding_links":[],"categories":["TODO scan for Android support in followings","C++","Tools"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmonopoly%2Fgtest-cmake-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmonopoly%2Fgtest-cmake-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmonopoly%2Fgtest-cmake-example/lists"}