Create basic FIND_PACKAGE() files for CMake.
Can probably be improved (patches welcome!), but this works for me
in a simple test.
While here, try to match best practices from other projects.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a2a4c16..a4800d9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,7 +77,7 @@
ENDIF()
SET(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION})
-IF(NOT TARGET dist)
+
ADD_CUSTOM_TARGET(dist
COMMAND git config tar.tar.xz.command "xz -c"
COMMAND git archive --prefix=${ARCHIVE_NAME}/ -o ${ARCHIVE_NAME}.tar.gz HEAD
@@ -91,20 +91,24 @@
COMMAND chmod -R u-w ${ARCHIVE_NAME}
COMMAND mkdir ${ARCHIVE_NAME}-build
COMMAND mkdir ${ARCHIVE_NAME}-dest
- COMMAND cd ${ARCHIVE_NAME}-build && ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=../${ARCHIVE_NAME}-dest ../${ARCHIVE_NAME}
- COMMAND cd ${ARCHIVE_NAME}-build && make -j4
- COMMAND cd ${ARCHIVE_NAME}-build && make test
- COMMAND cd ${ARCHIVE_NAME}-build && make install
-# COMMAND cd ${ARCHIVE_NAME}-build && make uninstall
+ COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${ARCHIVE_NAME}-dest ${ARCHIVE_NAME} -B ${ARCHIVE_NAME}-build
+ COMMAND make -C ${ARCHIVE_NAME}-build -j4
+ COMMAND make -C ${ARCHIVE_NAME}-build test
+ COMMAND make -C ${ARCHIVE_NAME}-build install
+# COMMAND make -C ${ARCHIVE_NAME}-build uninstall
# COMMAND if [ `find ${ARCHIVE_NAME}-dest ! -type d | wc -l` -ne 0 ]; then echo leftover files in ${ARCHIVE_NAME}-dest; false; fi
- COMMAND cd ${ARCHIVE_NAME}-build && make clean
+ COMMAND make -C ${ARCHIVE_NAME}-build clean
COMMAND chmod -R u+w ${ARCHIVE_NAME} ${ARCHIVE_NAME}-build ${ARCHIVE_NAME}-dest
COMMAND rm -rf ${ARCHIVE_NAME} ${ARCHIVE_NAME}-build ${ARCHIVE_NAME}-dest
COMMAND echo "${ARCHIVE_NAME}.tar.gz is ready for distribution."
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
ADD_DEPENDENCIES(distcheck dist)
-ENDIF(NOT TARGET dist)
+
+#ADD_CUSTOM_TARGET(uninstall
+# COMMAND cat ${PROJECT_BINARY_DIR}/install_manifest.txt | xargs rm
+# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+# )
IF(BUILD_SHARED_LIBS)
SET(HAVE_SHARED TRUE)
@@ -260,8 +264,8 @@
ENDIF()
IF(MSVC)
-ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS")
-ADD_DEFINITIONS("-D_CRT_NONSTDC_NO_DEPRECATE")
+ ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS")
+ ADD_DEFINITIONS("-D_CRT_NONSTDC_NO_DEPRECATE")
ENDIF(MSVC)
if(WIN32)
@@ -279,8 +283,8 @@
# rpath handling: use rpath in installed binaries
IF(NOT CMAKE_SYSTEM_NAME MATCHES Linux)
- SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
- SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+ SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
ENDIF()
# for code completion frameworks
@@ -293,7 +297,7 @@
ADD_SUBDIRECTORY(lib)
IF(BUILD_DOC)
-ADD_SUBDIRECTORY(man)
+ ADD_SUBDIRECTORY(man)
ENDIF()
IF(BUILD_TOOLS)
@@ -308,16 +312,16 @@
INCLUDE(FindPerl)
IF(NOT PERL_FOUND)
-MESSAGE(WARNING "-- perl not found, regression testing disabled")
-SET(BUILD_REGRESS OFF)
+ MESSAGE(WARNING "-- perl not found, regression testing disabled")
+ SET(BUILD_REGRESS OFF)
ENDIF()
IF(BUILD_REGRESS)
-ADD_SUBDIRECTORY(regress)
+ ADD_SUBDIRECTORY(regress)
ENDIF()
IF(BUILD_EXAMPLES)
-ADD_SUBDIRECTORY(examples)
+ ADD_SUBDIRECTORY(examples)
ENDIF()
@@ -339,7 +343,7 @@
set(LIBS "${LIBS} -l${LIB}")
endforeach()
CONFIGURE_FILE(libzip.pc.in libzip.pc @ONLY)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libzip.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
+INSTALL(FILES ${PROJECT_BINARY_DIR}/libzip.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# fixed size integral types
@@ -397,13 +401,13 @@
ENDIF()
IF(HAVE_UINT32_T_LIBZIP)
-SET(ZIP_UINT32_T uint32_t)
+ SET(ZIP_UINT32_T uint32_t)
ELSEIF(HAVE___INT32_LIBZIP)
-SET(ZIP_UINT32_T "unsigned __int32")
+ SET(ZIP_UINT32_T "unsigned __int32")
ELSEIF(INT_LIBZIP EQUAL 4)
-SET(ZIP_UINT32_T "unsigned int")
+ SET(ZIP_UINT32_T "unsigned int")
ELSEIF(LONG_LIBZIP EQUAL 4)
-SET(ZIP_UINT32_T "unsigned long")
+ SET(ZIP_UINT32_T "unsigned long")
ENDIF()
IF(HAVE_INT64_T_LIBZIP)
@@ -434,22 +438,50 @@
ENDIF()
# write out config file
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake-zipconf.h.in ${CMAKE_CURRENT_BINARY_DIR}/zipconf.h)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake-config.h.in ${PROJECT_BINARY_DIR}/config.h)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake-zipconf.h.in ${PROJECT_BINARY_DIR}/zipconf.h)
# for tests
SET(srcdir ${CMAKE_CURRENT_SOURCE_DIR}/regress)
SET(abs_srcdir ${CMAKE_CURRENT_SOURCE_DIR}/regress)
-SET(top_builddir ${CMAKE_CURRENT_BINARY_DIR}) # used to find config.h
+SET(top_builddir ${PROJECT_BINARY_DIR}) # used to find config.h
-CONFIGURE_FILE(regress/runtest.in ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/runtest @ONLY)
-FILE(COPY ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/runtest
- DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/regress
+CONFIGURE_FILE(regress/runtest.in ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/runtest @ONLY)
+FILE(COPY ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/runtest
+ DESTINATION ${PROJECT_BINARY_DIR}/regress
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+ )
+
+target_include_directories(zip
+ PUBLIC
+ $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
+ $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDE_DIR}>
)
+# create package config file
+INCLUDE(CMakePackageConfigHelpers)
+WRITE_BASIC_PACKAGE_VERSION_FILE("${PROJECT_BINARY_DIR}/libzip-version.cmake"
+ COMPATIBILITY AnyNewerVersion)
+
+CONFIGURE_PACKAGE_CONFIG_FILE("${PROJECT_NAME}.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libzip
+ PATH_VARS CMAKE_INSTALL_BINDIR CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR)
+
+INSTALL(EXPORT ${PROJECT_NAME}-targets
+ FILE ${PROJECT_NAME}-targets.cmake
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
+ )
+
+# Add targets to the build-tree export set
+EXPORT(TARGETS zip zipcmp
+ FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-targets.cmake")
# installation
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/zipconf.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+INSTALL(FILES ${PROJECT_BINARY_DIR}/zipconf.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+INSTALL(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-version.cmake
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
+ )
+
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index db1e686..6fcdd05 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,13 +1,13 @@
CHECK_FUNCTION_EXISTS(getopt HAVE_GETOPT)
IF(NOT HAVE_GETOPT)
SET(SRC_EXTRA_FILES ../src/getopt.c)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/../src)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/examples
+ ${PROJECT_SOURCE_DIR}/src)
ENDIF(NOT HAVE_GETOPT)
ADD_EXECUTABLE(in-memory in-memory.c)
TARGET_LINK_LIBRARIES(in-memory zip)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../lib
- ${CMAKE_CURRENT_SOURCE_DIR}/../src
- ${CMAKE_CURRENT_BINARY_DIR}/..)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/lib
+ ${PROJECT_SOURCE_DIR}/src
+ ${PROJECT_BINARY_DIR})
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 727709c..1275d10 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -141,9 +141,9 @@
)
ENDIF(WIN32)
-INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/..)
+INCLUDE_DIRECTORIES(BEFORE ${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR})
-file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zip.h zip_h)
+file(READ ${PROJECT_SOURCE_DIR}/lib/zip.h zip_h)
string(REGEX MATCHALL "#define ZIP_ER_([A-Z_]+) ([0-9]+)[ \t]+/([-*0-9a-zA-Z ']*)/" zip_h_err ${zip_h})
set(zip_err_str [=[
/*
@@ -213,9 +213,11 @@
SET_TARGET_PROPERTIES(zip PROPERTIES VERSION 5.2 SOVERSION 5)
ENDIF()
-
TARGET_LINK_LIBRARIES(zip PRIVATE ${ZLIB_LIBRARIES} ${OPTIONAL_LIBRARY})
+
INSTALL(TARGETS zip
+ EXPORT ${PROJECT_NAME}-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
diff --git a/libzip.cmake.in b/libzip.cmake.in
new file mode 100644
index 0000000..462439b
--- /dev/null
+++ b/libzip.cmake.in
@@ -0,0 +1,13 @@
+@PACKAGE_INIT@
+
+# Provide all our library targets to users.
+include("@PACKAGE_CMAKE_INSTALL_LIBDIR@/cmake/libzip/libzip-targets.cmake")
+
+get_filename_component(LIBZIP_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
+set(LIBZIP_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
+
+set(LIBZIP_LIBRARIES zip)
+set(ZIPCMP_EXECUTABLE zipcmp)
+#set_and_check(ZIPCMP_EXECUTABLE "@PACKAGE_CMAKE_INSTALL_BINDIR@/zipcmp")
+check_required_components(libzip)
+
diff --git a/man/CMakeLists.txt b/man/CMakeLists.txt
index d0a46cb..e3b8dc0 100644
--- a/man/CMakeLists.txt
+++ b/man/CMakeLists.txt
@@ -103,16 +103,16 @@
FOREACH(MAN_PAGE ${MAN_PAGES})
STRING(REGEX REPLACE "[1-9]$" "${DOCUMENTATION_FORMAT}" SOURCE_FILE ${MAN_PAGE})
IF (DOCUMENTATION_FORMAT MATCHES "html")
- INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${MAN_PAGE} DESTINATION ${CMAKE_INSTALL_DOCDIR} RENAME ${SOURCE_FILE})
+ INSTALL(FILES ${PROJECT_BINARY_DIR}/man/${MAN_PAGE} DESTINATION ${CMAKE_INSTALL_DOCDIR} RENAME ${SOURCE_FILE})
ELSE()
STRING(REGEX REPLACE ".*(.)$" "man\\1" SUBDIR ${MAN_PAGE})
- INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${MAN_PAGE} DESTINATION ${CMAKE_INSTALL_MANDIR}/${SUBDIR})
+ INSTALL(FILES ${PROJECT_BINARY_DIR}/man/${MAN_PAGE} DESTINATION ${CMAKE_INSTALL_MANDIR}/${SUBDIR})
ENDIF()
# CONFIGURE_FILE does not find out about updates to the sources, and it does not provide a target
#CONFIGURE_FILE(${SOURCE_FILE} ${MAN_PAGE} COPYONLY)
ADD_CUSTOM_COMMAND(OUTPUT ${MAN_PAGE}
DEPENDS ${SOURCE_FILE}
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${MAN_PAGE}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/man/${SOURCE_FILE} ${PROJECT_BINARY_DIR}/man/${MAN_PAGE}
COMMENT "Preparing ${MAN_PAGE}"
)
@@ -121,18 +121,18 @@
STRING(REGEX REPLACE "[1-9]$" "mdoc" MDOC_FILE ${MAN_PAGE})
# html re-generation
- ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${HTML_FILE}
+ ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/man/${HTML_FILE}
DEPENDS ${MDOC_FILE}
- COMMAND ${CMAKE_COMMAND} -DIN=${MDOC_FILE} -DOUT=${HTML_FILE} -DDIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/update-html.cmake
+ COMMAND ${CMAKE_COMMAND} -DIN=${MDOC_FILE} -DOUT=${HTML_FILE} -DDIR=${PROJECT_SOURCE_DIR}/man -P ${PROJECT_SOURCE_DIR}/man/update-html.cmake
)
- LIST(APPEND UPDATEHTML ${CMAKE_CURRENT_SOURCE_DIR}/${HTML_FILE})
+ LIST(APPEND UPDATEHTML ${PROJECT_SOURCE_DIR}/man/${HTML_FILE})
# man re-generation
- ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${MAN_FILE}
+ ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/man/${MAN_FILE}
DEPENDS ${MDOC_FILE}
- COMMAND ${CMAKE_COMMAND} -DIN=${MDOC_FILE} -DOUT=${MAN_FILE} -DDIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/update-man.cmake
+ COMMAND ${CMAKE_COMMAND} -DIN=${MDOC_FILE} -DOUT=${MAN_FILE} -DDIR=${PROJECT_SOURCE_DIR}/man -P ${PROJECT_SOURCE_DIR}/man/update-man.cmake
)
- LIST(APPEND UPDATEMAN ${CMAKE_CURRENT_SOURCE_DIR}/${MAN_FILE})
+ LIST(APPEND UPDATEMAN ${PROJECT_SOURCE_DIR}/man/${MAN_FILE})
ENDFOREACH()
ADD_CUSTOM_TARGET(man ALL DEPENDS ${MAN_PAGES})
ADD_CUSTOM_TARGET(update-man DEPENDS ${UPDATEMAN})
@@ -144,14 +144,14 @@
SET(SOURCE ${CMAKE_MATCH_1})
SET(TARGET ${CMAKE_MATCH_2})
IF (DOCUMENTATION_FORMAT MATCHES "html")
- INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE}.3 DESTINATION ${CMAKE_INSTALL_DOCDIR} RENAME ${TARGET}.html)
+ INSTALL(FILES ${PROJECT_BINARY_DIR}/man/${SOURCE}.3 DESTINATION ${CMAKE_INSTALL_DOCDIR} RENAME ${TARGET}.html)
ELSE()
- INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE}.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 RENAME ${TARGET}.3)
+ INSTALL(FILES ${PROJECT_BINARY_DIR}/man/${SOURCE}.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 RENAME ${TARGET}.3)
ENDIF()
ENDIF()
ENDFOREACH()
ADD_CUSTOM_TARGET(update_zip_errors
- COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/make_zip_errors.sh ${CMAKE_SOURCE_DIR}/lib/zip.h ${CMAKE_CURRENT_SOURCE_DIR}/zip_errors.mdoc
- DEPENDS ${CMAKE_SOURCE_DIR}/lib/zip.h ${CMAKE_CURRENT_SOURCE_DIR}/zip_errors.mdoc
+ COMMAND sh ${PROJECT_SOURCE_DIR}/man/make_zip_errors.sh ${CMAKE_SOURCE_DIR}/lib/zip.h ${PROJECT_SOURCE_DIR}/man/zip_errors.mdoc
+ DEPENDS ${CMAKE_SOURCE_DIR}/lib/zip.h ${PROJECT_SOURCE_DIR}/man/zip_errors.mdoc
)
diff --git a/regress/CMakeLists.txt b/regress/CMakeLists.txt
index baaae0f..b895ab6 100644
--- a/regress/CMakeLists.txt
+++ b/regress/CMakeLists.txt
@@ -17,7 +17,7 @@
ADD_EXECUTABLE(can_clone_file can_clone_file.c)
-SET(ENV{srcdir} ${CMAKE_CURRENT_SOURCE_DIR})
+SET(ENV{srcdir} ${PROJECT_SOURCE_DIR}/regress)
FOREACH(PROGRAM ${TEST_PROGRAMS})
ADD_EXECUTABLE(${PROGRAM} ${PROGRAM}.c)
TARGET_LINK_LIBRARIES(${PROGRAM} zip)
@@ -43,15 +43,15 @@
#SET(CMAKE_MSVCIDE_RUN_PATH C:/projects/libzip/vstudio/zlib/installed/bin;C:/projects/libzip/vstudio/zlib/installed/lib;C:/projects/libzip/build/lib/Release)
ADD_CUSTOM_TARGET(cleanup
- COMMAND ${CMAKE_COMMAND} -DDIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cleanup.cmake
+ COMMAND ${CMAKE_COMMAND} -DDIR=${PROJECT_BINARY_DIR}/regress -P ${PROJECT_SOURCE_DIR}/regress/cleanup.cmake
)
ADD_CUSTOM_TARGET(testinput
ALL
VERBATIM
- COMMAND ${CMAKE_COMMAND} -E tar x ${CMAKE_CURRENT_SOURCE_DIR}/manyfiles-zip.zip
- COMMAND ${CMAKE_COMMAND} -E tar x ${CMAKE_CURRENT_SOURCE_DIR}/bigzero-zip.zip
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/manyfiles-zip.zip ${CMAKE_CURRENT_SOURCE_DIR}/bigzero-zip.zip
+ COMMAND ${CMAKE_COMMAND} -E tar x ${PROJECT_SOURCE_DIR}/regress/manyfiles-zip.zip
+ COMMAND ${CMAKE_COMMAND} -E tar x ${PROJECT_SOURCE_DIR}/regress/bigzero-zip.zip
+ DEPENDS ${PROJECT_SOURCE_DIR}/regress/manyfiles-zip.zip ${PROJECT_SOURCE_DIR}/regress/bigzero-zip.zip
)
SET_PROPERTY(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
@@ -210,12 +210,12 @@
string(REPLACE ";" "\\;" path "${path}")
FOREACH(CASE ${EXTRA_TESTS})
- ADD_TEST(NAME ${CASE} COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/runtest --bin-sub-directory $<CONFIG> ${CMAKE_CURRENT_SOURCE_DIR}/${CASE})
+ ADD_TEST(NAME ${CASE} COMMAND ${PERL_EXECUTABLE} ${PROJECT_BINARY_DIR}/regress/runtest --bin-sub-directory $<CONFIG> ${PROJECT_SOURCE_DIR}/regress/${CASE})
SET_TESTS_PROPERTIES(${CASE} PROPERTIES SKIP_RETURN_CODE 77)
SET_TESTS_PROPERTIES(${CASE} PROPERTIES ENVIRONMENT "PATH=${path}")
ENDFOREACH()
-INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/../lib ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_BINARY_DIR}/..)
+INCLUDE_DIRECTORIES(BEFORE ${PROJECT_SOURCE_DIR}/lib ${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR})
ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 59db62a..dff9619 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,4 @@
-INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/../lib ${CMAKE_CURRENT_BINARY_DIR}/..)
+INCLUDE_DIRECTORIES(BEFORE ${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR})
CHECK_FUNCTION_EXISTS(getopt HAVE_GETOPT)
IF(NOT HAVE_GETOPT)
@@ -7,12 +7,12 @@
ADD_EXECUTABLE(zipcmp zipcmp.c ${SRC_EXTRA_FILES})
TARGET_LINK_LIBRARIES(zipcmp zip ${FTS_LIB} ${ZLIB_LIBRARIES})
-INSTALL(TARGETS zipcmp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+INSTALL(TARGETS zipcmp EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
ADD_EXECUTABLE(zipmerge zipmerge.c ${SRC_EXTRA_FILES})
TARGET_LINK_LIBRARIES(zipmerge zip)
-INSTALL(TARGETS zipmerge RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+INSTALL(TARGETS zipmerge EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
ADD_EXECUTABLE(ziptool ziptool.c ${SRC_EXTRA_FILES})
TARGET_LINK_LIBRARIES(ziptool zip)
-INSTALL(TARGETS ziptool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+INSTALL(TARGETS ziptool EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})