cmake: Build unit tests only if -DENABLE_UNIT_TESTING=ON.
authorAina Niemetz <aina.niemetz@gmail.com>
Tue, 21 Aug 2018 01:39:10 +0000 (18:39 -0700)
committerMathias Preiner <mathias.preiner@gmail.com>
Sat, 22 Sep 2018 23:30:59 +0000 (16:30 -0700)
CMakeLists.txt
test/unit/CMakeLists.txt

index 1ed87951df0a34cbc34b0c7478d5987bd99fe78d..2898f9dffa3ec206005d31d74c6875d8f8dae7df 100644 (file)
@@ -225,6 +225,11 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Competition")
   #TODO
 endif()
 
+#-----------------------------------------------------------------------------#
+# Enable the ctest testing framework
+
+enable_testing()
+
 #-----------------------------------------------------------------------------#
 
 if(ENABLE_ASAN)
@@ -293,7 +298,6 @@ endif()
 
 if(ENABLE_UNIT_TESTING)
        find_package(CxxTest REQUIRED)
-       enable_testing()
   # Force shared libs for unit tests, static libs with unit tests are not
   # working right now.
   set(ENABLE_SHARED ON)
index b29c705c14668765324c788481b98b2fc07da699..15ac63dd2c3c5339668bc7739760cc54ae46a85f 100644 (file)
@@ -1,40 +1,42 @@
-include_directories(.)
-include_directories(${PROJECT_SOURCE_DIR}/src)
-include_directories(${PROJECT_SOURCE_DIR}/src/include)
-include_directories(${CMAKE_BINARY_DIR}/src)
+if(ENABLE_UNIT_TESTING)
+  include_directories(.)
+  include_directories(${PROJECT_SOURCE_DIR}/src)
+  include_directories(${PROJECT_SOURCE_DIR}/src/include)
+  include_directories(${CMAKE_BINARY_DIR}/src)
 
-set(CVC4_CXXTEST_FLAGS_BLACK
-  -D__BUILDING_CVC4LIB_UNIT_TEST -D__BUILDING_CVC4PARSERLIB_UNIT_TEST
-       -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS)
-set(CVC4_CXXTEST_FLAGS_WHITE -fno-access-control ${CVC4_CXXTEST_FLAGS_BLACK})
+  set(CVC4_CXXTEST_FLAGS_BLACK
+    -D__BUILDING_CVC4LIB_UNIT_TEST -D__BUILDING_CVC4PARSERLIB_UNIT_TEST
+    -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS)
+  set(CVC4_CXXTEST_FLAGS_WHITE -fno-access-control ${CVC4_CXXTEST_FLAGS_BLACK})
 
-macro(cvc4_add_unit_test is_white name)
-  cxxtest_add_test(${name} ${name}.cpp ${CMAKE_CURRENT_LIST_DIR}/${name}.h)
-  set_tests_properties(${name} PROPERTIES LABELS "unit")
-  target_link_libraries(${name} main)
-  target_compile_definitions(${name} PRIVATE ${CVC4_CXXTEST_FLAGS_BLACK})
-  if(${is_white})
-    target_compile_options(${name} PRIVATE -fno-access-control)
-  endif()
-  # Disable the Wsuggest-override warnings for the unit tests. CxxTest generates
-  # code that does not properly add the override keyword to runTest().
-  target_compile_options(${name} PRIVATE -Wno-suggest-override)
-endmacro()
+  macro(cvc4_add_unit_test is_white name)
+    cxxtest_add_test(${name} ${name}.cpp ${CMAKE_CURRENT_LIST_DIR}/${name}.h)
+    set_tests_properties(${name} PROPERTIES LABELS "unit")
+    target_link_libraries(${name} main)
+    target_compile_definitions(${name} PRIVATE ${CVC4_CXXTEST_FLAGS_BLACK})
+    if(${is_white})
+      target_compile_options(${name} PRIVATE -fno-access-control)
+    endif()
+    # Disable the Wsuggest-override warnings for the unit tests. CxxTest generates
+    # code that does not properly add the override keyword to runTest().
+    target_compile_options(${name} PRIVATE -Wno-suggest-override)
+  endmacro()
 
-macro(cvc4_add_unit_test_black name)
-  cvc4_add_unit_test(FALSE ${name})
-endmacro()
-macro(cvc4_add_unit_test_white name)
-  cvc4_add_unit_test(TRUE ${name})
-endmacro()
+  macro(cvc4_add_unit_test_black name)
+    cvc4_add_unit_test(FALSE ${name})
+  endmacro()
+  macro(cvc4_add_unit_test_white name)
+    cvc4_add_unit_test(TRUE ${name})
+  endmacro()
 
-add_subdirectory(base)
-add_subdirectory(context)
-add_subdirectory(expr)
-add_subdirectory(main)
-add_subdirectory(parser)
-add_subdirectory(prop)
-add_subdirectory(theory)
-add_subdirectory(util)
+  add_subdirectory(base)
+  add_subdirectory(context)
+  add_subdirectory(expr)
+  add_subdirectory(main)
+  add_subdirectory(parser)
+  add_subdirectory(prop)
+  add_subdirectory(theory)
+  add_subdirectory(util)
 
-add_custom_target(units COMMAND ctest -L "unit")
+  add_custom_target(units COMMAND ctest -L "unit")
+endif()