Skip to content

Commit

Permalink
Clean up the Find Google Test and Xorg GTest logic, put them in their…
Browse files Browse the repository at this point in the history
… own cmake files

behind their own functions. Make it so that all users can see xorg-gtest and not just the users
in tests/
  • Loading branch information
Sam Spilsbury committed Feb 12, 2013
1 parent 5619809 commit 37e24f6
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 71 deletions.
46 changes: 19 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ include (CompizPackage)
# GSettings schema recompilation
include (CompizGSettings)

# Google Test and Xorg-GTest
include (GoogleTest)
include (XorgGTest)

include (cmake/base.cmake)
# Check if specific function is present in library.
include (CheckFunctionExists)
Expand Down Expand Up @@ -137,45 +141,33 @@ install (

if (COMPIZ_BUILD_TESTING)

# Build Google Test and make its headers known
find_package (GTest)
find_package (GoogleTest)

if (GOOGLE_TEST_AND_MOCK_FOUND)

if (NOT GTEST_FOUND)
build_google_test_locally (${CMAKE_BINARY_DIR}/__gtest)

# Check for google test and build it locally
set (GTEST_ROOT_DIR
"/usr/src/gtest" # Default value, adjustable by user with e.g., ccmake
CACHE
PATH
"Path to Google Test srcs"
FORCE
)
if (BUILD_XORG_GTEST)

find_path (GTEST_INCLUDE_DIR gtest/gtest.h)
find_package (XorgGTest)

if (GTEST_INCLUDE_DIR)
add_subdirectory (${GTEST_ROOT_DIR}
gtest)
endif (GTEST_INCLUDE_DIR)
if (XORG_GTEST_FOUND)

set (GTEST_BOTH_LIBRARIES gtest gtest_main)
set (GTEST_FOUND TRUE)
build_xorg_gtest_locally (${CMAKE_BINARY_DIR}/__xorg_gtest)

endif (NOT GTEST_FOUND)
else (XORG_GTEST_FOUND)

find_library (GMOCK_LIBRARY gmock)
find_library (GMOCK_MAIN_LIBRARY gmock_main)
set (BUILD_XORG_GTEST FALSE)

if (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY OR NOT GTEST_FOUND)
endif (XORG_GTEST_FOUND)

message ("Google Mock and Google Test not found - cannot build tests!")
set (COMPIZ_BUILD_TESTING OFF CACHE BOOL "" FORCE)
endif (BUILD_XORG_GTEST)

else (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY OR NOT GTEST_FOUND)
else (GOOGLE_TEST_AND_MOCK_FOUND)

include_directories (${GTEST_INCLUDE_DIRS})
set (COMPIZ_BUILD_TESTING OFF CACHE "" FORCE)

endif (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY OR NOT GTEST_FOUND)
endif (GOOGLE_TEST_AND_MOCK_FOUND)

endif (COMPIZ_BUILD_TESTING)

Expand Down
1 change: 1 addition & 0 deletions cmake/CompizCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ option (COMPIZ_BUILD_WITH_RPATH "Leave as ON unless building packages" ON)
option (COMPIZ_RUN_LDCONFIG "Leave OFF unless you need to run ldconfig after install")
option (COMPIZ_PACKAGING_ENABLED "Enable to manually set prefix, exec_prefix, libdir, includedir, datadir" OFF)
option (COMPIZ_BUILD_TESTING "Build Unit Tests" ON)
option (BUILD_XORG_GTEST "Build Xorg GTest integration tests" ON)

set (COMPIZ_DATADIR ${CMAKE_INSTALL_PREFIX}/share)
set (COMPIZ_METADATADIR ${CMAKE_INSTALL_PREFIX}/share/compiz)
Expand Down
46 changes: 46 additions & 0 deletions cmake/FindGoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Find Google Test and Google Mock, either with pkg-config or by
# searching the system install paths. This sets:
#
# GOOGLE_TEST_AND_MOCK_FOUND
# GTEST_INCLUDE_DIR
# GTEST_ROOT_DIR
# GMOCK_LIBRARY
# GMOCK_MAIN_LIBRARY

find_package (GTest)

if (NOT GTEST_FOUND)

# Check for google test and build it locally
set (GTEST_ROOT_DIR
"/usr/src/gtest" # Default value, adjustable by user with e.g., ccmake
CACHE
PATH
"Path to Google Test srcs"
FORCE)

find_path (GTEST_INCLUDE_DIR gtest/gtest.h)

set (GTEST_BOTH_LIBRARIES gtest gtest_main)
set (GTEST_FOUND TRUE)
set (GTEST_LOCAL_BUILD_REQUIRED TRUE)

else (NOT GTEST_FOUND)

set (GTEST_LOCAL_BUILD_REQUIRED FALSE)

endif (NOT GTEST_FOUND)

find_library (GMOCK_LIBRARY gmock)
find_library (GMOCK_MAIN_LIBRARY gmock_main)

if (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY OR NOT GTEST_FOUND)

message ("Google Mock and Google Test not found - cannot build tests!")
set (GOOGLE_TEST_AND_MOCK_FOUND OFF CACHE BOOL "" FORCE)

else (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY OR NOT GTEST_FOUND)

set (GOOGLE_TEST_AND_MOCK_FOUND ON CACHE BOOL "" FORCE)

endif (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY OR NOT GTEST_FOUND)
39 changes: 39 additions & 0 deletions cmake/FindXorgGTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Find xorg-gtest,with pkg-config. This sets:
#
# XORG_GTEST_FOUND
# XORG_SERVER_INCLUDE_XORG_GTEST
# XORG_SERVER_GTEST_SRC

# xorg-gtest
pkg_check_modules (XORG_SERVER xorg-gtest xorg-server x11 xi)

if (XORG_SERVER_FOUND)

execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=prefix xorg-gtest OUTPUT_VARIABLE _xorg_gtest_prefix)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=includedir xorg-gtest OUTPUT_VARIABLE _xorg_gtest_include_dir)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=sourcedir xorg-gtest OUTPUT_VARIABLE _xorg_gtest_source_dir)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=CPPflags xorg-gtest OUTPUT_VARIABLE _xorg_gtest_cflags)

