Skip to content

Commit

Permalink
Merge pull request #4 from chuckatkins/add-googletest
Browse files Browse the repository at this point in the history
Add initial third party library support with the google test framework
  • Loading branch information
Chuck Atkins authored Dec 8, 2016
2 parents 6b154e5 + 1d2848f commit 03af3d6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 15 deletions.
31 changes: 16 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#------------------------------------------------------------------------------#

cmake_minimum_required(VERSION 3.7)
project(ADIOS VERSION 2.0.a)
project(ADIOS VERSION 2.0.0)

#------------------------------------------------------------------------------#
# Some boilerplate to setup nice output directories
Expand Down Expand Up @@ -50,11 +50,24 @@ if(ADIOS_ENABLE_PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

#------------------------------------------------------------------------------#
# Third party libraries
#------------------------------------------------------------------------------#
include(CTest)
add_subdirectory(thirdparty)

#------------------------------------------------------------------------------#
# Main library source
#------------------------------------------------------------------------------#
add_subdirectory(source)

#------------------------------------------------------------------------------#
# Installation
#------------------------------------------------------------------------------#
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
#------------------------------------------------------------------------------#
# Examples
#------------------------------------------------------------------------------#
Expand All @@ -66,20 +79,8 @@ endif()
#------------------------------------------------------------------------------#
# Testing
#------------------------------------------------------------------------------#
include(CTest)
option(ADIOS_ENABLE_TESTING "Enable ADIOS Testing" ON)
set(ENABLE_TESTING ${ADIOS_ENABLE_TESTING} CACHE INTERNAL "" FORCE)
mark_as_advanced(ENABLE_TESTING)
if(ADIOS_ENABLE_TESTING)
# We have to wait until after the library is defined to enable testing
if(BUILD_TESTING)
enable_testing()
add_subdirectory(testing)
endif()

#------------------------------------------------------------------------------#
# Installation
#------------------------------------------------------------------------------#
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)

28 changes: 28 additions & 0 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
set(ADIOS_THIRDPARTY_DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/downloads
CACHE PATH "Download directory for third party dependencies")

include(ExternalProject)

# Boilerplate settings for a common external project infrastructure
set(EP_ARGS
DOWNLOAD_DIR ${ADIOS_THIRDPARTY_DOWNLOAD_DIR}
PREFIX .
SOURCE_DIR source
BINARY_DIR build
STAMP_DIR stamp
INSTALL_DIR install)

# Use Google Test for a unit testing framework
cmake_dependent_option(ADIOS_USE_SYSTEM_GOOGLETEST
"Use a system-supplied Google Test framework" OFF
"BUILD_TESTING" OFF)
if(BUILD_TESTING)
if(NOT ADIOS_USE_SYSTEM_GOOGLETEST)
add_subdirectory(googletest)
endif()
find_package(GTest REQUIRED)
if(NOT ADIOS_USE_SYSTEM_GOOGLETEST)
add_dependencies(GTest::GTest googletest)
add_dependencies(GTest::Main googletest)
endif()
endif()
36 changes: 36 additions & 0 deletions thirdparty/googletest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

ExternalProject_Add(googletest
URL https://github.com/google/googletest/archive/release-1.8.0.zip
URL_MD5 adfafc8512ab65fd3cf7955ef0100ff5
${EP_ARGS}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/install
-DCMAKE_POLICY_DEFAULT_CMP0048=OLD
-DCMAKE_POLICY_DEFAULT_CMP0063=NEW
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DBUILD_GMOCK=OFF
-DBUILD_GTEST=ON
-Dgtest_build_samples=OFF
-Dgtest_build_tests=OFF
-Dgtest_hide_internal_symbols=ON
-Dgtest_disable_pthreads=OFF
-Dgtest_force_shared_crt=OFF)

function(get_libfile var name)
if(BUILD_SHARED_LIBS)
set(${var} ${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX} PARENT_SCOPE)
else()
set(${var} ${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX} PARENT_SCOPE)
endif()
endfunction()

get_libfile(GTEST_LIBRARY gtest)
get_libfile(GTEST_MAIN_LIBRARY gtest_main)
set(GTEST_ROOT ${CMAKE_CURRENT_BINARY_DIR}/install)
set(GTEST_INCLUDE_DIR ${GTEST_ROOT}/include
CACHE PATH "")
set(GTEST_LIBRARY ${GTEST_ROOT}/lib/${GTEST_LIBRARY}
CACHE FILEPATH "")
set(GTEST_MAIN_LIBRARY ${GTEST_ROOT}/lib/${GTEST_MAIN_LIBRARY}
CACHE FILEPATH "")

0 comments on commit 03af3d6

Please sign in to comment.