--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -330,18 +330,29 @@
 # in the top level CMakeLists.txt, to ensure a consistent
 # header file layout across the entire project.
 #
-set(ENABLE_BUNDLED_LIBCORO ON)
-include(BuildLibCORO)
-libcoro_build()
-add_dependencies(build_bundled_libs coro)
+option(ENABLE_BUNDLED_LIBCORO "Enable building of the bundled libcoro" ON)
+if (ENABLE_BUNDLED_LIBCORO)
+    include(BuildLibCORO)
+    libcoro_build()
+    add_dependencies(build_bundled_libs coro)
+else()
+    set(LIBCORO_FIND_REQUIRED ON)
+    find_package(LibCORO)
+endif()
 
 #
 # LibGOPT
 #
 
-include(BuildLibGOPT)
-libgopt_build()
-add_dependencies(build_bundled_libs gopt)
+option(ENABLE_BUNDLED_LIBGOPT "Enable building of the bundled gopt" ON)
+if (ENABLE_BUNDLED_LIBGOPT)
+    include(BuildLibGOPT)
+    libgopt_build()
+    add_dependencies(build_bundled_libs gopt)
+else()
+    set(LIBGOPT_FIND_REQUIRED ON)
+    find_package(LibGOPT)
+endif()
 
 #
 # MsgPuck
@@ -377,11 +388,14 @@
 # zstd
 #
 
-# Debian: missing zstd_static.h in libzstd-dev
-# Fedora: not found
-# => always use bundled version
-include(BuildZSTD)
-zstd_build()
+option(ENABLE_BUNDLED_ZSTD "Enable building of the bundled zstd" ON)
+if (ENABLE_BUNDLED_ZSTD)
+    include(BuildZSTD)
+    zstd_build()
+else()
+    set(LIBZSTD_FIND_REQUIRED ON)
+    find_package(ZSTD)
+endif()
 
 #
 # OpenSSL
--- /dev/null
+++ b/cmake/FindLibCORO.cmake
@@ -0,0 +1,24 @@
+find_path(LIBCORO_INCLUDE_DIR
+  NAMES coro.h
+)
+
+find_library(LIBCORO_LIBRARY
+  NAMES libcoro.a coro
+)
+
+set(LIBCORO_INCLUDE_DIRS "${LIBCORO_INCLUDE_DIR}")
+set(LIBCORO_LIBRARIES "${LIBCORO_LIBRARY}")
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LIBCORO REQUIRED_VARS
+    LIBCORO_LIBRARIES LIBCORO_INCLUDE_DIRS)
+
+mark_as_advanced(LIBCORO_LIBRARY LIBCORO_LIBRARIES
+    LIBCORO_INCLUDE_DIR LIBCORO_INCLUDE_DIRS)
+
+if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "86" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "amd64"
+        OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
+    add_definitions("-DCORO_ASM")
+else()
+    add_definitions("-DCORO_SJLJ")
+endif()
--- /dev/null
+++ b/cmake/FindLibGOPT.cmake
@@ -0,0 +1,17 @@
+find_path(LIBGOPT_INCLUDE_DIR
+  NAMES gopt.h
+)
+
+find_library(LIBGOPT_LIBRARY
+  NAMES libgopt.a gopt
+)
+
+set(LIBGOPT_INCLUDE_DIRS "${LIBGOPT_INCLUDE_DIR}")
+set(LIBGOPT_LIBRARIES "${LIBGOPT_LIBRARY}")
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LIBGOPT REQUIRED_VARS
+    LIBGOPT_LIBRARIES LIBGOPT_INCLUDE_DIRS)
+
+mark_as_advanced(LIBGOPT_LIBRARY LIBGOPT_LIBRARIES
+    LIBGOPT_INCLUDE_DIR LIBGOPT_INCLUDE_DIRS)
--- /dev/null
+++ b/cmake/FindZSTD.cmake
@@ -0,0 +1,17 @@
+find_path(ZSTD_INCLUDE_DIR
+  NAMES zstd.h
+)
+
+find_library(ZSTD_LIBRARY
+  NAMES zstd
+)
+
+set(ZSTD_INCLUDE_DIRS "${ZSTD_INCLUDE_DIR}")
+set(ZSTD_LIBRARIES "${ZSTD_LIBRARY}")
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(ZSTD REQUIRED_VARS
+    ZSTD_LIBRARIES ZSTD_INCLUDE_DIRS)
+
+mark_as_advanced(ZSTD_LIBRARY ZSTD_LIBRARIES
+    ZSTD_INCLUDE_DIR ZSTD_INCLUDE_DIRS)
--- a/src/main.cc
+++ b/src/main.cc
@@ -67,7 +67,7 @@
 #include "random.h"
 #include "tt_uuid.h"
 #include "iobuf.h"
