Building PX4Autopilot fails on ubuntu 16.04

Hello everyone, I have been trying to build PX4Autopilot (the latest version) on my Ubuntu 16.04.
I managed to recify most of the issues (Python3 had to be at least 3.7, git had to be updated(updated to 2.32.0), gcc had to be updated from 5.4 to something newer(I updated to gcc-9)) and it got pretty far into the compilation.
Now when I try to build PX4Autopilot with the following command :
DONT_RUN=1 make px4_sitl_default gazebo
This is what I get :

user@ubuntu:~/PX4-Autopilot$ DONT_RUN=1 make px4_sitl_default gazebo
[1/6] Performing configure step for 'sitl_gazebo'
-- install-prefix: /usr/local
-- cmake build type: RelWithDebInfo
-- Using C++17 standard
-- Found Boost: /usr/include (found suitable version "1.58.0", minimum required is "1.58") found components: system thread filesystem chrono date_time atomic 
-- Found Boost: /usr/include (found version "1.58.0")  
-- Checking for module 'gstreamer-1.0 >= 1.0'
--   No package 'gstreamer-1.0' found
-- Checking for module 'gstreamer-base-1.0 >= 1.0'
--   No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-app-1.0 >= 1.0'
--   No package 'gstreamer-app-1.0' found
CMake Deprecation Warning at external/OpticalFlow/CMakeLists.txt:34 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


CMake Deprecation Warning at external/OpticalFlow/external/klt_feature_tracker/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Building klt_feature_tracker without catkin
-- Building OpticalFlow with OpenCV
-- catkin DISABLED
-- Gazebo version: 7.16
-- Found GStreamer: adding gst_camera_plugin
-- Found GStreamer: adding gst_video_stream_widget
CMake Error at CMakeLists.txt:456 (QT5_WRAP_CPP):
  Unknown CMake command "QT5_WRAP_CPP".


-- Configuring incomplete, errors occurred!
See also "/home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeOutput.log".
See also "/home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeError.log".
[2/6] Generating ../../logs
FAILED: cd /home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo && /usr/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DSEND_ODOMETRY_DATA=ON -DGENERATE_ROS_MODELS=ON -GNinja /home/user/PX4-Autopilot/Tools/sitl_gazebo && /usr/bin/cmake -E touch /home/user/PX4-Autopilot/build/px4_sitl_default/external/Stamp/sitl_gazebo/sitl_gazebo-configure
ninja: build stopped: subcommand failed.
Makefile:224: recipe for target 'px4_sitl_default' failed
make: *** [px4_sitl_default] Error 1

Looking at the CMakeError.log I see this :

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_d9915 && [1/2] Building C object CMakeFiles/cmTC_d9915.dir/src.c.o
[2/2] Linking C executable cmTC_d9915
FAILED: : && /usr/bin/cc   CMakeFiles/cmTC_d9915.dir/src.c.o -o cmTC_d9915   && :
CMakeFiles/cmTC_d9915.dir/src.c.o: In function `main':
src.c:(.text+0x3c): undefined reference to `pthread_create'
src.c:(.text+0x48): undefined reference to `pthread_detach'
src.c:(.text+0x54): undefined reference to `pthread_cancel'
src.c:(.text+0x65): undefined reference to `pthread_join'
src.c:(.text+0x79): undefined reference to `pthread_atfork'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.


Source file was:
#include <pthread.h>

static void* test_func(void* data)
{
  return data;
}

int main(void)
{
  pthread_t thread;
  pthread_create(&thread, NULL, test_func, NULL);
  pthread_detach(thread);
  pthread_cancel(thread);
  pthread_join(thread, NULL);
  pthread_atfork(NULL, NULL, NULL);
  pthread_exit(NULL);

  return 0;
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_bac02 && [1/2] Building C object CMakeFiles/cmTC_bac02.dir/CheckFunctionExists.c.o
[2/2] Linking C executable cmTC_bac02
FAILED: : && /usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create  CMakeFiles/cmTC_bac02.dir/CheckFunctionExists.c.o -o cmTC_bac02  -lpthreads && :
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.



Determining if the Q_WS_WIN exist failed with the following output:
Change Dir: /home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_ffa0b && [1/2] Building CXX object CMakeFiles/cmTC_ffa0b.dir/CheckSymbolExists.cxx.o
FAILED: /usr/bin/c++  -I/usr/include/qt4  -o CMakeFiles/cmTC_ffa0b.dir/CheckSymbolExists.cxx.o -c CheckSymbolExists.cxx
CheckSymbolExists.cxx: In function ‘int main(int, char**)’:
CheckSymbolExists.cxx:8:19: error: ‘Q_WS_WIN’ was not declared in this scope
    8 |   return ((int*)(&Q_WS_WIN))[argc];
      |                   ^~~~~~~~
ninja: build stopped: subcommand failed.


File /home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <QtCore/qglobal.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef Q_WS_WIN
  return ((int*)(&Q_WS_WIN))[argc];
#else
  (void)argc;
  return 0;
#endif
}
Determining if the Q_WS_QWS exist failed with the following output:
Change Dir: /home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_38325 && [1/2] Building CXX object CMakeFiles/cmTC_38325.dir/CheckSymbolExists.cxx.o
FAILED: /usr/bin/c++  -I/usr/include/qt4  -o CMakeFiles/cmTC_38325.dir/CheckSymbolExists.cxx.o -c CheckSymbolExists.cxx
CheckSymbolExists.cxx: In function ‘int main(int, char**)’:
CheckSymbolExists.cxx:8:19: error: ‘Q_WS_QWS’ was not declared in this scope
    8 |   return ((int*)(&Q_WS_QWS))[argc];
      |                   ^~~~~~~~
ninja: build stopped: subcommand failed.


File /home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <QtCore/qglobal.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef Q_WS_QWS
  return ((int*)(&Q_WS_QWS))[argc];
#else
  (void)argc;
  return 0;
#endif
}
Determining if the Q_WS_MAC exist failed with the following output:
Change Dir: /home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_c5b26 && [1/2] Building CXX object CMakeFiles/cmTC_c5b26.dir/CheckSymbolExists.cxx.o
FAILED: /usr/bin/c++  -I/usr/include/qt4  -o CMakeFiles/cmTC_c5b26.dir/CheckSymbolExists.cxx.o -c CheckSymbolExists.cxx
CheckSymbolExists.cxx: In function ‘int main(int, char**)’:
CheckSymbolExists.cxx:8:19: error: ‘Q_WS_MAC’ was not declared in this scope
    8 |   return ((int*)(&Q_WS_MAC))[argc];
      |                   ^~~~~~~~
ninja: build stopped: subcommand failed.


File /home/user/PX4-Autopilot/build/px4_sitl_default/build_gazebo/CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <QtCore/qglobal.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef Q_WS_MAC
  return ((int*)(&Q_WS_MAC))[argc];
#else
  (void)argc;
  return 0;
#endif
}

now what should I do to get this fixed? whats missing?
For the first part I tried adding -pthread -lpthread to the add_compile_options in cmake/px4_add_common_flags.cmake to no avail. I have no idea about the rest of the issues.
So how should I go about this ?
Thanks a lot in advance

Do you solved it ? I have the same issue, and I do not know how to deal with it.