From e5f2b87c6bf263fb04fca17aa46f36d2595b5b6e Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Wed, 16 Feb 2022 21:38:17 +0100
Subject: [PATCH] WIP: Try to check for OpenMP support by the compilers

---
 CMakeLists.txt           | 20 ++++++++++++++++++--
 README.md                |  3 +++
 utils/cmake/TestOpenMP.c | 14 ++++++++++++++
 3 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 utils/cmake/TestOpenMP.c

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 508562cb..f9bfbe9f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -228,6 +228,22 @@ set(SQL_SOURCE_FILES
     ${CMAKE_CURRENT_SOURCE_DIR}/src/database/memory.sql
 )
 
+###         ###
+# TEST OPENMP #
+###         ###
+
+try_compile(OPENMP_SUPPORT_OK
+    ${CMAKE_BINARY_DIR/___openmp_test_ok
+    ${CMAKE_CURRENT_SOURCE_DIR}/utils/cmake/TestOpenMP.c}
+    LINK_LIBRARIES -fopenmp
+)
+
+if(OPENMP_SUPPORT_OK)
+    message(STATUS "Compiler has OpenMP support")
+else()
+    message(FATAL_ERROR "Compiler doesn't have OpenMP support")
+endif()
+
 ###                        ###
 # THE COMPILATION DIRECTIVES #
 ###                        ###
@@ -258,8 +274,8 @@ else()
         ${SQL_GENERATED_FILE}
     )
 endif()
-add_executable(lkt     ${lkt_SOURCES})
-add_executable(luka    ${luka_SOURCES} ${SQL_GENERATED_FILE})
+add_executable(lkt  ${lkt_SOURCES})
+add_executable(luka ${luka_SOURCES} ${SQL_GENERATED_FILE})
 
 set(MANPAGES_COMMANDS)
 if(GENERATE_MANPAGES)
diff --git a/README.md b/README.md
index 3467535e..6bf616d8 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,9 @@ A Karaoke player made to replace the old bash scripts on Sakura.
 
 - [cmake](https://cmake.org/) with at least the version 3.17
 - a C compiler with C11 support
+- a C++ compiler with C++20 support (for the Qt5 module)
+- The C and C++ compilers must have OpenMP support (see the
+  [OpenMP C test program](utils/cmake/TestOpenMp.c))
 - the [sqlite3](https://www.sqlite.org/) development library, version
   3.31.0 or newer for [generated columns](https://www.sqlite.org/gencol.html) support
 - a POSIX.1-2008 compatible system (for MS Windows, use something like WSL2)
diff --git a/utils/cmake/TestOpenMP.c b/utils/cmake/TestOpenMP.c
new file mode 100644
index 00000000..63c7d73b
--- /dev/null
+++ b/utils/cmake/TestOpenMP.c
@@ -0,0 +1,14 @@
+int
+main(void)
+{
+    int res = 0;
+    int A[10];
+    memset(&A, 1, sizeof(A));
+
+    #pragma omp parallel for shared(A, res) reduction (+res)
+    for (int i = 0; i < 10; i += 1) {
+        res += A[i]
+    }
+
+    return res;
+}
\ No newline at end of file
-- 
GitLab