Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
38efa38f
Commit
38efa38f
authored
Jan 05, 2010
by
zhanyong.wan
Browse files
Uses FindThreads to set the proper link flag when using threads (by Manuel Klimek).
parent
1d6df4be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
35 deletions
+27
-35
CMakeLists.txt
CMakeLists.txt
+27
-35
No files found.
CMakeLists.txt
View file @
38efa38f
...
@@ -17,7 +17,8 @@
...
@@ -17,7 +17,8 @@
# CMake files in this project can refer to the root source directory
# CMake files in this project can refer to the root source directory
# as ${gtest_SOURCE_DIR} and to the root binary directory as
# as ${gtest_SOURCE_DIR} and to the root binary directory as
# ${gtest_BINARY_DIR}.
# ${gtest_BINARY_DIR}.
project
(
gtest CXX
)
# Language "C" is required for find_package(Threads).
project
(
gtest CXX C
)
cmake_minimum_required
(
VERSION 2.8
)
cmake_minimum_required
(
VERSION 2.8
)
# Where gtest's .h files can be found.
# Where gtest's .h files can be found.
...
@@ -114,25 +115,38 @@ option(build_all_gtest_tests "Build all of gtest's own tests." OFF)
...
@@ -114,25 +115,38 @@ option(build_all_gtest_tests "Build all of gtest's own tests." OFF)
enable_testing
()
enable_testing
()
# Sets PYTHONINTERP_FOUND and PYTHON_EXECUTABLE.
# Sets PYTHONINTERP_FOUND and PYTHON_EXECUTABLE.
in
clude
(
Find
PythonInterp
)
f
in
d_package
(
PythonInterp
)
############################################################
############################################################
# C++ tests built with standard compiler flags.
# C++ tests built with standard compiler flags.
# cxx_test
(name
lib srcs...)
# cxx_test
_with_flags(name cxx_flags
lib
s
srcs...)
#
#
# creates a named test target that depends on the given lib and is
# creates a named C++ test that depends on the given libs and is built
# built from the given source files. test/name.cc is implicitly
# from the given source files with the given compiler flags.
# included in the source file list.
function
(
cxx_test_with_flags name cxx_flags libs
)
function
(
cxx_test name lib
)
add_executable
(
${
name
}
${
ARGN
}
)
add_executable
(
${
name
}
test/
${
name
}
.cc
${
ARGN
}
)
set_target_properties
(
${
name
}
set_target_properties
(
${
name
}
PROPERTIES
PROPERTIES
COMPILE_FLAGS
"
${
cxx_default
}
"
)
COMPILE_FLAGS
"
${
cxx_flags
}
"
)
target_link_libraries
(
${
name
}
${
lib
}
)
# To support mixing linking in static and dynamic libraries, link each
# library in with an extra call to target_link_libraries.
foreach
(
lib
"
${
libs
}
"
)
target_link_libraries
(
${
name
}
${
lib
}
)
endforeach
()
add_test
(
${
name
}
${
name
}
)
add_test
(
${
name
}
${
name
}
)
endfunction
()
endfunction
()
# cxx_test(name libs srcs...)
#
# creates a named test target that depends on the given libs and is
# built from the given source files. Unlike cxx_test_with_flags,
# test/name.cc is already implicitly included in the source file list.
function
(
cxx_test name libs
)
cxx_test_with_flags
(
"
${
name
}
"
"
${
cxx_default
}
"
"
${
libs
}
"
"test/
${
name
}
.cc"
${
ARGN
}
)
endfunction
()
cxx_test
(
gtest_unittest gtest_main
)
cxx_test
(
gtest_unittest gtest_main
)
if
(
${
build_all_gtest_tests
}
)
if
(
${
build_all_gtest_tests
}
)
...
@@ -163,35 +177,15 @@ endif()
...
@@ -163,35 +177,15 @@ endif()
############################################################
############################################################
# C++ tests built with non-standard compiler flags.
# C++ tests built with non-standard compiler flags.
# TODO(wan@google.com): use FindThreads to set the flags for using threads.
if
(
MSVC
)
if
(
MSVC
)
set
(
cxx_no_exception
"
${
cxx_base
}
-D_HAS_EXCEPTIONS=0"
)
set
(
cxx_no_exception
"
${
cxx_base
}
-D_HAS_EXCEPTIONS=0"
)
set
(
cxx_no_rtti
"
${
cxx_default
}
-GR-"
)
set
(
cxx_no_rtti
"
${
cxx_default
}
-GR-"
)
set
(
cxx_use_threads
"
${
cxx_default
}
"
)
set
(
link_use_threads
""
)
else
()
else
()
set
(
cxx_no_exception
"
${
cxx_base
}
-fno-exceptions"
)
set
(
cxx_no_exception
"
${
cxx_base
}
-fno-exceptions"
)
set
(
cxx_no_rtti
"
${
cxx_default
}
-fno-rtti -DGTEST_HAS_RTTI=0"
)
set
(
cxx_no_rtti
"
${
cxx_default
}
-fno-rtti -DGTEST_HAS_RTTI=0"
)
set
(
cxx_use_threads
"
${
cxx_default
}
-pthread"
)
set
(
link_use_threads
"-pthread"
)
endif
()
endif
()
set
(
cxx_use_own_tuple
"
${
cxx_default
}
-DGTEST_USE_OWN_TR1_TUPLE=1"
)
set
(
cxx_use_own_tuple
"
${
cxx_default
}
-DGTEST_USE_OWN_TR1_TUPLE=1"
)
# cxx_test_with_flags(name cxx_flags lib srcs...)
#
# creates a named C++ test that depends on the given lib and is built
# from the given source files with the given compiler flags. Unlike
# cxx_test(), test/name.cc is NOT implicitly included in the source
# file list.
function
(
cxx_test_with_flags name cxx_flags lib
)
add_executable
(
${
name
}
${
ARGN
}
)
set_target_properties
(
${
name
}
PROPERTIES
COMPILE_FLAGS
"
${
cxx_flags
}
"
)
target_link_libraries
(
${
name
}
${
lib
}
)
add_test
(
${
name
}
${
name
}
)
endfunction
()
if
(
${
build_all_gtest_tests
}
)
if
(
${
build_all_gtest_tests
}
)
cxx_library
(
gtest_no_exception
"
${
cxx_no_exception
}
"
cxx_library
(
gtest_no_exception
"
${
cxx_no_exception
}
"
src/gtest-all.cc
)
src/gtest-all.cc
)
...
@@ -200,11 +194,9 @@ if (${build_all_gtest_tests})
...
@@ -200,11 +194,9 @@ if (${build_all_gtest_tests})
cxx_library
(
gtest_main_use_own_tuple
"
${
cxx_use_own_tuple
}
"
cxx_library
(
gtest_main_use_own_tuple
"
${
cxx_use_own_tuple
}
"
src/gtest-all.cc src/gtest_main.cc
)
src/gtest-all.cc src/gtest_main.cc
)
cxx_test_with_flags
(
gtest-death-test_test
"
${
cxx_use_threads
}
"
find_package
(
Threads
)
# Defines CMAKE_THREAD_LIBS_INIT.
gtest_main test/gtest-death-test_test.cc
)
cxx_test_with_flags
(
gtest-death-test_test
"
${
cxx_default
}
"
set_target_properties
(
gtest-death-test_test
"gtest_main;
${
CMAKE_THREAD_LIBS_INIT
}
"
test/gtest-death-test_test.cc
)
PROPERTIES
LINK_FLAGS
"
${
link_use_threads
}
"
)
cxx_test_with_flags
(
gtest_no_rtti_unittest
"
${
cxx_no_rtti
}
"
cxx_test_with_flags
(
gtest_no_rtti_unittest
"
${
cxx_no_rtti
}
"
gtest_main_no_rtti test/gtest_unittest.cc
)
gtest_main_no_rtti test/gtest_unittest.cc
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment