Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

Commit

Permalink
Automate Google Test dependency resolution using CMake
Browse files Browse the repository at this point in the history
It's more portable than Bash commands.
  • Loading branch information
Ortham committed Mar 21, 2016
1 parent 394b613 commit 3c4d99a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
14 changes: 3 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,11 @@ addons:
before_script:
# Use GCC 5.
- if [ "$CXX" = "g++" ]; then export CXX="g++-5" CC="gcc-5"; fi
# Build Google Test
- cd ..
- wget https://github.com/google/googletest/archive/release-1.7.0.tar.gz -O - | tar -xz
- cd googletest-release-1.7.0
- cmake .
- make
# Move back into the cloned LOOT repo path.
- cd $TRAVIS_BUILD_DIR
- mkdir build && cd build
# Fetch plugins to test with.
- wget https://github.com/WrinklyNinja/testing-plugins/archive/master.tar.gz -O - | tar -xz
- mv testing-plugins-master/* ./
- wget https://github.com/WrinklyNinja/testing-plugins/archive/1.0.0.tar.gz -O - | tar -xz
- mv testing-plugins-1.0.0/* ./
# Travis machines are 64 bit, and the dependencies use dynamic linking.
- cmake .. -DPROJECT_STATIC_RUNTIME=OFF -DGTEST_ROOT=../googletest-release-1.7.0
- cmake .. -DPROJECT_STATIC_RUNTIME=OFF

script: make tests && ./tests
20 changes: 16 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@

cmake_minimum_required(VERSION 2.8)
project(libespm)
include(ExternalProject)

option(PROJECT_STATIC_RUNTIME "Build with static runtime libs (/MT)" ON)
if (MSVC)
set(BUILD_SUBDIRECTORY $<CONFIGURATION>)
else()
set(BUILD_SUBDIRECTORY "")
endif()

set (Boost_USE_STATIC_LIBS ${PROJECT_STATIC_RUNTIME})
set (Boost_USE_MULTITHREADED ON)
set (Boost_USE_STATIC_RUNTIME ${PROJECT_STATIC_RUNTIME})

find_package(GTest REQUIRED)
find_package(Boost REQUIRED COMPONENTS iostreams filesystem system locale)

ExternalProject_Add(GTest
PREFIX "external"
URL "https://github.com/google/googletest/archive/release-1.7.0.tar.gz"
INSTALL_COMMAND "")
ExternalProject_Get_Property(GTest SOURCE_DIR BINARY_DIR)
set (GTEST_INCLUDE_DIRS "${SOURCE_DIR}/include")
set (GTEST_LIBRARIES "${BINARY_DIR}/${BUILD_SUBDIRECTORY}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}")

set(PROJECT_HEADERS "${CMAKE_SOURCE_DIR}/include/libespm/FormId.h"
"${CMAKE_SOURCE_DIR}/include/libespm/GameId.h"
"${CMAKE_SOURCE_DIR}/include/libespm/Group.h"
Expand Down Expand Up @@ -67,11 +80,10 @@ else (MSVC)
ENDIF ()
endif ()



##############################
# Define Targets
##############################

add_executable (tests ${TESTER_SRC} ${PROJECT_HEADERS} ${TESTER_HEADERS})
target_link_libraries (tests ${GTEST_BOTH_LIBRARIES} ${Boost_LIBRARIES} ${PROJECT_LIBRARIES})
add_dependencies (tests GTest)
target_link_libraries (tests ${GTEST_LIBRARIES} ${Boost_LIBRARIES} ${PROJECT_LIBRARIES})

0 comments on commit 3c4d99a

Please sign in to comment.