Skip to content

Commit

Permalink
Issue #10 - Improved linking to googletest using find_package. Did so…
Browse files Browse the repository at this point in the history
…me clean up.
  • Loading branch information
vldtecno committed Dec 22, 2017
1 parent 8bcf74d commit 325889e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 50 deletions.
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ option(BUILD_EXAMPLES "Builds the examples" OFF)
add_subdirectory(PTN_Engine)

if(BUILD_TESTS)
add_subdirectory(Tests/WhiteBoxTests)
add_subdirectory(Tests/BlackBoxTests)
find_path(GTEST_ROOT PATH ENV${GTEST_ROOT} NO_DEFAULT_PATH)
enable_testing()
find_package(GTest REQUIRED)
add_subdirectory(Tests/WhiteBoxTests)
add_subdirectory(Tests/BlackBoxTests)
endif(BUILD_TESTS)

if(BUILD_EXAMPLES)
add_subdirectory(Examples)
add_subdirectory(Examples)
endif(BUILD_EXAMPLES)

30 changes: 7 additions & 23 deletions Tests/BlackBoxTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,27 @@
# limitations under the License.

cmake_minimum_required (VERSION 3.8)

find_path(GOOGLE_TEST_INCLUDE_DIR google_test)
find_path(GOOGLE_TEST_BUILD_DIR google_test_build)

enable_testing()
set(PROJECT_TEST_NAME &{PROJECT_NAME_STR}_test)

include_directories(
${INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/Tests/BlackBoxTests
${GOOGLE_TEST_INCLUDE_DIR}
${GTEST_INCLUDE_DIRS}
)

file( GLOB_RECURSE BlackBoxTest_SRC
"*.h"
"*.cpp"
)

if(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "GCC detected")
link_directories(${GOOGLE_TEST_BUILD_DIR}/googlemock/gtest)
endif(CMAKE_COMPILER_IS_GNUCXX)

if(MSVC)
message(STATUS "MSVC detected")
link_directories(${GOOGLE_TEST_BUILD_DIR}/googletest)
link_directories(${GOOGLE_TEST_BUILD_DIR}/googlemock)
link_directories(${GOOGLE_TEST_BUILD_DIR}/googlemock/gtest)
endif(MSVC)

add_executable (BlackBoxTestDynamic ${BlackBoxTest_SRC})
target_link_libraries(BlackBoxTestDynamic PUBLIC gtest gtest_main)
target_link_libraries(BlackBoxTestDynamic PUBLIC PTN_EngineDynamic)
target_link_libraries(BlackBoxTestDynamic PUBLIC
${GTEST_BOTH_LIBRARIES}
PTN_EngineDynamic)

add_executable (BlackBoxTestStatic ${BlackBoxTest_SRC})
target_link_libraries(BlackBoxTestStatic PUBLIC gtest gtest_main)
target_link_libraries(BlackBoxTestStatic PUBLIC PTN_EngineStatic)
target_link_libraries(BlackBoxTestStatic PUBLIC
${GTEST_BOTH_LIBRARIES}
PTN_EngineStatic)



Expand Down
32 changes: 8 additions & 24 deletions Tests/WhiteBoxTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,30 @@

cmake_minimum_required (VERSION 3.8)

find_path(GOOGLE_TEST_INCLUDE_DIR google_test)
find_path(GOOGLE_TEST_BUILD_DIR google_test_build)

add_library(google_test SHARED IMPORTED)

enable_testing()
set(PROJECT_TEST_NAME &{PROJECT_NAME_STR}_test)

include_directories(
${INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/Tests/WhiteBoxTests
${PROJECT_SOURCE_DIR}/PTN_Engine
${GOOGLE_TEST_INCLUDE_DIR}
${GTEST_INCLUDE_DIRS}
)

file( GLOB_RECURSE Test_SRC
"*.h"
"*.cpp"
)

if(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "GCC detected")
link_directories(${GOOGLE_TEST_BUILD_DIR}/googlemock/gtest)
endif(CMAKE_COMPILER_IS_GNUCXX)

if(MSVC)
message(STATUS "MSVC detected")
link_directories(${GOOGLE_TEST_BUILD_DIR}/googletest)
link_directories(${GOOGLE_TEST_BUILD_DIR}/googlemock)
link_directories(${GOOGLE_TEST_BUILD_DIR}/googlemock/gtest)
endif(MSVC)

add_executable (WhiteBoxTestStatic ${Test_SRC})
if(MSVC)
target_compile_definitions(WhiteBoxTestStatic PUBLIC GTEST_LINKED_AS_SHARED_LIBRARY)
endif(MSVC)
target_link_libraries(WhiteBoxTestStatic PUBLIC gtest gtest_main)
target_link_libraries(WhiteBoxTestStatic PUBLIC PTN_EngineStatic)


target_link_libraries(WhiteBoxTestStatic PUBLIC
${GTEST_BOTH_LIBRARIES}
PTN_EngineStatic)

add_executable (WhiteBoxTestDynamic ${Test_SRC})
target_link_libraries(WhiteBoxTestDynamic PUBLIC gtest gtest_main)
target_link_libraries(WhiteBoxTestDynamic PUBLIC PTN_EngineDynamicExpAll)
target_link_libraries(WhiteBoxTestDynamic PUBLIC
${GTEST_BOTH_LIBRARIES}
PTN_EngineDynamicExpAll)

0 comments on commit 325889e

Please sign in to comment.