build REFACTOR put all checks into main cmake list
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1c2d0ae..2aaf665 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -223,6 +223,21 @@
 #
 # checks
 #
+if(ENABLE_VALGRIND_TESTS AND ENABLE_STATIC)
+    message(WARNING "Can't run C valgrind tests on a static build")
+    set(ENABLE_VALGRIND_TESTS OFF)
+endif()
+
+if(ENABLE_VALGRIND_TESTS)
+    find_program(VALGRIND_FOUND valgrind)
+    if(NOT VALGRIND_FOUND)
+        message(WARNING "valgrind executable not found! Disabling memory leaks tests.")
+        set(ENABLE_VALGRIND_TESTS OFF)
+    else()
+        set(ENABLE_BUILD_TESTS ON)
+    endif()
+endif()
+
 if(ENABLE_BUILD_TESTS)
     find_package(CMocka 1.0.0)
     if(NOT CMOCKA_FOUND)
@@ -324,10 +339,6 @@
 endif()
 
 # tests
-if(ENABLE_VALGRIND_TESTS)
-    set(ENABLE_BUILD_TESTS ON)
-endif()
-
 if(ENABLE_BUILD_TESTS)
     enable_testing()
     add_subdirectory(tests)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7516a90..f66b8be 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,12 +1,6 @@
 # Correct RPATH usage on OS X
 set(CMAKE_MACOSX_RPATH TRUE)
 
-if(ENABLE_STATIC AND ENABLE_VALGRIND_TESTS)
-    message(WARNING "Can't run C valgrind tests on a static build")
-else()
-    find_program(VALGRIND_FOUND valgrind)
-endif()
-
 configure_file("${PROJECT_SOURCE_DIR}/tests/tests_config.h.in" "${PROJECT_BINARY_DIR}/tests/tests_config.h" ESCAPE_QUOTES @ONLY)
 include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR})
 include_directories(${PROJECT_BINARY_DIR}/tests/)
@@ -34,14 +28,9 @@
     set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "MALLOC_CHECK_=3")
 
     if(ENABLE_VALGRIND_TESTS)
-        if(VALGRIND_FOUND)
-            add_test(${TEST_NAME}_valgrind valgrind --leak-check=full --show-leak-kinds=all --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp --error-exitcode=1
-               ${CMAKE_BINARY_DIR}/tests/${TEST_NAME})
-        else(VALGRIND_FOUND)
-            message(WARNING "valgrind executable not found! Disabling memory leaks tests.")
-        endif(VALGRIND_FOUND)
-    endif(ENABLE_VALGRIND_TESTS)
-endfunction(ly_add_utest)
+        add_test(${TEST_NAME}_valgrind valgrind --leak-check=full --show-leak-kinds=all --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp --error-exitcode=1 ${CMAKE_BINARY_DIR}/tests/${TEST_NAME})
+    endif()
+endfunction()
 
 add_subdirectory(style)
 add_subdirectory(plugins)