From 13b5268f808b0f5ab89e65899616d3206d4632a3 Mon Sep 17 00:00:00 2001
From: Justin Carpentier <justin.carpentier@inria.fr>
Date: Fri, 12 Jul 2019 19:49:49 +0200
Subject: [PATCH] cmake/test: change policy - do build TESTs by default

---
 CMakeLists.txt          | 11 ++++++++---
 unittest/CMakeLists.txt | 15 +++++++++++----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1bf4faed..e1a9bd54 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,6 @@ INCLUDE(cmake/test.cmake)
 SET(PROJECT_NAME eigenpy)
 SET(PROJECT_DESCRIPTION "Wrapping Eigen3 -- numpy")
 SET(PROJECT_URL "http://github.com/stack-of-tasks/eigenpy")
-OPTION(INSTALL_DOCUMENTATION "Generate and install the documentation" FALSE)
 
 # Disable -Werror on Unix for now.
 SET(CXX_DISABLE_WERROR True)
@@ -47,11 +46,17 @@ ELSE(WIN32)
   SET(LINK create_symlink)
 ENDIF(WIN32)
 
-
 # ----------------------------------------------------
 # --- OPTIONS  ---------------------------------------
 # ----------------------------------------------------
-OPTION (BUILD_UNIT_TESTS "Build the unitary tests" ON)
+OPTION(INSTALL_DOCUMENTATION "Generate and install the documentation" FALSE)
+OPTION(BUILD_UNIT_TESTS "Build the unitary tests" OFF)
+
+IF(BUILD_UNIT_TESTS)
+  SET(DISABLE_TESTS OFF)
+ELSE(BUILD_UNIT_TESTS)
+  SET(DISABLE_TESTS ON) 
+ENDIF(BUILD_UNIT_TESTS)
 
 FINDPYTHON()
 
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
index 84ce752b..ebdf23b4 100644
--- a/unittest/CMakeLists.txt
+++ b/unittest/CMakeLists.txt
@@ -3,15 +3,20 @@
 # Copyright (c) 2018-2019 INRIA
 #
 
+
 MACRO(ADD_LIB_UNIT_TEST test PKGS)
+  CREATE_CTEST_BUILD_TESTS_TARGET()
+
   IF (BUILD_UNIT_TESTS)
     ADD_LIBRARY(${test} SHARED ${test})
   ELSE (BUILD_UNIT_TESTS)
     ADD_LIBRARY(${test} SHARED EXCLUDE_FROM_ALL ${test})
   ENDIF (BUILD_UNIT_TESTS)
+
   FOREACH(PKG ${PKGS})
     PKG_CONFIG_USE_DEPENDENCY(${test} ${PKG})
   ENDFOREACH(PKG)
+
   TARGET_LINK_LIBRARIES(${test} ${PROJECT_NAME})
   TARGET_LINK_BOOST_PYTHON(${test})
   SET_TARGET_PROPERTIES(${test} PROPERTIES PREFIX "")
@@ -21,11 +26,13 @@ MACRO(ADD_LIB_UNIT_TEST test PKGS)
     SET_TARGET_PROPERTIES(${test} PROPERTIES SUFFIX ".so")
   ENDIF(APPLE)
 
-  ADD_TEST(NAME ${test} COMMAND ${PYTHON_EXECUTABLE} -c "import ${test}")
-  ADD_DEPENDENCIES(check ${test})
-ENDMACRO(ADD_LIB_UNIT_TEST)
+  ADD_TEST(${test} COMMAND ${PYTHON_EXECUTABLE} -c "import ${test}")
 
-ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
+  ADD_DEPENDENCIES(build_tests ${test})
+  IF(DISABLE_TESTS)
+    SET_TESTS_PROPERTIES(${test} PROPERTIES DEPENDS ctest_build_tests)
+  ENDIF(DISABLE_TESTS)
+ENDMACRO(ADD_LIB_UNIT_TEST)
 
 ADD_LIB_UNIT_TEST(matrix "eigen3")
 ADD_LIB_UNIT_TEST(geometry "eigen3")
-- 
GitLab