Commit 5221e1854846ac31dd2ada44fb29dc705104e851

Peter Pettersson 2021-10-02T23:54:14

Add target for testing libgit2 headers

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 0724703..d42c6ad 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -51,7 +51,7 @@ ide_split_sources(libgit2_tests)
 # this on newer compilers to avoid unnecessary recompilation.
 #
 if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
-	add_definitions(-include \"clar_suite.h\")
+	target_compile_options(libgit2_tests PRIVATE -include "clar_suite.h")
 endif()
 
 if(MSVC_IDE)
@@ -79,3 +79,15 @@ add_clar_test(ssh                 -v -sonline::push -sonline::clone::ssh_cert -s
 add_clar_test(proxy               -v -sonline::clone::proxy)
 add_clar_test(auth_clone          -v -sonline::clone::cred)
 add_clar_test(auth_clone_and_push -v -sonline::clone::push -sonline::push)
+
+# Header file validation project
+add_executable(headertest headertest.c)
+set_target_properties(headertest PROPERTIES C_STANDARD 90)
+set_target_properties(headertest PROPERTIES C_EXTENSIONS OFF)
+target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES})
+
+if (MSVC)
+    target_compile_options(headertest PUBLIC /W4 /WX)
+else()
+    target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror)
+endif()
diff --git a/tests/headertest.c b/tests/headertest.c
new file mode 100644
index 0000000..2af8a14
--- /dev/null
+++ b/tests/headertest.c
@@ -0,0 +1,13 @@
+/*
+ * Dummy project to validate header files
+ *
+ * This project is not intended to be executed, it should only include all
+ * header files to make sure that they can be used with stricter compiler
+ * settings than the libgit2 source files generally supports.
+ */
+#include "git2.h"
+
+int main(void)
+{
+    return 0;
+}