googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Rewrite gtest_main.cc, gmock_main.cc, gtest-all.cc, and gmock-all.cc to use `.h` or `.hpp` files rather than `.cc` files.

Open AeroSW opened this issue 1 year ago • 0 comments
trafficstars

Hello everyone,

I am attempting to build googletest and googlemock from its source directly using Premake5.

Background on builder choice: My project is using Premake5 because it seemed easier to setup compared to CMAKE, and I feel this is true so far, since, CMAKE guides are relatively confusing to follow and Premake5 is just Lua.

Issue

I am currently running into an error where my generated makefile script is finding the following error:

extern/__include__/GoogleTest/googlemock/src/gmock-all.cc:42:10: fatal error: src/gmock-cardinalities.cc: No such file or directory
   42 | #include "src/gmock-cardinalities.cc"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

This error feels weird because it makes it seem like I should add -Igooglemock/src which is not really a standard practice for C++ where you typically want to Include Header files and not Source files.

I have GoogleTest project forked and linked as a submodule to my project, so I have everything that is on the master branch. Is this a mistake in the source code to include source code rather than the headers?

Additional Information

I am using VSCode with GCC 14 (C++23).

Edit 1 (From my own comment below)

https://cplusplus.com/forum/general/39618/

Generally, it seems to be looked down upon to include source files due to compilation and linking ending up including the file twice...

Edit 2 (From my second comment)

Looking at your CMakeLists.txt file, it does appear that you are including source files as if they were header files...

get_target_property(gtest_include_dirs gtest INCLUDE_DIRECTORIES)
set(gmock_build_include_dirs
  "${gmock_SOURCE_DIR}/include"
  "${gmock_SOURCE_DIR}"
  "${gtest_include_dirs}")
include_directories(${gmock_build_include_dirs})

Originally posted by @AeroSW in https://github.com/google/googletest/discussions/4580

AeroSW avatar Jul 31 '24 23:07 AeroSW