string (STRIP ${_xorg_gtest_prefix} _xorg_gtest_prefix)
string (STRIP ${_xorg_gtest_include_dir} _xorg_gtest_include_dir)
string (STRIP ${_xorg_gtest_source_dir} _xorg_gtest_source_dir)
string (STRIP ${_xorg_gtest_cflags} _xorg_gtest_cflags)

set (XORG_SERVER_GTEST_INCLUDES ${XORG_SERVER_INCLUDE_DIRS})
set (XORG_SERVER_GTEST_LIBRARY_DIRS ${XORG_SERVER_LIBRARIES})
set (XORG_SERVER_GTEST_LIBRARIES} ${XORG_SERVER_LIBRARIES})
set (XORG_SERVER_INCLUDE_XORG_GTEST ${_xorg_gtest_include_dir} CACHE PATH "Path to Xorg GTest Headers")
set (XORG_SERVER_GTEST_SRC ${_xorg_gtest_source_dir} CACHE PATH "Path to Xorg GTest Sources")
set (XORG_SERVER_GTEST_CFLAGS ${_xorg_gtest_cflags})
set (XORG_SERVER_GTEST_ROOT ${CMAKE_SOURCE_DIR}/tests/xorg-gtest CACHE PATH "Path to Xorg GTest CMake sources")
set (COMPIZ_XORG_SYSTEM_TEST_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/tests/xorg-gtest/include CACHE PATH "Path to Compiz Xorg GTest Headers")

message (STATUS "Found xorg-gtest sources at " ${XORG_SERVER_GTEST_SRC})
set (XORG_GTEST_FOUND ON)

else (XORG_SERVER_FOUND)

message (WARNING "Could not found xorg-gtest, can't build xserver tests")
set (XORG_GTEST_FOUND OFF)

endif (XORG_SERVER_FOUND)
20 changes: 20 additions & 0 deletions cmake/GoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# GoogleTest.cmake
# build_google_test_locally (dir) takes a subdirectory
# and builds Google Test in there locally if required

function (build_google_test_locally build_directory)

if (GOOGLE_TEST_AND_MOCK_FOUND)

if (GTEST_LOCAL_BUILD_REQUIRED)

add_subdirectory (${GTEST_ROOT_DIR}
${build_directory})

endif (GTEST_LOCAL_BUILD_REQUIRED)

include_directories (${GTEST_INCLUDE_DIRS})

endif (GOOGLE_TEST_AND_MOCK_FOUND)

endfunction ()
14 changes: 14 additions & 0 deletions cmake/XorgGTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# XorgGTest.cmake
#
# build_xorg_gtest_locally (dir) specifies a subdirectory to
# build xorg-gtest in locally

function (build_xorg_gtest_locally build_directory)

if (XORG_GTEST_FOUND)

add_subdirectory (${XORG_SERVER_GTEST_ROOT} ${build_directory})

endif (XORG_GTEST_FOUND)