-#include <third_party/gopt/gopt.h>
+#include <gopt.h>
 #include "cfg.h"
 #include "version.h"
 #include <readline/readline.h>
--- a/src/fiber.h
+++ b/src/fiber.h
@@ -44,7 +44,7 @@
 #include "small/rlist.h"
 #include "salad/stailq.h"
 
-#include <third_party/coro/coro.h>
+#include <coro.h>
 
 #if defined(__cplusplus)
 extern "C" {
--- a/src/opts.c
+++ b/src/opts.c
@@ -31,7 +31,7 @@
 #include "trivia/config.h"
 #include <stddef.h>
 
-#include <third_party/gopt/gopt.h>
+#include <gopt.h>
 
 const void *opt_def =
 	gopt_start(
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -47,15 +47,15 @@
 lua_source(lua_sources lua/httpc.lua)
 lua_source(lua_sources lua/iconv.lua)
 # LuaJIT jit.* library
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/bc.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/bcsave.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/dis_x86.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/dis_x64.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/dump.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/vmdef.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/v.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/p.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/zone.lua")
+lua_source(lua_sources "${LUAJIT_JITLIB_DIR}/bc.lua")
+lua_source(lua_sources "${LUAJIT_JITLIB_DIR}/bcsave.lua")
+lua_source(lua_sources "${LUAJIT_JITLIB_DIR}/dis_x86.lua")
+lua_source(lua_sources "${LUAJIT_JITLIB_DIR}/dis_x64.lua")
+lua_source(lua_sources "${LUAJIT_JITLIB_DIR}/dump.lua")
+lua_source(lua_sources "${LUAJIT_JITLIB_DIR}/vmdef.lua")
+lua_source(lua_sources "${LUAJIT_JITLIB_DIR}/v.lua")
+lua_source(lua_sources "${LUAJIT_JITLIB_DIR}/p.lua")
+lua_source(lua_sources "${LUAJIT_JITLIB_DIR}/zone.lua")
 
 add_custom_target(generate_lua_sources
     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src/box

@@ -197,10 +197,11 @@
 # Rule of thumb: if exporting a symbol from a static library, list the
 # library here.
 set (reexport_libraries server core misc bitset csv
-     ${LUAJIT_LIBRARIES} ${MSGPUCK_LIBRARIES})
+     ${MSGPUCK_LIBRARIES})
 
 set (common_libraries
     ${reexport_libraries}
+    ${LUAJIT_LIBRARIES}
     ${LIBEIO_LIBRARIES}
     ${LIBGOPT_LIBRARIES}
     ${LIBYAML_LIBRARIES}
--- a/cmake/luajit.cmake
+++ b/cmake/luajit.cmake
@@ -38,6 +38,7 @@
     set (LUAJIT_PREFIX "${LUAJIT_BUNDLED_PREFIX}")
     set (LUAJIT_INCLUDE "${PROJECT_SOURCE_DIR}/third_party/luajit/src")
     set (LUAJIT_LIB "${LUAJIT_BUNDLED_LIB}")
+    set (LUAJIT_JITLIB_DIR "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit")
     set (ENABLE_BUNDLED_LUAJIT True)
 endmacro()
 
@@ -63,10 +64,12 @@
 # usable with the server (determined by a compiled test).
 #
 macro (luajit_try_system)
-    find_path (LUAJIT_INCLUDE lj_obj.h PATH_SUFFIXES luajit-2.0 luajit)
+    find_path (LUAJIT_INCLUDE lj_obj.h PATH_SUFFIXES luajit-2.1 luajit)
     find_library (LUAJIT_LIB NAMES luajit luajit-5.1 PATH_SUFFIXES x86_64-linux-gnu)
-    if (LUAJIT_INCLUDE AND LUAJIT_LIB)
-        message (STATUS "include: ${LUAJIT_INCLUDE}, lib: ${LUAJIT_LIB}")
+    file (GLOB LUAJIT_JITLIB_SEARCH_PATHS "/usr/local/share/luajit-2.1*/jit" "/usr/share/luajit-2.1*/jit" "/share/luajit-2.1*/jit")
+    find_path (LUAJIT_JITLIB_DIR vmdef.lua PATHS ${LUAJIT_JITLIB_SEARCH_PATHS})
+    if (LUAJIT_INCLUDE AND LUAJIT_LIB AND LUAJIT_JITLIB_DIR)
+        message (STATUS "include: ${LUAJIT_INCLUDE}, lib: ${LUAJIT_LIB}, jitlib_dir: ${LUAJIT_JITLIB_DIR}")
         message (STATUS "Found a system-wide LuaJIT.")
         luajit_test()
         if ("${LUAJIT_RUNS}" STREQUAL "1")
@@ -79,6 +82,7 @@
         message (FATAL_ERROR "Not found a system LuaJIT")
         #luajit_use_bundled()
     endif()
+    unset(LUAJIT_JITLIB_SEARCH_PATHS)
 endmacro()
 
 #
@@ -87,7 +91,8 @@
 macro (luajit_try_prefix)
     find_path (LUAJIT_INCLUDE "lua.h" ${LUAJIT_PREFIX} NO_DEFAULT_PATH)
     find_library (LUAJIT_LIB "luajit" ${LUAJIT_PREFIX} NO_DEFAULT_PATH)
-    if (LUAJIT_INCLUDE AND LUAJIT_LIB)
+    find_path (LUAJIT_JITLIB_DIR "vmdef.lua" ${LUAJIT_PREFIX}/jit NO_DEFAULT_PATH)
+    if (LUAJIT_INCLUDE AND LUAJIT_LIB AND LUAJIT_JITLIB_DIR)
         include_directories("${LUAJIT_INCLUDE}")
         luajit_test()
         if (LUAJIT_RUNS)
--- a/cmake/utils.cmake
+++ b/cmake/utils.cmake
@@ -41,8 +41,8 @@
 function(lua_source varname filename)
     if (IS_ABSOLUTE "${filename}")
         set (srcfile "${filename}")
-        set (tmpfile "${filename}.new.c")
-        set (dstfile "${filename}.c")
+        set (tmpfile "${CMAKE_CURRENT_BINARY_DIR}${filename}.new.c")
+        set (dstfile "${CMAKE_CURRENT_BINARY_DIR}${filename}.c")
     else(IS_ABSOLUTE "${filename}")
         set (srcfile "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
         set (tmpfile "${CMAKE_CURRENT_BINARY_DIR}/${filename}.new.c")
@@ -62,7 +62,7 @@
         COMMAND ${ECHO} '\;' >> ${tmpfile}
         COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmpfile} ${dstfile}
         COMMAND ${CMAKE_COMMAND} -E remove ${tmpfile}
-        DEPENDS ${srcfile} txt2c libluajit)
+        DEPENDS ${srcfile} txt2c)
 
     set(var ${${varname}})
     set(${varname} ${var} ${dstfile} PARENT_SCOPE)
