Define ZIP_STATIC in zipconf.h when building a static library (with cmake).
Improve BUILD_SHARED_LIBS; default to ON.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bfbc95d..f34a405 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,6 +16,8 @@
INCLUDE(TestBigEndian)
INCLUDE(GNUInstallDirs)
+OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON)
+
SET(PACKAGE "libzip")
SET(PACKAGE_NAME ${PACKAGE})
SET(PACKAGE_VERSION_MAJOR "1")
@@ -30,6 +32,10 @@
SET(LIBZIP_VERSION_MICRO ${PACKAGE_VERSION_MICRO})
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+IF(NOT BUILD_SHARED_LIBS)
+ SET(ZIP_STATIC TRUE)
+ENDIF()
+
# Checks
CHECK_FUNCTION_EXISTS(_chmod HAVE__CHMOD)
@@ -99,7 +105,7 @@
FIND_PACKAGE(ZLIB REQUIRED)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
-set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
+SET(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
IF(ZLIB_VERSION_STRING VERSION_LESS "1.1.2")
MESSAGE(FATAL_ERROR "-- ZLIB version too old, please install at least v1.1.2")
ENDIF(ZLIB_VERSION_STRING VERSION_LESS "1.1.2")
@@ -141,7 +147,7 @@
SET(LIBS "${LIBS} -lz")
IF(CMAKE_SYSTEM_NAME MATCHES BSD)
SET(PKG_CONFIG_RPATH "-Wl,-R\${libdir}")
-ENDif(CMAKE_SYSTEM_NAME MATCHES BSD)
+ENDIF(CMAKE_SYSTEM_NAME MATCHES BSD)
CONFIGURE_FILE(libzip.pc.in libzip.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libzip.pc DESTINATION lib/pkgconfig)
diff --git a/TODO.md b/TODO.md
index 5213e8c..fe07c05 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,7 +1,5 @@
# Soon
-* define ZIP_STATIC when libzip is built statically
-
* review guidelines/community standards
- (Linux Foundation Core Infrastructure Initiative Best Practices)[https://bestpractices.coreinfrastructure.org/]
- (Readme Maturity Level)[https://github.com/LappleApple/feedmereadmes/blob/master/README-maturity-model.md]
diff --git a/cmake-zipconf.h.in b/cmake-zipconf.h.in
index 00bf5af..f0e24e8 100644
--- a/cmake-zipconf.h.in
+++ b/cmake-zipconf.h.in
@@ -13,6 +13,8 @@
#cmakedefine LIBZIP_VERSION_MINOR @PACKAGE_VERSION_MINOR@
#cmakedefine LIBZIP_VERSION_MICRO @PACKAGE_VERSION_MICRO@
+#cmakedefine ZIP_STATIC
+
#cmakedefine HAVE_INTTYPES_H_LIBZIP
#cmakedefine HAVE_STDINT_H_LIBZIP
#cmakedefine HAVE_SYS_TYPES_H_LIBZIP
diff --git a/lib/zip.h b/lib/zip.h
index ec3ec30..2f88b18 100644
--- a/lib/zip.h
+++ b/lib/zip.h
@@ -35,6 +35,15 @@
*/
+#ifdef __cplusplus
+extern "C" {
+#if 0
+} /* fix autoindent */
+#endif
+#endif
+
+#include <zipconf.h>
+
#ifndef ZIP_EXTERN
# ifndef ZIP_STATIC
# ifdef _WIN32
@@ -49,15 +58,6 @@
# endif
#endif
-#ifdef __cplusplus
-extern "C" {
-#if 0
-} /* fix autoindent */
-#endif
-#endif
-
-#include <zipconf.h>
-
#include <sys/types.h>
#include <stdio.h>
#include <time.h>