From 67982703b112722b74677f14609896d653012a0c Mon Sep 17 00:00:00 2001
From: Sebastian Ohlmann <sebastian.ohlmann@mpcdf.mpg.de>
Date: Wed, 6 Nov 2019 10:27:23 +0100
Subject: [PATCH 1/3] Remove autogenerated Makefile

---
 tests/Makefile | 178 -------------------------------------------------
 1 file changed, 178 deletions(-)
 delete mode 100644 tests/Makefile

diff --git a/tests/Makefile b/tests/Makefile
deleted file mode 100644
index 3757ec2..0000000
--- a/tests/Makefile
+++ /dev/null
@@ -1,178 +0,0 @@
-# CMAKE generated file: DO NOT EDIT!
-# Generated by "Unix Makefiles" Generator, CMake Version 3.12
-
-# Default target executed when no arguments are given to make.
-default_target: all
-
-.PHONY : default_target
-
-# Allow only one "make -f Makefile2" at a time, but pass parallelism.
-.NOTPARALLEL:
-
-
-#=============================================================================
-# Special targets provided by cmake.
-
-# Disable implicit rules so canonical targets will work.
-.SUFFIXES:
-
-
-# Remove some rules from gmake that .SUFFIXES does not remove.
-SUFFIXES =
-
-.SUFFIXES: .hpux_make_needs_suffix_list
-
-
-# Suppress display of executed commands.
-$(VERBOSE).SILENT:
-
-
-# A target that is always out of date.
-cmake_force:
-
-.PHONY : cmake_force
-
-#=============================================================================
-# Set environment variables for the build.
-
-# The shell in which to execute make rules.
-SHELL = /bin/sh
-
-# The CMake executable.
-CMAKE_COMMAND = /usr/bin/cmake
-
-# The command to remove a file.
-RM = /usr/bin/cmake -E remove -f
-
-# Escaping for special characters.
-EQUALS = =
-
-# The top-level source directory on which CMake was run.
-CMAKE_SOURCE_DIR = /home/sluka/Work/testing_example/tests
-
-# The top-level build directory on which CMake was run.
-CMAKE_BINARY_DIR = /home/sluka/Work/testing_example/tests
-
-#=============================================================================
-# Targets provided globally by CMake.
-
-# Special rule for the target rebuild_cache
-rebuild_cache:
-	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
-	/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
-.PHONY : rebuild_cache
-
-# Special rule for the target rebuild_cache
-rebuild_cache/fast: rebuild_cache
-
-.PHONY : rebuild_cache/fast
-
-# Special rule for the target edit_cache
-edit_cache:
-	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
-	/usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
-.PHONY : edit_cache
-
-# Special rule for the target edit_cache
-edit_cache/fast: edit_cache
-
-.PHONY : edit_cache/fast
-
-# The main all target
-all: cmake_check_build_system
-	$(CMAKE_COMMAND) -E cmake_progress_start /home/sluka/Work/testing_example/tests/CMakeFiles /home/sluka/Work/testing_example/tests/CMakeFiles/progress.marks
-	$(MAKE) -f CMakeFiles/Makefile2 all
-	$(CMAKE_COMMAND) -E cmake_progress_start /home/sluka/Work/testing_example/tests/CMakeFiles 0
-.PHONY : all
-
-# The main clean target
-clean:
-	$(MAKE) -f CMakeFiles/Makefile2 clean
-.PHONY : clean
-
-# The main clean target
-clean/fast: clean
-
-.PHONY : clean/fast
-
-# Prepare targets for installation.
-preinstall: all
-	$(MAKE) -f CMakeFiles/Makefile2 preinstall
-.PHONY : preinstall
-
-# Prepare targets for installation.
-preinstall/fast:
-	$(MAKE) -f CMakeFiles/Makefile2 preinstall
-.PHONY : preinstall/fast
-
-# clear depends
-depend:
-	$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
-.PHONY : depend
-
-#=============================================================================
-# Target rules for targets named runTests
-
-# Build rule for target.
-runTests: cmake_check_build_system
-	$(MAKE) -f CMakeFiles/Makefile2 runTests
-.PHONY : runTests
-
-# fast build rule for target.
-runTests/fast:
-	$(MAKE) -f CMakeFiles/runTests.dir/build.make CMakeFiles/runTests.dir/build
-.PHONY : runTests/fast
-
-test_funcs.o: test_funcs.cpp.o
-
-.PHONY : test_funcs.o
-
-# target to build an object file
-test_funcs.cpp.o:
-	$(MAKE) -f CMakeFiles/runTests.dir/build.make CMakeFiles/runTests.dir/test_funcs.cpp.o
-.PHONY : test_funcs.cpp.o
-
-test_funcs.i: test_funcs.cpp.i
-
-.PHONY : test_funcs.i
-
-# target to preprocess a source file
-test_funcs.cpp.i:
-	$(MAKE) -f CMakeFiles/runTests.dir/build.make CMakeFiles/runTests.dir/test_funcs.cpp.i
-.PHONY : test_funcs.cpp.i
-
-test_funcs.s: test_funcs.cpp.s
-
-.PHONY : test_funcs.s
-
-# target to generate assembly for a file
-test_funcs.cpp.s:
-	$(MAKE) -f CMakeFiles/runTests.dir/build.make CMakeFiles/runTests.dir/test_funcs.cpp.s
-.PHONY : test_funcs.cpp.s
-
-# Help Target
-help:
-	@echo "The following are some of the valid targets for this Makefile:"
-	@echo "... all (the default if no target is provided)"
-	@echo "... clean"
-	@echo "... depend"
-	@echo "... rebuild_cache"
-	@echo "... runTests"
-	@echo "... edit_cache"
-	@echo "... test_funcs.o"
-	@echo "... test_funcs.i"
-	@echo "... test_funcs.s"
-.PHONY : help
-
-
-
-#=============================================================================
-# Special targets to cleanup operation of make.
-
-# Special rule to run CMake to check the build system integrity.
-# No rule that depends on this can have commands that come from listfiles
-# because they might be regenerated.
-cmake_check_build_system:
-	$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
-.PHONY : cmake_check_build_system
-
-- 
GitLab


