diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1408816b3..7f05f318b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,7 +62,7 @@ find_package(Threads REQUIRED)
 # c++14
 # TODO: set here 17 once it will be available in the cmake version (3.8)
 set(cxx_standard 14)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -Wall")
 # -----------------------------------------------------------------------------
 
 # dir variables
@@ -357,12 +357,14 @@ set(memgraph_src_files
 
 # STATIC library used by memgraph executables
 add_library(memgraph_lib STATIC ${memgraph_src_files})
-add_dependencies(memgraph_lib generate_opencypher_parser)
+add_dependencies(memgraph_lib generate_opencypher_parser
+                              generate_plan_compiler_flags)
 # -----------------------------------------------------------------------------
 
 # STATIC PIC library used by query engine
 add_library(memgraph_pic STATIC ${memgraph_src_files})
-add_dependencies(memgraph_pic generate_opencypher_parser)
+add_dependencies(memgraph_pic generate_opencypher_parser
+                              generate_plan_compiler_flags)
 set_property(TARGET memgraph_pic PROPERTY POSITION_INDEPENDENT_CODE TRUE)
 # -----------------------------------------------------------------------------
 
@@ -462,3 +464,23 @@ foreach(file_path ${__HARDCODED_SOURCES})
                           PROPERTIES RUNTIME_OUTPUT_DIRECTORY
                           "${CMAKE_BINARY_DIR}/__hardcoded_targets")
 endforeach()
+
+get_target_cxx_flags(memgraph_lib compile_flags)
+set(plan_compiler_flags_file ${build_include_dir}/query/plan_compiler_flags.hpp)
+add_custom_target(generate_plan_compiler_flags
+  COMMENT
+  "Generating ${plan_compiler_flags_file} with compile flags: ${compile_flags}"
+  VERBATIM
+  COMMAND
+  /bin/echo -e
+  "#pragma once"
+  "\\n// Generated from cmake. Flags are taken from current build configuration."
+  "\\n// Do not edit this manually!"
+  "\\nstatic constexpr const char compile_flags[] = \"${compile_flags}\";"
+  "\\nstatic constexpr const char include_dirs[] ="
+  "\"-I${CMAKE_BINARY_DIR}/include -I${CMAKE_SOURCE_DIR}/libs/fmt\";"
+  "\\nstatic constexpr const char link_dirs[] = \"-L${CMAKE_BINARY_DIR}\";"
+  > ${plan_compiler_flags_file}
+  BYPRODUCTS ${plan_compiler_flags_file}
+)
+set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${plan_compiler_flags_file})
diff --git a/cmake/functions.cmake b/cmake/functions.cmake
index ac2ab1834..b285b6a51 100644
--- a/cmake/functions.cmake
+++ b/cmake/functions.cmake
@@ -43,3 +43,45 @@ function(disallow_in_source_build)
                 "directory, e.g. 'build' and run cmake there.")
     endif()
 endfunction()
+
+# Takes a string of ';' separated VALUES and stores a new string in RESULT,
+# where ';' is replaced with given SEP.
+function(join values sep result)
+    # Match non escaped ';' and replace it with separator. This doesn't handle
+    # the case when backslash is escaped, e.g: "a\\\\;b" will produce "a;b".
+    string(REGEX REPLACE "([^\\]|^);" "\\1${sep}" tmp "${values}")
+    # Fix-up escapes by matching backslashes and removing them.
+    string(REGEX REPLACE "[\\](.)" "\\1" tmp "${tmp}")
+    set(${result} "${tmp}" PARENT_SCOPE)
+endfunction()
+
+# Returns a list of compile flags ready for gcc or clang.
+function(get_target_cxx_flags target result)
+    # First set the CMAKE_CXX_FLAGS variables, then append directory and target
+    # options in that order. Definitions come last, directory then target.
+    string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
+    set(flags "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${build_type}}")
+    get_directory_property(dir_opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+                           COMPILE_OPTIONS)
+    if(dir_opts)
+        join("${dir_opts}" " " dir_opts)
+        string(APPEND flags " " ${dir_opts})
+    endif()
+    get_target_property(opts ${target} COMPILE_OPTIONS)
+    if(opts)
+        join("${opts}" " " opts)
+        string(APPEND flags " " ${opts})
+    endif()
+    get_directory_property(dir_defs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+                           COMPILE_DEFINITIONS)
+    if(dir_defs)
+        join("${dir_defs}" " -D" dir_defs)
+        string(APPEND flags " -D" ${dir_defs})
+    endif()
+    get_target_property(defs ${target} COMPILE_DEFINITIONS)
+    if(defs)
+        join("${defs}" " -D" defs)
+        string(APPEND flags " -D" ${defs})
+    endif()
+    set(${result} ${flags} PARENT_SCOPE)
+endfunction()
diff --git a/src/query/plan_compiler.hpp b/src/query/plan_compiler.hpp
index e546da912..5b49a6287 100644
--- a/src/query/plan_compiler.hpp
+++ b/src/query/plan_compiler.hpp
@@ -5,6 +5,7 @@
 #include "logging/default.hpp"
 #include "logging/loggable.hpp"
 #include "query/exception/plan_compilation.hpp"
+#include "query/plan_compiler_flags.hpp"
 #include "utils/string/join.hpp"
 
 // TODO:
@@ -27,45 +28,16 @@ class PlanCompiler : public Loggable {
    * @return void
    */
   void compile(const std::string &in_file, const std::string &out_file) {
-    std::string flags;
-
-// TODO: sync this with cmake configuration
-#ifdef NDEBUG
-    flags += " -DNDEBUG -O2";
-#endif
-#ifdef LOG_NO_TRACE
-    flags += " -DLOG_NO_TRACE";
-#endif
-#ifdef LOG_NO_DEBUG
-    flags += " -DLOG_NO_DEBUG";
-#endif
-#ifdef LOG_NO_INFO
-    flags += " -DLOG_NO_INFO";
-#endif
-#ifdef LOG_NO_WARN
-    flags += " -DLOG_NO_WARN";
-#endif
-#ifdef LOG_NO_ERROR
-    flags += " -DLOG_NO_ERROR";
-#endif
-#ifdef DEBUG_ASSERT_ON
-    flags += " -DDEBUG_ASSERT_ON";
-#endif
-
-    // TODO: load from config (generate compile command)
     // generate compile command
     auto compile_command = utils::prints(
-        "clang++" + flags,
+        "clang++", compile_flags,
 #ifdef HARDCODED_OUTPUT_STREAM
         "-DHARDCODED_OUTPUT_STREAM",
 #endif
-        // "-std=c++1y -O2 -DNDEBUG",
-        "-std=c++1y",    // compile flags
         in_file,         // input file
         "-o", out_file,  // ouput file
-        "-I./include", "-I../include", "-I../../include", "-I../../../include",
-        "-I./libs/fmt", "-I../libs/fmt", "-I../../libs/fmt",
-        "-I../../../libs/fmt", "-L./ -L../ -L../../", "-lmemgraph_pic",
+        include_dirs,
+        link_dirs, "-lmemgraph_pic",
         "-shared -fPIC"  // shared library flags
         );
 
diff --git a/tests/concurrent/network_common.hpp b/tests/concurrent/network_common.hpp
index 8371a5b60..1fa294be4 100644
--- a/tests/concurrent/network_common.hpp
+++ b/tests/concurrent/network_common.hpp
@@ -1,4 +1,4 @@
-#pragma ONCE
+#pragma once
 
 #include <array>
 #include <cassert>