CMakeLists.txt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # ----------------------------------------------------------------------------
  2. # TESTS
  3. # ----------------------------------------------------------------------------
  4. PROJECT(tests)
  5. # Fix a "bug" in VS11 (MSVC 2012):
  6. if(MSVC)
  7. add_definitions(-D_VARIADIC_MAX=10)
  8. endif(MSVC)
  9. if(NANOFLANN_USE_SYSTEM_GTEST)
  10. find_package(GTest REQUIRED)
  11. else()
  12. # Treat this directory as "system" to ignore pedantic warnings.
  13. if(CMAKE_COMPILER_IS_GNUCXX)
  14. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem gtest-1.8.0/include")
  15. endif()
  16. # Compile gtest from sources:
  17. add_subdirectory(gtest-1.8.0)
  18. INCLUDE_DIRECTORIES("gtest-1.8.0/include/")
  19. endif()
  20. set(EXECUTABLE_OUTPUT_PATH "${${PROJECT_NAME}_BINARY_DIR}")
  21. # Tests based on Google gtest:
  22. # -----------------------------
  23. # If using system library, add C++ flags:
  24. if (UNIX)
  25. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
  26. endif()
  27. # Test project:
  28. ADD_EXECUTABLE(unit_tests test_main.cpp)
  29. set_target_properties(unit_tests PROPERTIES FOLDER "./")
  30. ADD_TEST(unit_tests_build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target unit_tests)
  31. ADD_TEST(unit_tests_run ${EXECUTABLE_OUTPUT_PATH}/unit_tests)
  32. set_tests_properties(unit_tests_run PROPERTIES DEPENDS unit_tests_build)
  33. # Add the required libraries for linking:
  34. if(NANOFLANN_USE_SYSTEM_GTEST)
  35. target_link_libraries(unit_tests GTest::gtest nanoflann)
  36. else()
  37. target_link_libraries(unit_tests mygtest nanoflann)
  38. endif()