macro(Build3rdParties)
  print("3rd parties")

  #_____________________________________________________________________________
  #                                                                   call_stack
  if (BUILD_SWITCH_CORE)
    find_package(call_stack QUIET)
    if (call_stack_FOUND)
      print("  [X] call_stack")
    else()
      print("  [X] call_stack master (*)")
      add_subdirectory(3rdparty/call_stack)
      set_target_properties(call_stack PROPERTIES FOLDER 3rdparty)
      set(CALL_STACK_LIBRARY call_stack)
      set(CALL_STACK_LIBRARIES ${CALL_STACK_LIBRARY})
    endif()
    include_directories(${CALL_STACK_INCLUDE_DIRS})
  else()
    print("  [ ] call_stack")
  endif()

  #_____________________________________________________________________________
  #                                                                 easywsclient
  if (BUILD_SWITCH_CORE)
    find_package(easywsclient QUIET)
    if (easywsclient_FOUND)
      print("  [X] easywsclient")
    else()
      print("  [X] easywsclient master (*)")
      add_subdirectory(3rdparty/easywsclient)
      set_target_properties(easywsclient PROPERTIES FOLDER 3rdparty)
      set(EASYWSCLIENT_LIBRARY easywsclient)
      set(EASYWSCLIENT_LIBRARIES ${EASYWSCLIENT_LIBRARY})
    endif()
    include_directories(${EASYWSCLIENT_INCLUDE_DIRS})
  else()
    print("  [ ] easywsclient")
  endif()

  #_____________________________________________________________________________
  #                                                                        RS232
  if (BUILD_SWITCH_CORE)
    find_package(RS232 QUIET)
    if (RS232_FOUND)
      print("  [X] RS232")
    else()
      print("  [X] RS232 master (*)")
      add_subdirectory(3rdparty/RS-232)
      set_target_properties(RS232 PROPERTIES FOLDER 3rdparty)
    endif()
    include_directories(${RS232_INCLUDE_DIRS})
  else()
    print("  [ ] RS232")
  endif()

  #_____________________________________________________________________________
  #                                                                         ZLIB
  if (BUILD_SWITCH_CORE)
    find_package(ZLIB QUIET)
    if (ZLIB_FOUND)
      print("  [X] ZLIB ${ZLIB_VERSION_STRING}")
    else()
      print("  [X] ZLIB 1.2.8 (*)")
      add_subdirectory(3rdparty/zlib)
      set_target_properties(zlib PROPERTIES FOLDER 3rdparty)
      set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/zlib/zlib")
      set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
      set(ZLIB_LIBRARY zlib)
      set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
    endif()
    include_directories(${ZLIB_INCLUDE_DIRS})
  else()
    print("  [ ] ZLIB")
  endif()

  #_____________________________________________________________________________
  #                                                                         CURL
  if (NOT IOS AND NOT ANDROID AND BUILD_SWITCH_SYSTEM)
    find_package(CURL QUIET)
    if (CURL_FOUND)
      print("  [X] curl ${CURL_VERSION_STRING}")
    else()
      print("  [X] curl 7.53.0 (*)")
      option(BUILD_CURL_EXE "Set to ON to build curl executable." OFF)
      #option(CURL_STATICLIB "Set to ON to build libcurl with static linking." ON)
      option(BUILD_TESTING "Build the testing tree" OFF)
      option(ENABLE_MANUAL "to provie the built-in manual" OFF)
      add_subdirectory(3rdparty/curl)
      set_target_properties(libcurl PROPERTIES FOLDER 3rdparty)
      set(CURL_LIBRARIES libcurl)
      set(CURL_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/curl/include" "${CMAKE_CURRENT_BINARY_DIR}/3rdparty/curl/include/curl")
    endif()
    include_directories(${CURL_INCLUDE_DIRS})
  else()
    print("  [ ] curl")
  endif()

  #_____________________________________________________________________________
  #                                                                         jpeg
  if (BUILD_SWITCH_SYSTEM_DRAWING)
    find_package(JPEG)
    if (JPEG_FOUND)
      print("  [X] JPEG")
    else()
      print("  [X] JPEG master (*)")
      #add_subdirectory(3rdparty/libjpeg)
      add_subdirectory(3rdparty/jpeg)
      set_target_properties(jpeg PROPERTIES FOLDER 3rdparty)
      set(JPEG_LIBRARY jpeg)
      set(JPEG_LIBRARIES ${JPEG_LIBRARY})
    endif()
    include_directories(${JPEG_INCLUDE_DIRS})
  else()
    print("  [ ] JPEG")
  endif()

  #_____________________________________________________________________________
  #                                                                       libpng
  if (BUILD_SWITCH_SYSTEM_DRAWING)
    find_package(PNG QUIET)
    if (PNG_FOUND)
      print("  [X] PNG  ${PNG_VERSION_STRING}")
    else()
      print("  [X] PNG 1.6.34 (*)")
      add_subdirectory(3rdparty/libpng)
      set_target_properties(png PROPERTIES FOLDER 3rdparty)
      set(PNG_LIBRARIES png)
      set(PNG_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/libpng" "${CMAKE_CURRENT_BINARY_DIR}/3rdparty/libpng")
    endif()
    include_directories(${PNG_INCLUDE_DIRS})
  else()
    print("  [ ] PNG")
  endif()

  #_____________________________________________________________________________
  #                                                                        GTest
  if (BUILD_SWITCH_TESTS OR BUILD_SWITCH_TUNIT_CORE)
    find_package(GTest QUIET)
    if (GTEST_FOUND)
      print("  [X] GTest")
    else()
      print("  [X] gtest 1.8.0 (*)")
      option(BUILD_GMOCK "Build the google mock subproject" OFF)
      option(BUILD_GTEST "Build the google test subproject" ON)
      option(gtest_force_shared_crt "Use shared (DLL) run-time lib even when Google Test is built as static lib." ON)
      add_subdirectory(3rdparty/googletest)
      set_target_properties(gtest PROPERTIES FOLDER 3rdparty)
      set_target_properties(gtest_main PROPERTIES FOLDER 3rdparty)
      set(GTEST_LIBRARY gtest)
      set(GTEST_LIBRARIES ${GTEST_LIBRARY})
      set(GTEST_MAIN_LIBRARY gtest_main)
      set(GTEST_MAIN_LIBRARIES ${GTEST_MAIN_LIBRARY})
    endif()
  endif()
  include_directories(${GTEST_INCLUDE_DIRS})
endmacro()
