Skip to content

Commit eade7bd

Browse files
Merge branch '79-integrate-google-test' into develop
2 parents 2e93d25 + c59f713 commit eade7bd

File tree

10 files changed

+92
-585
lines changed

10 files changed

+92
-585
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ DerivedData/
3939

4040
# MAc OS X
4141
.DS_Store
42+
*.icloud
4243

4344
# MAc OS X
4445
.DS_Store

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
v1.8.0
2+
- integrate GTest as an external module (#79)
23
- use CMake
34
v1.7.3
45
- sync_queue::set_max_size accepts 0.

CMakeLists.txt

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ set(CMAKE_CXX_STANDARD 11)
1414

1515
configure_file(src/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h)
1616

17-
# this works becaus we've extended CMAKE_MODULE_PATH
17+
# this works because we've extended CMAKE_MODULE_PATH
1818
# uncomment if you have a conanfile.txt and run 'conan install ...' include(conan_paths)
19-
find_package(Git CONFIG)
20-
find_package(Conan)
19+
#find_package(Git CONFIG)
20+
#find_package(Conan)
2121

2222
# main targets --------------------------------------------------
2323
#
@@ -38,40 +38,34 @@ endif()
3838
# project's public headers
3939
include_directories(include src)
4040

41-
add_library(cpp-pthread-static STATIC
41+
set(PTHREAD_SOURCE_CODE
4242
src/config.h
4343
src/condition_variable.cpp
4444
src/exceptions.cpp
4545
src/lock_guard.cpp
4646
src/pthread.cpp
4747
src/read_write_lock.cpp
4848
src/thread.cpp
49-
src/mutex.cpp)
49+
src/mutex.cpp
50+
)
51+
add_library(cpp-pthread-static STATIC ${PTHREAD_SOURCE_CODE})
5052
target_link_libraries(cpp-pthread-static pthread)
5153
set_target_properties(cpp-pthread-static PROPERTIES OUTPUT_NAME cpp-pthread)
5254

53-
add_library(cpp-pthread-shared SHARED
54-
src/config.h
55-
src/condition_variable.cpp
56-
src/exceptions.cpp
57-
src/lock_guard.cpp
58-
src/pthread.cpp
59-
src/read_write_lock.cpp
60-
src/thread.cpp
61-
src/mutex.cpp)
55+
add_library(cpp-pthread-shared SHARED ${PTHREAD_SOURCE_CODE})
56+
6257
target_link_libraries(cpp-pthread-shared pthread)
6358
set_target_properties(cpp-pthread-shared PROPERTIES OUTPUT_NAME cpp-pthread)
6459

6560
# Testing -------------------------------------------------------
6661
#
6762

68-
# Locate GTest
69-
if ( BUILD_TESTS )
70-
find_package(GTest)
71-
if (GTest_FOUND)
72-
enable_testing()
73-
add_subdirectory(tests)
74-
endif()
63+
# Load and compile GTest
64+
# Aliases: GTest::GTest, GTest::gtest_main, GMock::GMock
65+
find_package(GTest PATHS cmake)
66+
if (GTest_FOUND)
67+
enable_testing()
68+
add_subdirectory(tests)
7569
endif()
7670

7771
# doxygen -------------------------------------------------------
@@ -98,19 +92,14 @@ install( DIRECTORY include DESTINATION include COMPONENT Devel)
9892
#
9993

10094
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
101-
# set(CPACK_GENERATOR "RPM")
102-
10395
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
10496
set(CPACK_PACKAGE_RELEASE 1)
10597
set(CPACK_PACKAGE_CONTACT "Herbert Koelman")
10698
set(CPACK_PACKAGE_VENDOR "Urbix Software")
10799
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
108-
# set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}")
109100

110101
include(CPack)
111102

112-
cpack_add_install_type(develop DESCRIPTION "includes & libs (for developpers)")
113-
114103
# misc ------------------------------------------------------------
115104
#
116105
find_program(RM rm)

README.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,21 @@ Of course, this library is a replacement of C++11 features, it is best to use th
88

99
To use this library:
1010

11-
configure
12-
make
13-
make install
14-
15-
or
16-
1711
mkdir build && cd build
1812
cmake ..
1913
make install
2014

2115
Install moves files into your system's default location for headers and libraries (often /usr/local/include and /usr/local/lib). Use this command line argument to change install target directory:
2216

23-
configure --prefix=/usr/local
17+
cmake -DCMAKE_INSTALL_PREFIX=/your/destination/
2418

2519
Doxygen [documentation](http://herbertkoelman.github.io/cpp-pthread/doc/html/) can be generated with this command. I hope this help make things easier to use and understand.
2620

2721
make doxygen
2822

2923
> Doxygen can be downloaded [here](http://www.stack.nl/~dimitri/doxygen/index.html).
3024
31-
The `make` target `pkg` will produce au tar.gz that can be distributed.
25+
The `make` target `package` will produce au tar.gz that can be distributed.
3226

3327
### How to use it
3428

@@ -38,13 +32,7 @@ Once compiled and installed in a location that suites you, use your compiler opt
3832

3933
Once your compiler is upgraded you simply include the standard `#include <thread>` and replace the namespace `pthread` for `std`.
4034

41-
Sample code can be found in the `tests` directory. To use it, run the following commands:
42-
43-
cd tests
44-
./configure
45-
./make
46-
47-
> **WARNING** tests rely on GoogleTest and which MUST be installed before building.
35+
Sample code can be found in the `tests` directory.
4836

4937
If you use CMake, the test are built and run like this (in your `build` directory):
5038

@@ -96,4 +84,4 @@ This project can produce Conan Artefacts using these commands:
9684

9785
### Diagrams
9886

99-
![overview](diagrams/threads-classes.png)
87+
![overview](diagrams/threads-classes.png)

cmake/CMakeLists.txt.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.11)
2+
3+
message(STATUS "Loading external project GoogleTest")
4+
5+
# project(googletest-download NONE)
6+
project(googletest-download VERSION 1.8.1)
7+
8+
include(ExternalProject)
9+
ExternalProject_Add(googletest
10+
GIT_REPOSITORY https://github.com/google/googletest.git
11+
GIT_TAG release-1.8.1
12+
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
13+
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
14+
CONFIGURE_COMMAND ""
15+
BUILD_COMMAND ""
16+
INSTALL_COMMAND ""
17+
TEST_COMMAND ""
18+
)

cmake/GTestConfig.cmake

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
set(__GTEST_DOWNLOAD ${CMAKE_BINARY_DIR}/googletest-download)
2+
file(MAKE_DIRECTORY ${__GTEST_DOWNLOAD})
3+
if (EXISTS ${__GTEST_DOWNLOAD})
4+
5+
option(INSTALL_GMOCK "Install Googletest's GMock?" OFF)
6+
option(INSTALL_GTEST "Install Googletest's GTest?" OFF)
7+
8+
message(STATUS "Generating GoogleTest CMakeLists.txt")
9+
configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in ${__GTEST_DOWNLOAD}/CMakeLists.txt)
10+
11+
message(STATUS "Setup build for GoogleTest")
12+
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
13+
WORKING_DIRECTORY "${__GTEST_DOWNLOAD}" )
14+
15+
message(STATUS "Building GoogleTest")
16+
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
17+
WORKING_DIRECTORY "${__GTEST_DOWNLOAD}" )
18+
19+
# Prevent GoogleTest from overriding our compiler/linker options
20+
# when building with Visual Studio
21+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
22+
23+
# Add googletest directly to our build. This adds
24+
# the following targets: gtest, gtest_main, gmock
25+
# and gmock_main
26+
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
27+
"${CMAKE_BINARY_DIR}/googletest-build")
28+
29+
# The gtest/gmock targets carry header search path
30+
# dependencies automatically when using CMake 2.8.11 or
31+
# later. Otherwise we have to add them here ourselves.
32+
if(CMAKE_VERSION VERSION_LESS 2.8.11)
33+
message(STATUS "GoogleTest include directory ${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)")
34+
include_directories("${gtest_SOURCE_DIR}/include"
35+
"${gmock_SOURCE_DIR}/include")
36+
endif()
37+
38+
add_library(GTest::GTest ALIAS gtest)
39+
add_library(GTest::gtest_main ALIAS gtest_main)
40+
41+
add_library(GMock::GMock ALIAS gmock)
42+
add_library(GMock::gmock_main ALIAS gmock_main)
43+
44+
else()
45+
message(STATUS "Failed to create GoogleTest download directory")
46+
endif()

0 commit comments

Comments
 (0)