Currently, main() in the gtest_main target becomes ill-formed due to the definition of GTEST_API_, which is conditioned on the GTEST_LINKED_AS_SHARED_LIBRARY compile definition.
The gtest target (before this change) adds the mentioned definition as an INTERFACE definition, which gets picked up by gtest_main, resulting in the definition of the main function being declared as __declspec(dllimport) on Windows.
To keep the INTERFACE compile definitions of GTEST_LINKED_AS_SHARED_LIBRARY for both gtest_main and gtest, I've simply made them two separate targets that do not link to each other. Alternatively, the gtest target could be dropped altogether since it isn't needed, but I figured it could make sense to keep it around if it'll be needed later.
I'm not thrilled to have two separate targets for gtest and gtest_main, but it seems like the least bad solution if one wants to keep the INTERFACE definitions for both targets.
Currently,
main()
in thegtest_main
target becomes ill-formed due to the definition ofGTEST_API_
, which is conditioned on theGTEST_LINKED_AS_SHARED_LIBRARY
compile definition.The
gtest
target (before this change) adds the mentioned definition as anINTERFACE
definition, which gets picked up bygtest_main
, resulting in the definition of the main function being declared as__declspec(dllimport)
on Windows.To keep the
INTERFACE
compile definitions ofGTEST_LINKED_AS_SHARED_LIBRARY
for bothgtest_main
andgtest
, I've simply made them two separate targets that do not link to each other. Alternatively, thegtest
target could be dropped altogether since it isn't needed, but I figured it could make sense to keep it around if it'll be needed later.I'm not thrilled to have two separate targets for
gtest
andgtest_main
, but it seems like the least bad solution if one wants to keep theINTERFACE
definitions for both targets.