Commit 6929c1364c39b41fba63e68260a40bbf48dec93e

Steffen Jaeckel 2022-03-23T17:50:22

add C89 support for CMake Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 63b62ac..525ba1c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -103,11 +103,17 @@ target_link_options(${PROJECT_NAME} BEFORE PRIVATE
     ${LTM_LD_FLAGS}
 )
 
+set(PUBLIC_HEADERS tommath.h)
+set(C89 False CACHE BOOL "(Usually maintained automatically) Enable when the library is in c89 mode to package the correct header files on install")
+if(C89)
+    list(APPEND PUBLIC_HEADERS tommath_c89.h)
+endif()
+
 set_target_properties(${PROJECT_NAME} PROPERTIES
     OUTPUT_NAME tommath
     VERSION ${PROJECT_VERSION}
     SOVERSION ${PROJECT_VERSION_MAJOR}
-    PUBLIC_HEADER tommath.h
+    PUBLIC_HEADER "${PUBLIC_HEADERS}"
 )
 
 option(COMPILE_LTO "Build with LTO enabled")
diff --git a/makefile b/makefile
index 7fa04d2..7fe933f 100644
--- a/makefile
+++ b/makefile
@@ -173,7 +173,8 @@ c89:
 	-e 's/uint\([0-9][0-9]*\)_t/mp_u\1/g' \
 	-e 's/int\([0-9][0-9]*\)_t/mp_i\1/g' \
 	-e 's/__func__/MP_FUNCTION_NAME/g' \
-	*.c tommath.h tommath_private.h demo/*.c demo/*.h etc/*.c
+	-e 's/set(C89 False/set(C89 True/g' \
+	*.c tommath.h tommath_private.h demo/*.c demo/*.h etc/*.c CMakeLists.txt
 
 c99:
 	@echo "Applying substitutions for c99 compatibility..."
@@ -196,7 +197,8 @@ c99:
 	-e 's/mp_u\([0-9][0-9]*\)/uint\1_t/g' \
 	-e 's/mp_i\([0-9][0-9]*\)/int\1_t/g' \
 	-e 's/MP_FUNCTION_NAME/__func__/g' \
-	*.c tommath.h tommath_private.h demo/*.c demo/*.h etc/*.c
+	-e 's/set(C89 True/set(C89 False/g' \
+	*.c tommath.h tommath_private.h demo/*.c demo/*.h etc/*.c CMakeLists.txt
 
 astyle:
 	@echo "   * run astyle on all sources"