From 0c1a8ea8be64f1d64a2cc76af0f36a43da6917a9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Offringa?= <offringa@gmail.com>
Date: Sat, 2 Jan 2021 16:11:09 +0000
Subject: [PATCH] Add pybind11 as git submodule

---
 .gitlab-ci.yml                  |  4 ++-
 .gitmodules                     |  3 +++
 CMakeLists.txt                  | 46 +++++++++++++++++++++++----------
 CMakeVersionInfo.txt            |  4 +--
 external/pybind11               |  1 +
 scripts/docker/Dockerfile       | 10 ++++---
 scripts/docker/Dockerfile-nogui |  8 +++---
 7 files changed, 52 insertions(+), 24 deletions(-)
 create mode 100644 .gitmodules
 create mode 160000 external/pybind11

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 39319c05..98e8ca3a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -20,6 +20,7 @@ before_script:
     libxml2-dev 
     pkg-config
     pybind11-dev
+    python3
     python3-dev python3-numpy
 
 aoflagger:
@@ -30,4 +31,5 @@ aoflagger:
     - make
     - make install
     - make check
-
+    - cd python
+    - echo "import aoflagger"|python3
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 00000000..7676f394
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "external/pybind11"]
+	path = external/pybind11
+	url = https://github.com/pybind/pybind11.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7f01e720..6ccee3db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,46 +14,64 @@ find_package(PkgConfig)
 pkg_check_modules(GTKMM gtkmm-3.0>=3.0.0)
 pkg_check_modules(SIGCXX sigc++-2.0)
 
-include_directories(${CMAKE_SOURCE_DIR}/aocommon/include)
+# Find and include git submodules
+find_package(Git QUIET)
+if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
+# Update submodules as needed
+    option(GIT_SUBMODULE "Check submodules during build" ON)
+    if(GIT_SUBMODULE)
+        message(STATUS "Submodule update")
+        execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --checkout
+                        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+                        RESULT_VARIABLE GIT_SUBMOD_RESULT)
+        if(NOT GIT_SUBMOD_RESULT EQUAL "0")
+            message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
+        endif()
+    endif()
+endif()
+
+# Include aocommon/pybind11 headers
+include_directories("${CMAKE_SOURCE_DIR}/aocommon/include")
+add_subdirectory("${CMAKE_SOURCE_DIR}/external/pybind11")
+include_directories(${pybind11_INCLUDE_DIR})
 
 set(CASACORE_MAKE_REQUIRED_EXTERNALS_OPTIONAL TRUE)
 find_package(Casacore REQUIRED COMPONENTS casa ms tables measures)
+include_directories(${CASACORE_INCLUDE_DIRS})
 
 find_package(CFITSIO REQUIRED)
+include_directories(${CFITSIO_INCLUDE_DIR})
 
 find_path(FFTW3_INCLUDE_DIR NAMES fftw3.h)
 
 find_library(GSL_LIB NAMES gsl)
 find_library(GSL_CBLAS_LIB NAMES gslcblas)
 find_path(GSL_INCLUDE_DIR NAMES gsl/gsl_version.h)
+if(GSL_INCLUDE_DIR)
+  include_directories(${GSL_INCLUDE_DIR})
+endif(GSL_INCLUDE_DIR)
 
 find_package(Threads REQUIRED)
 find_package(LibXml2 REQUIRED)
+include_directories(${LIBXML2_INCLUDE_DIR})
+
 find_package(PNG REQUIRED)
 find_package(PythonLibs 3 REQUIRED)
 find_package(PythonInterp REQUIRED)
 message(STATUS "Using python version ${PYTHON_VERSION_STRING}")
-find_package(pybind11 REQUIRED)
+include_directories(${PYTHON_INCLUDE_DIRS})
 
-set(Boost_NO_BOOST_CMAKE ON)
 # boost::alignment requires Boost 1.56
 find_package(Boost 1.56.0 REQUIRED COMPONENTS date_time filesystem system unit_test_framework)
+include_directories(${Boost_INCLUDE_DIR})
+
 find_library(FFTW3_LIB fftw3 REQUIRED)
+include_directories(${FFTW3_INCLUDE_DIR})
+
 enable_language(Fortran OPTIONAL)
 find_package(BLAS REQUIRED)
 find_package(LAPACK REQUIRED)
 find_package(Lua 5.2 REQUIRED)