From 651d5ac6a2192b057e2e982007be74666faf2e1e Mon Sep 17 00:00:00 2001
From: Sebastian Ohlmann <sebastian.ohlmann@mpcdf.mpg.de>
Date: Wed, 6 Nov 2019 10:51:10 +0100
Subject: [PATCH 2/3] Add headers to make intel compiler happy

---
 src/main.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/main.cpp b/src/main.cpp
index 702da9d..24cb085 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,3 +1,5 @@
+#include <stdio.h>
+#include <stdlib.h>
 #include "funcs.cpp"
 using namespace std;
 
-- 
GitLab


From 0ee77a627cf29fe4aadc7d3dad5a1356cfe78592 Mon Sep 17 00:00:00 2001
From: Sebastian Ohlmann <sebastian.ohlmann@mpcdf.mpg.de>
Date: Wed, 6 Nov 2019 10:27:32 +0100
Subject: [PATCH 3/3] Add CI, including compiling gtest

---
 .gitlab-ci.yml | 18 ++++++++++++++++++
 Makefile       | 16 ++++++++++------
 get_gtest.sh   | 11 +++++++++++
 3 files changed, 39 insertions(+), 6 deletions(-)
 create mode 100644 .gitlab-ci.yml
 create mode 100755 get_gtest.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..7807c59
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,18 @@
+# use MPCDF module environment
+image: gitlab-registry.mpcdf.mpg.de/mpcdf/module-image
+
+default:
+  before_script:
+    - module load cmake git
+
+test-gcc9:
+  script:
+    - module load gcc/9
+    - CC=gcc CXX=g++ CXXFLAGS="-std=c++11" ./get_gtest.sh
+    - make CC=gcc CXX=g++ CXXFLAGS="-std=c++11 -I$PWD/googletest/install/include" LDFLAGS="-L$PWD/googletest/install/lib64"
+
+test-intel19:
+  script:
+    - module load intel/19.0.4
+    - CC=icc CXX=icpc CXXFLAGS="-std=c++11" ./get_gtest.sh
+    - make CC=icc CXX=icpc CXXFLAGS="-std=c++11 -I$PWD/googletest/install/include" LDFLAGS="-L$PWD/googletest/install/lib64"
diff --git a/Makefile b/Makefile
index dbb7287..30af201 100644
--- a/Makefile
+++ b/Makefile
@@ -1,21 +1,24 @@
 SRC=src/main.cpp
-TESTS=tests
 COV=coverage
 OUT_T=test_output
 OUT_E=expected_output
 APP=program
 CXX=g++
 BROWSER=google-chrome
+TESTS=tests
+TEST_APP=runTests
+TEST_SRC=$(TESTS)/test_funcs.cpp
+LDFLAGS_GTEST=-lgtest -lpthread
 
 # Default
 all: distclean compile test
 
 # Compiling section
 compile:
-	$(CXX) -o $(APP) $(SRC)
+	$(CXX) $(CXXFLAGS) -o $(APP) $(SRC)
 
 compile_coverage:
-	$(CXX) -o $(APP) --coverage $(SRC)
+	$(CXX) $(CXXFLAGS) -o $(APP) --coverage $(SRC)
 
 # Testing section
 test: simple_tests regression_test unit_tests
@@ -31,8 +34,9 @@ regression_test:
 	diff $(OUT_T) $(OUT_E)
 
 unit_tests:
-	cd $(TESTS) && cmake CMakeLists.txt && make
-	./$(TESTS)/runTests
+	$(CXX) $(CXXFLAGS) -o test_funcs.o -c $(TEST_SRC)
+	$(CXX) $(CXXFLAGS) test_funcs.o -o $(TEST_APP) $(LDFLAGS) $(LDFLAGS_GTEST)
+	./$(TEST_APP)
 
 # Coverage section
 coverage: clean clean_coverage compile_coverage simple_tests
@@ -50,7 +54,7 @@ clean:
 	rm -f $(APP)
 
 clean_tests:
-	rm -rf $(TESTS)/CMakeFiles $(TESTS)/CMakeCache.txt $(TESTS)/cmake_install.cmake $(TESTS)/CMakeFiles $(TESTS)/runTests $(OUT_E) $(OUT_T)
+	rm -rf $(TESTS)/CMakeFiles $(TESTS)/CMakeCache.txt $(TESTS)/cmake_install.cmake $(TESTS)/CMakeFiles $(TESTS)/runTests $(OUT_E) $(OUT_T) $(TEST_APP) *.o
 
 clean_coverage:
 	rm -rf *.gcno *.gcda $(APP).info $(COV)
diff --git a/get_gtest.sh b/get_gtest.sh
new file mode 100755
index 0000000..16385fa
--- /dev/null
+++ b/get_gtest.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# already there
+[[ -d googletest ]] && exit 0
+
+# otherwise download and build
+git clone https://github.com/google/googletest.git
+mkdir -p googletest/build
+cd googletest/build
+cmake .. -DCMAKE_INSTALL_PREFIX=../install
+make && make install
-- 
GitLab