endfunction ()
32 changes: 2 additions & 30 deletions tests/system/xorg-gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
include (FindPkgConfig)
if (BUILD_XORG_GTEST)

pkg_check_modules (XORG_SERVER xorg-gtest xorg-server x11)

option (BUILD_XORG_GTEST "Build Xorg GTest integration tests" OFF)

if (XORG_SERVER_FOUND AND BUILD_XORG_GTEST)

execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=prefix xorg-gtest OUTPUT_VARIABLE _xorg_gtest_prefix)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=includedir xorg-gtest OUTPUT_VARIABLE _xorg_gtest_include_dir)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=sourcedir xorg-gtest OUTPUT_VARIABLE _xorg_gtest_source_dir)
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=CPPflags xorg-gtest OUTPUT_VARIABLE _xorg_gtest_cflags)

string (STRIP ${_xorg_gtest_prefix} _xorg_gtest_prefix)
string (STRIP ${_xorg_gtest_include_dir} _xorg_gtest_include_dir)
string (STRIP ${_xorg_gtest_source_dir} _xorg_gtest_source_dir)
string (STRIP ${_xorg_gtest_cflags} _xorg_gtest_cflags)

set (XORG_SERVER_INCLUDE_XORG_GTEST ${_xorg_gtest_include_dir} CACHE PATH "Path to Xorg GTest Headers")
set (XORG_SERVER_GTEST_SRC ${_xorg_gtest_source_dir} CACHE PATH "Path to Xorg GTest Sources")
set (COMPIZ_XORG_SYSTEM_TEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE PATH "Path to Compiz Xorg GTest Headers")

message (STATUS "Found xorg-gtest sources at " ${XORG_SERVER_GTEST_SRC})

add_subdirectory (src)
add_subdirectory (tests)

else (XORG_SERVER_FOUND AND BUILD_XORG_GTEST)

message (WARNING "Could not found xorg-gtest, not building system tests")
set (BUILD_XORG_GTEST OFF)

endif (XORG_SERVER_FOUND AND BUILD_XORG_GTEST)
endif (BUILD_XORG_GTEST)
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
set (COMPIZ_LD_LIBRARY_PATH ${CMAKE_BINARY_DIR}/src CACHE STRING "" FORCE)
set (COMPIZ_BINARY ${CMAKE_BINARY_DIR}/src/compiz CACHE STRING "" FORCE)

configure_file (${CMAKE_CURRENT_SOURCE_DIR}/compiz-xorg-gtest-config.h.in
${CMAKE_CURRENT_BINARY_DIR}/compiz-xorg-gtest-config.h
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/compiz-xorg-gtest-config.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/compiz-xorg-gtest-config.h
@ONLY)

add_definitions (${_xorg_gtest_cflags})

include_directories (${COMPIZ_XORG_SYSTEM_TEST_INCLUDE_DIR}
${XORG_SERVER_INCLUDE_DIRS}
${GTEST_INCLUDE_DIRS}
${XORG_SERVER_INCLUDE_XORG_GTEST}
${XORG_SERVER_GTEST_SRC}
${CMAKE_CURRENT_BINARY_DIR})
include_directories (${XORG_SERVER_INCLUDE_XORG_GTEST}
${XORG_SERVER_GTEST_INCLUDES}
${COMPIZ_XORG_SYSTEM_TEST_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/src)

link_directories (${XORG_SERVER_LIBRARY_DIRS})

# This actually includes xorg-gtest-all and the defines
add_definitions (${XORG_SERVER_GTEST_CFLAGS})

set (_xorg_gtest_all_srcs
${XORG_SERVER_GTEST_SRC}/src/xorg-gtest-all.cpp)

Expand All @@ -30,17 +27,17 @@ add_library (xorg_gtest_main STATIC
${_xorg_gtest_main_srcs})

add_library (compiz_xorg_gtest_system_test STATIC
${CMAKE_CURRENT_SOURCE_DIR}/compiz-xorg-gtest.cpp)
${CMAKE_CURRENT_SOURCE_DIR}/src/compiz-xorg-gtest.cpp)

target_link_libraries (xorg_gtest_all
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${XORG_SERVER_LIBRARIES})
${XORG_SERVER_GTEST_LIBRARIES})

target_link_libraries (xorg_gtest_main
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${XORG_SERVER_LIBRARIES})
${XORG_SERVER_GTEST_LIBRARIES})

target_link_libraries (compiz_xorg_gtest_system_test
xorg_gtest_all
Expand Down
Empty file.
File renamed without changes.

0 comments on commit 37e24f6

Please sign in to comment.