Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / samples / CMakeLists.txt
index 1f7bb9f..da00b43 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2018 Intel Corporation
+# Copyright (C) 2018-2019 Intel Corporation
 # SPDX-License-Identifier: Apache-2.0
 #
 
@@ -50,16 +50,6 @@ else ()
     set (LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_DIRECTORY}/lib)
 endif()
 
-# use this flag if you need to throw custom message in case if the IE package is not found.
-if (IE_NOT_FOUND_MESSAGE)
-    find_package(InferenceEngine 1.5 QUIET)
-    if (NOT(InferenceEngine_FOUND))
-        message(FATAL_ERROR ${IE_NOT_FOUND_MESSAGE})
-    endif()
-else()
-    find_package(InferenceEngine 1.5 REQUIRED)
-endif()
-
 if (WIN32)
     if (NOT "${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
         message(FATAL_ERROR "Only 64-bit supported on Windows")
@@ -69,13 +59,16 @@ if (WIN32)
     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SCL_SECURE_NO_WARNINGS -DNOMINMAX")
     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") #no asynchronous structured exception handling
     set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
+    if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
+        set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /wd4275 /wd4267") #disable some warnings
+    endif()
 else()
-    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type ")
+    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") #treating warnings as errors
     if (APPLE)
         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-command-line-argument")
     elseif(UNIX)
         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized -Winit-self")
-        if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+        if(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmaybe-uninitialized")
         endif()
     endif()
@@ -86,54 +79,70 @@ endif()
 ## to use C++11
 set (CMAKE_CXX_STANDARD 11)
 set (CMAKE_CXX_STANDARD_REQUIRED ON)
-set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
+if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
+    set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
+endif()
 ####################################
 
 set (GFLAGS_IS_SUBPROJECT TRUE)
 set (HAVE_SYS_STAT_H 1)
 set (HAVE_INTTYPES_H 1)
 
-if (WIN32)
-    # add_compile_options("/WX")
-else()
-    add_compile_options("-Werror")
+add_subdirectory(thirdparty/gflags)
+
+if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
 endif()
 
-# Properties->C/C++->General->Additional Include Directories
 include_directories (
-    ${CMAKE_CURRENT_SOURCE_DIR}/common/format_reader
-    ${InferenceEngine_INCLUDE_DIRS}
-    ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/gflags/include
-    ${CMAKE_CURRENT_SOURCE_DIR}/common
+        ${CMAKE_CURRENT_SOURCE_DIR}/common
+        ${CMAKE_CURRENT_SOURCE_DIR}/common/format_reader
 )
+add_subdirectory(common/format_reader)
 
-if (UNIX)
-    set (LIB_DL dl)
+# samples build can be switched off during whole IE build
+if (IE_MAIN_SOURCE_DIR AND NOT ENABLE_SAMPLES)
+    return()
 endif()
 
-add_subdirectory(thirdparty/gflags)
-add_subdirectory(common/format_reader)
-
-# collect all samples subdirectories
-file(GLOB subdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
-# skip building of unnecessary subdirs
-list(REMOVE_ITEM subdirs archived common thirdparty)
-
-foreach (dir ${subdirs})
-    if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
-        # check if a subdirectory contains CMakeLists.txt. In this case we can build it.
-        file(GLOB is_sample_dir "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
-        if(is_sample_dir)
-            # check if specified sample/demo is found.
-            if (BUILD_SAMPLE_NAME)
-                list(FIND BUILD_SAMPLE_NAME ${dir} index)
-            endif()
-            if (index EQUAL -1)
-                message(STATUS "${dir} SKIPPED")
-            else()
-                # Include subdirectory to the project.
-                add_subdirectory(${dir})
+function(add_samples_to_build)
+    # check each passed sample subdirectory
+    foreach (dir ${ARGN})
+        if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
+            # check if a subdirectory contains CMakeLists.txt. In this case we can build it.
+            file(GLOB is_sample_dir "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
+            if(is_sample_dir)
+                # check if specified sample/demo is found.
+                if (BUILD_SAMPLE_NAME)
+                    list(FIND BUILD_SAMPLE_NAME ${dir} index)
+                endif()
+                if (index EQUAL -1)
+                    message(STATUS "${dir} SKIPPED")
+                else()
+                    # Include subdirectory to the project.
+                    add_subdirectory(${dir})
+                endif()
             endif()
         endif()
+    endforeach()
+endfunction(add_samples_to_build)
+
+# use this flag if you need to throw custom message in case if the IE package is not found.
+if (IE_NOT_FOUND_MESSAGE)
+    find_package(InferenceEngine 1.6 QUIET)
+    if (NOT(InferenceEngine_FOUND))
+        message(FATAL_ERROR ${IE_NOT_FOUND_MESSAGE})
     endif()
-endforeach()
+else()
+    find_package(InferenceEngine 1.6 REQUIRED)
+endif()
+
+if (UNIX)
+    set (LIB_DL dl)
+endif()
+
+# collect all samples subdirectories
+file(GLOB samples_dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
+# skip building of unnecessary subdirectories
+list(REMOVE_ITEM samples_dirs archived common thirdparty)
+add_samples_to_build(${samples_dirs})