lcm-proj / lcm

Lightweight Communications and Marshalling
GNU Lesser General Public License v2.1
980 stars 388 forks source link

Don't define GTEST_LINKED_AS_SHARED_LIBRARY for gtest_main target #351

Closed hoxell closed 1 year ago

hoxell commented 3 years ago

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.