-
-include_directories(${pybind11_INCLUDE_DIR})
-include_directories(${CASACORE_INCLUDE_DIRS})
-include_directories(${Boost_INCLUDE_DIR})
-include_directories(${LIBXML2_INCLUDE_DIR})
-include_directories(${CFITSIO_INCLUDE_DIR})
-include_directories(${FFTW3_INCLUDE_DIR})
-if(GSL_INCLUDE_DIR)
-	include_directories(${GSL_INCLUDE_DIR})
-endif(GSL_INCLUDE_DIR)
-include_directories(${PYTHON_INCLUDE_DIRS})
 include_directories(${LUA_INCLUDE_DIR})
 
 # The following stuff will set the "rpath" correctly, so that
diff --git a/CMakeVersionInfo.txt b/CMakeVersionInfo.txt
index a1dc8eb1..6ef40bad 100644
--- a/CMakeVersionInfo.txt
+++ b/CMakeVersionInfo.txt
@@ -1,8 +1,8 @@
 set(AOFLAGGER_VERSION_STR   3.0)
 set(AOFLAGGER_VERSION_MAJOR 3)
 set(AOFLAGGER_VERSION_MINOR 0)
-set(AOFLAGGER_VERSION_SUBMINOR 1)
-set(AOFLAGGER_VERSION_DATE_STR 2020-12-09)
+set(AOFLAGGER_VERSION_SUBMINOR 2)
+set(AOFLAGGER_VERSION_DATE_STR 2021-01-02)
 
 # SOVERSION stored in the library -- increase
 # when making ABI changes
diff --git a/external/pybind11 b/external/pybind11
new file mode 160000
index 00000000..98f1bbb8
--- /dev/null
+++ b/external/pybind11
@@ -0,0 +1 @@
+Subproject commit 98f1bbb8004f654ba9e26717bdf5912fb899b05a
diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile
index 3aa509c1..5c380c76 100644
--- a/scripts/docker/Dockerfile
+++ b/scripts/docker/Dockerfile
@@ -1,4 +1,4 @@
-FROM kernsuite/base:4
+FROM ubuntu:18.04
 
 RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && \
     apt-get install -y \
@@ -8,10 +8,10 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && \
     casacore-data casacore-dev \
     libblas-dev liblapack-dev \
     liblua5.3-dev \
+    python3 \
     libpython3-dev \
-    pybind11-dev \
     libboost-date-time-dev libboost-test-dev \
-      libboost-system-dev libboost-filesystem-dev \
+    libboost-system-dev libboost-filesystem-dev \
     libgtkmm-3.0-dev \
     libcfitsio-dev \
     libfftw3-dev \
@@ -24,4 +24,6 @@ WORKDIR /src
 
 RUN mkdir /build && cd /build && cmake ../src
 
-RUN cd /build && make -j2 && make install && make check -j2
+RUN cd /build && make -j24 && make install && make check -j24
+
+RUN cd /build/python && echo "import aoflagger" | python3
diff --git a/scripts/docker/Dockerfile-nogui b/scripts/docker/Dockerfile-nogui
index d94a477f..80ec19f8 100644
--- a/scripts/docker/Dockerfile-nogui
+++ b/scripts/docker/Dockerfile-nogui
@@ -1,4 +1,4 @@
-FROM kernsuite/base:4
+FROM ubuntu:18.04
 
 RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && \
     apt-get install -y \
@@ -8,10 +8,10 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && \
     casacore-data casacore-dev \
     libblas-dev liblapack-dev \
     liblua5.3-dev \
+    python3 \
     libpython3-dev \
-    pybind11-dev \
     libboost-date-time-dev libboost-test-dev \
-      libboost-system-dev libboost-filesystem-dev \
+    libboost-system-dev libboost-filesystem-dev \
     libcfitsio-dev \
     libfftw3-dev \
     libxml2-dev \
@@ -24,3 +24,5 @@ WORKDIR /src
 RUN mkdir /build && cd /build && cmake ../src
 
 RUN cd /build && make -j2 && make install && make check -j2
+
+RUN cd /build/python && echo "import aoflagger" | python3
-- 
GitLab