diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 000000000..c17c35fa9
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.12)
+cmake_policy(SET CMP0076 NEW)
+cmake_policy(SET CMP0091 NEW)
+
+project(Telegram
+    LANGUAGES C CXX
+    VERSION 1.9.0
+    DESCRIPTION "Official Telegram Desktop messenger"
+    HOMEPAGE_URL "https://desktop.telegram.org"
+)
+
+include(cmake/constants.cmake)
+include(cmake/functions.cmake)
+
+add_subdirectory(cmake)
+add_subdirectory(Telegram)
diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt
new file mode 100644
index 000000000..5b776c0a4
--- /dev/null
+++ b/Telegram/CMakeLists.txt
@@ -0,0 +1,18 @@
+add_subdirectory(lib_rpl)
+add_subdirectory(lib_crl)
+add_subdirectory(lib_base)
+add_subdirectory(codegen)
+
+# get_filename_component(src_loc "./SourceFiles" REALPATH)
+
+# add_executable(Telegram WIN32 MACOSX_BUNDLE
+#     ${src_loc}/main.cpp
+# )
+# init_target(Telegram)
+
+# force_include(Telegram stdafx.h)
+
+# target_link_libraries(Telegram
+# PRIVATE
+#     lib_base
+# )
diff --git a/Telegram/codegen b/Telegram/codegen
index f1202034e..3eee2b658 160000
--- a/Telegram/codegen
+++ b/Telegram/codegen
@@ -1 +1 @@
-Subproject commit f1202034e2466475eee86b03d880c8c5d9d56988
+Subproject commit 3eee2b6581f4d89952d863b3ea39553a4db1d787
diff --git a/Telegram/lib_base b/Telegram/lib_base
index a94ad7f81..eae957873 160000
--- a/Telegram/lib_base
+++ b/Telegram/lib_base
@@ -1 +1 @@
-Subproject commit a94ad7f817c1e1aeb242843d90f2bac313daab7a
+Subproject commit eae95787375e0dd399641abb5e94e40f5ef154e7
diff --git a/Telegram/lib_crl b/Telegram/lib_crl
index 440d088d5..5ea1a6d44 160000
--- a/Telegram/lib_crl
+++ b/Telegram/lib_crl
@@ -1 +1 @@
-Subproject commit 440d088d5d377fe4bddd20e6f3ef32c4174fb27e
+Subproject commit 5ea1a6d4469ff6292f4a563958830d3104b42aef
diff --git a/Telegram/lib_rpl b/Telegram/lib_rpl
index 01323035b..2423c2636 160000
--- a/Telegram/lib_rpl
+++ b/Telegram/lib_rpl
@@ -1 +1 @@
-Subproject commit 01323035bcc9395525f851b4b208f09818ce65f1
+Subproject commit 2423c263604441616fbe402bafa07101bb2dc29d
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
new file mode 100644
index 000000000..621cd3eec
--- /dev/null
+++ b/cmake/CMakeLists.txt
@@ -0,0 +1,72 @@
+add_subdirectory(external)
+
+add_library(common INTERFACE)
+
+target_compile_features(common
+INTERFACE
+    cxx_std_17
+)
+
+target_compile_definitions(common
+INTERFACE
+    UNICODE
+)
+
+if (WIN32)
+    target_compile_definitions(common
+    INTERFACE
+        WIN32
+        _WINDOWS
+        _UNICODE
+        UNICODE
+        # HAVE_STDINT_H
+        # ZLIB_WINAPI
+        _SCL_SECURE_NO_WARNINGS
+        _USING_V110_SDK71_
+        NOMINMAX
+    )
+    target_compile_options(common
+    INTERFACE
+        /permissive-
+        # /Qspectre
+        /MP     # Enable multi process build.
+        /EHsc   # Catch C++ exceptions only, extern C functions never throw a C++ exception.
+        /w14834 # [[nodiscard]]
+        /w15038 # wrong initialization order
+        /w14265 # class has virtual functions, but destructor is not virtual
+        /experimental:preprocessor # need for range-v3 see https://github.com/ericniebler/range-v3#supported-compilers
+        /wd5105 # needed for `/experimental:preprocessor`, suppressing C5105 "macro expansion producing 'defined' has undefined behavior"
+        /Zc:wchar_t- # don't tread wchar_t as builtin type
+    )
+    target_link_libraries(common
+    INTERFACE
+        winmm
+        imm32
+        ws2_32
+        kernel32
+        user32
+        gdi32
+        winspool
+        comdlg32
+        advapi32
+        shell32
+        ole32
+        oleaut32
+        uuid
+        odbc32
+        odbccp32
+        Shlwapi
+        Iphlpapi
+        Gdiplus
+        Strmiids
+        Netapi32
+        Userenv
+        Version
+        Dwmapi
+        Wtsapi32
+        UxTheme
+        DbgHelp
+        Rstrtmgr
+      )
+else()
+endif()
diff --git a/cmake/constants.cmake b/cmake/constants.cmake
new file mode 100644
index 000000000..700a96ff2
--- /dev/null
+++ b/cmake/constants.cmake
@@ -0,0 +1,8 @@
+get_filename_component(libs_loc "../Libraries" REALPATH)
+get_filename_component(third_party_loc "Telegram/ThirdParty" REALPATH)
+
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+    set(build_debug 1)
+else()
+    set(build_debug 0)
+endif()
diff --git a/cmake/external/CMakeLists.txt b/cmake/external/CMakeLists.txt
new file mode 100644
index 000000000..6e7ea170e
--- /dev/null
+++ b/cmake/external/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_subdirectory(qt)
+add_subdirectory(openssl)
+add_subdirectory(variant)
+add_subdirectory(ranges)
+add_subdirectory(gsl)
+add_subdirectory(crash_reports)
diff --git a/cmake/external/crash_reports/CMakeLists.txt b/cmake/external/crash_reports/CMakeLists.txt
new file mode 100644
index 000000000..76485e43c
--- /dev/null
+++ b/cmake/external/crash_reports/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_library(external_crash_reports INTERFACE IMPORTED GLOBAL)
+
+add_subdirectory(breakpad)
+
+if (WIN32)
+    target_link_libraries(external_crash_reports
+    INTERFACE
+        external_breakpad
+    )
+else()
+    target_link_libraries(external_crash_reports
+    INTERFACE
+        external_crashpad
+    )
+endif()
diff --git a/cmake/external/crash_reports/breakpad/CMakeLists.txt b/cmake/external/crash_reports/breakpad/CMakeLists.txt
new file mode 100644
index 000000000..7ef281a67
--- /dev/null
+++ b/cmake/external/crash_reports/breakpad/CMakeLists.txt
@@ -0,0 +1,18 @@
+add_library(external_breakpad INTERFACE IMPORTED GLOBAL)
+
+target_include_directories(external_breakpad SYSTEM
+INTERFACE
+    ${libs_loc}/breakpad/src
+)
+
+target_link_libraries(external_breakpad
+INTERFACE
+    windows/common
+    windows/handler/exception_handler
+    windows/crash_generation/crash_generation_client
+)
+
+target_link_directories(external_breakpad
+INTERFACE
+    ${libs_loc}/breakpad/src/out/$<IF:$<CONFIG:Debug>,Debug,Release>/obj/client
+)
diff --git a/cmake/external/gsl/CMakeLists.txt b/cmake/external/gsl/CMakeLists.txt
new file mode 100644
index 000000000..5a3e4ec33
--- /dev/null
+++ b/cmake/external/gsl/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_library(external_gsl INTERFACE IMPORTED GLOBAL)
+
+target_include_directories(external_gsl SYSTEM
+INTERFACE
+    ${third_party_loc}/GSL/include
+)
diff --git a/cmake/external/openssl/CMakeLists.txt b/cmake/external/openssl/CMakeLists.txt
new file mode 100644
index 000000000..1d476d4e1
--- /dev/null
+++ b/cmake/external/openssl/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_library(external_openssl INTERFACE IMPORTED GLOBAL)
+
+target_include_directories(external_openssl SYSTEM
+INTERFACE
+    ${libs_loc}/openssl_1_1_1/include
+)
diff --git a/cmake/external/qt/CMakeLists.txt b/cmake/external/qt/CMakeLists.txt
new file mode 100644
index 000000000..edd03a6d2
--- /dev/null
+++ b/cmake/external/qt/CMakeLists.txt
@@ -0,0 +1,67 @@
+add_library(external_qt INTERFACE IMPORTED GLOBAL)
+
+set(qt_version 5.12.5)
+
+if (WIN32)
+    set(qt_loc ${libs_loc}/Qt-${qt_version})
+else()
+endif()
+
+target_include_directories(external_qt SYSTEM
+INTERFACE
+    ${qt_loc}/include
+    ${qt_loc}/include/QtCore
+    ${qt_loc}/include/QtGui
+    ${qt_loc}/include/QtDBus
+    ${qt_loc}/include/QtCore/${qt_version}
+    ${qt_loc}/include/QtGui/${qt_version}
+    ${qt_loc}/include/QtCore/${qt_version}/QtCore
+    ${qt_loc}/include/QtGui/${qt_version}/QtGui
+)
+
+set(common_qt_libs
+    qwebp
+    qgif
+    qjpeg
+    Qt5PrintSupport
+    Qt5AccessibilitySupport
+    Qt5FontDatabaseSupport
+    Qt5EventDispatcherSupport
+    Qt5ThemeSupport
+    Qt5Network
+    Qt5Widgets
+    Qt5Gui
+    qtharfbuzz
+    qtlibpng
+)
+
+if (WIN32)
+    set(qt_libs
+        ${common_qt_libs}
+        Qt5Core
+        Qt5WindowsUIAutomationSupport
+        qtmain
+        qwindows
+        qtfreetype
+        qtpcre2
+    )
+    set(qt_libs_list "")
+    foreach(lib ${qt_libs})
+        list(APPEND qt_libs_list "${lib}$<$<CONFIG:Debug>:d>")
+    endforeach()
+else()
+endif()
+
+target_link_directories(external_qt
+INTERFACE
+    ${qt_loc}/lib
+    ${qt_loc}/plugins
+    ${qt_loc}/plugins/bearer
+    ${qt_loc}/plugins/platforms
+    ${qt_loc}/plugins/imageformats
+)
+
+target_link_libraries(external_qt
+INTERFACE
+    ${qt_libs_list}
+)
diff --git a/cmake/external/ranges/CMakeLists.txt b/cmake/external/ranges/CMakeLists.txt
new file mode 100644
index 000000000..e2fcdf603
--- /dev/null
+++ b/cmake/external/ranges/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_library(external_ranges INTERFACE IMPORTED GLOBAL)
+
+target_include_directories(external_ranges SYSTEM
+INTERFACE
+    ${libs_loc}/range-v3/include
+)
diff --git a/cmake/external/variant/CMakeLists.txt b/cmake/external/variant/CMakeLists.txt
new file mode 100644
index 000000000..b0bee9a76
--- /dev/null
+++ b/cmake/external/variant/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_library(external_variant INTERFACE IMPORTED GLOBAL)
+
+target_include_directories(external_variant SYSTEM
+INTERFACE
+    ${third_party_loc}/variant/include
+)
diff --git a/cmake/functions.cmake b/cmake/functions.cmake
new file mode 100644
index 000000000..c35f042e6
--- /dev/null
+++ b/cmake/functions.cmake
@@ -0,0 +1,74 @@
+function(force_include target_name file_path)
+if (MSVC)
+    target_compile_options(${target_name}
+    PRIVATE
+        /FI${file_path}
+    )
+else()
+    target_compile_options(${target_name}
+    PRIVATE
+        -include ${file_path}
+    )
+endif()
+endfunction()
+
+function(init_target target_name)
+    set_property(TARGET ${target_name} PROPERTY
+        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+endfunction()
+
+function(nice_target_sources target_name src_loc list)
+    set(writing_now "")
+    set(private_sources "")
+    set(public_sources "")
+    set(interface_sources "")
+    set(not_win_sources "")
+    set(not_mac_sources "")
+    set(not_linux_sources "")
+    foreach(file ${list})
+        if (${file} STREQUAL "PRIVATE" OR ${file} STREQUAL "PUBLIC" OR ${file} STREQUAL "INTERFACE")
+            set(writing_now ${file})
+        else()
+            set(full_name ${src_loc}/${file})
+            if (${file} MATCHES "/win/" OR ${file} MATCHES "_win\.")
+                list(APPEND not_mac_sources ${full_name})
+                list(APPEND not_linux_sources ${full_name})
+            elseif (${file} MATCHES "/mac/" OR ${file} MATCHES "_mac\.")
+                list(APPEND not_win_sources ${full_name})
+                list(APPEND not_linux_sources ${full_name})
+            elseif (${file} MATCHES "/linux/" OR ${file} MATCHES "_linux\.")
+                list(APPEND not_win_sources ${full_name})
+                list(APPEND not_mac_sources ${full_name})
+            elseif (${file} MATCHES "/posix/" OR ${file} MATCHES "_posix\.")
+                list(APPEND not_win_sources ${full_name})
+            endif()
+            if ("${writing_now}" STREQUAL "PRIVATE")
+                list(APPEND private_sources ${full_name})
+            elseif ("${writing_now}" STREQUAL "PUBLIC")
+                list(APPEND public_sources ${full_name})
+            elseif ("${writing_now}" STREQUAL "INTERFACE")
+                list(APPEND interface_sources ${full_name})
+            else()
+                message(FATAL_ERROR "Unknown sources scope for target ${target_name}")
+            endif()
+            source_group(TREE ${src_loc} FILES ${full_name})
+        endif()
+    endforeach()
+
+    if (NOT "${public_sources}" STREQUAL "")
+        target_sources(${target_name} PUBLIC ${public_sources})
+    endif()
+    if (NOT "${private_sources}" STREQUAL "")
+        target_sources(${target_name} PRIVATE ${private_sources})
+    endif()
+    if (NOT "${interface_sources}" STREQUAL "")
+        target_sources(${target_name} INTERFACE ${interface_sources})
+    endif()
+    if (WIN32)
+        set_source_files_properties(${not_win_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
+    elseif (APPLE)
+        set_source_files_properties(${not_mac_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
+    elseif (LINUX)
+        set_source_files_properties(${not_linux_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
+    endif()
+endfunction()