Skip to content

Commit 65cf762

Browse files
authored
Merge pull request #31 from kimkulling/bugfix/fix_gtest_linkage
Make direct source include optional
2 parents 143c6fc + 8980906 commit 65cf762

File tree

8 files changed

+30
-21
lines changed

8 files changed

+30
-21
lines changed

CMakeLists.txt

+15-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ SET ( CPPCORE_VERSION_PATCH 0 )
66
SET ( CPPCORE_VERSION ${CPPCORE_VERSION_MAJOR}.${CPPCORE_VERSION_MINOR}.${CPPCORE_VERSION_PATCH} )
77
SET ( PROJECT_VERSION "${CPPCORE_VERSION}" )
88

9+
find_package(GTest)
10+
911
if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
1012
find_package(Threads)
1113
endif()
@@ -30,8 +32,6 @@ add_definitions( -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING=1)
3032

3133
INCLUDE_DIRECTORIES( BEFORE
3234
include/
33-
contrib/googletest-1.15.2/googletest/include
34-
contrib/googletest-1.15.2/googletest
3535
)
3636

3737
link_directories(
@@ -157,8 +157,6 @@ IF( CPPCORE_BUILD_UNITTESTS )
157157
test/Random/RandomGeneratorTest.cpp
158158
)
159159

160-
SET ( GTEST_PATH ../contrib/googletest-1.15.2 )
161-
162160
SOURCE_GROUP( code FILES ${cppcore_test_src} )
163161
SOURCE_GROUP( code\\common FILES ${cppcore_common_test_src} )
164162
SOURCE_GROUP( code\\container FILES ${cppcore_container_test_src} )
@@ -168,7 +166,18 @@ IF( CPPCORE_BUILD_UNITTESTS )
168166
# Prevent overriding the parent project's compiler/linker
169167
# settings on Windows
170168
SET(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
171-
ADD_SUBDIRECTORY( contrib/googletest-1.15.2/ )
169+
if (GTest_FOUND)
170+
SET(test_libs GTest::gtest_main)
171+
else()
172+
SET(test_libs gtest_main)
173+
SET ( GTEST_PATH ../contrib/googletest-1.15.2 )
174+
INCLUDE_DIRECTORIES(
175+
contrib/googletest-1.15.2/googletest/include
176+
contrib/googletest-1.15.2/googletest
177+
)
178+
ADD_SUBDIRECTORY( contrib/googletest-1.15.2/ )
179+
endif()
180+
172181
ADD_EXECUTABLE( cppcore_unittest
173182
${cppcore_test_src}
174183
${cppcore_common_test_src}
@@ -182,5 +191,5 @@ IF( CPPCORE_BUILD_UNITTESTS )
182191
ELSE( WIN32 )
183192
SET( platform_libs pthread )
184193
ENDIF( WIN32 )
185-
target_link_libraries( cppcore_unittest cppcore ${CMAKE_THREAD_LIBS_INIT} gtest_main ${platform_libs} )
194+
target_link_libraries( cppcore_unittest cppcore ${CMAKE_THREAD_LIBS_INIT} ${platform_libs} ${test_libs})
186195
ENDIF()

contrib/googletest-1.15.2/googletest/generated/GTestConfig.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ endmacro()
2424

2525
####################################################################################
2626
include(CMakeFindDependencyMacro)
27-
if (ON)
27+
if ()
2828
set(THREADS_PREFER_PTHREAD_FLAG )
2929
find_dependency(Threads)
3030
endif()
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
libdir=/usr/local/lib
2-
includedir=/usr/local/include
1+
libdir=C:/Program Files (x86)/osre/lib
2+
includedir=C:/Program Files (x86)/osre/include
33

44
Name: gmock
55
Description: GoogleMock (without main() function)
66
Version: 1.15.2
77
URL: https://github.com/google/googletest
88
Requires: gtest = 1.15.2
99
Libs: -L${libdir} -lgmock
10-
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1
10+
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=0
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
libdir=/usr/local/lib
2-
includedir=/usr/local/include
1+
libdir=C:/Program Files (x86)/osre/lib
2+
includedir=C:/Program Files (x86)/osre/include
33

44
Name: gmock_main
55
Description: GoogleMock (with main() function)
66
Version: 1.15.2
77
URL: https://github.com/google/googletest
88
Requires: gmock = 1.15.2
99
Libs: -L${libdir} -lgmock_main
10-
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1
10+
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=0
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
libdir=/usr/local/lib
2-
includedir=/usr/local/include
1+
libdir=C:/Program Files (x86)/osre/lib
2+
includedir=C:/Program Files (x86)/osre/include
33

44
Name: gtest
55
Description: GoogleTest (without main() function)
66
Version: 1.15.2
77
URL: https://github.com/google/googletest
88
Libs: -L${libdir} -lgtest
9-
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1
9+
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=0
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
libdir=/usr/local/lib
2-
includedir=/usr/local/include
1+
libdir=C:/Program Files (x86)/osre/lib
2+
includedir=C:/Program Files (x86)/osre/include
33

44
Name: gtest_main
55
Description: GoogleTest (with main() function)
66
Version: 1.15.2
77
URL: https://github.com/google/googletest
88
Requires: gtest = 1.15.2
99
Libs: -L${libdir} -lgtest_main
10-
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1
10+
Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=0

contrib/googletest-1.15.2/googletest/gtest.dir/Debug/gtest.lib.recipe

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<ProjectOutputs>
44
<ProjectOutput>
5-
<FullPath>C:\develop\projects\cppcore\x64\Debug\ZERO_CHECK</FullPath>
5+
<FullPath>C:\develop\projects\osre\x64\Debug\ZERO_CHECK</FullPath>
66
</ProjectOutput>
77
</ProjectOutputs>
88
<ContentFiles />

contrib/googletest-1.15.2/googletest/gtest_main.dir/Debug/gtest_main.lib.recipe

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<ProjectOutputs>
44
<ProjectOutput>
5-
<FullPath>C:\develop\projects\cppcore\x64\Debug\ZERO_CHECK</FullPath>
5+
<FullPath>C:\develop\projects\osre\x64\Debug\ZERO_CHECK</FullPath>
66
</ProjectOutput>
77
</ProjectOutputs>
88
<ContentFiles />

0 commit comments

Comments
 (0)