From 9571c57a0b166c19b80640295f4484f1c8eda7d1 Mon Sep 17 00:00:00 2001 From: Brecht Sanders Date: Wed, 1 Sep 2021 10:57:36 +0200 Subject: [PATCH] Changed CMakeLists.txt to generate .pc and .cmake files --- CMakeLists.txt | 37 +++++++++++++++++++--------------- template.pc.in | 13 ++++++++++++ templateConfig.cmake.in | 33 ++++++++++++++++++++++++++++++ templateConfigVersion.cmake.in | 12 +++++++++++ 4 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 template.pc.in create mode 100644 templateConfig.cmake.in create mode 100644 templateConfigVersion.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 3630123..ebd72ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ SET(XLSXIO_VER_MICRO ${CMAKE_MATCH_1}) SET(XLSXIO_VER "${XLSXIO_VER_MAJOR}.${XLSXIO_VER_MINOR}.${XLSXIO_VER_MICRO}") UNSET(DUMMYVAR) UNSET(VERFILE) +MESSAGE(STATUS "XLSX I/O library version: ${XLSXIO_VER}") # parameters OPTION(BUILD_STATIC "Build static libraries" ON) @@ -30,7 +31,7 @@ ELSE() ENDIF() SET(EXPAT_DIR "" CACHE PATH "Path to the Expat library") -# conditions +# check conditions IF(NOT BUILD_STATIC AND NOT BUILD_SHARED) MESSAGE(FATAL_ERROR "Cannot build with both BUILD_STATIC and BUILD_SHARED disabled") ENDIF() @@ -219,20 +220,24 @@ IF(MINGW AND BUILD_SHARED) ENDIF() ENDIF() -# generate pkg-config .pc files -IF (BUILD_PC_FILES) - STRING(REPLACE ";" " " LIBXLSXIO_WRITE_LIBS "${ANYZIP_LIBRARIES} ${THREADLIB}") - STRING(REGEX REPLACE "\([^ ]*\)[/\\]([^ /\\.]*).[^ ]*" "-L\\1 -l\\2" LIBXLSXIO_WRITE_LIBS "${LIBXLSXIO_WRITE_LIBS}") - CONFIGURE_FILE(libxlsxio_write.pc.in libxlsxio_write.pc @ONLY) - INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_write.pc" DESTINATION lib/pkgconfig) - STRING(REPLACE ";" " " LIBXLSXIO_READ_LIBS "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}") - STRING(REGEX REPLACE "\([^ ]*\)[/\\]([^ /\\.]*).[^ ]*" "-L\\1 -l\\2" LIBXLSXIO_READ_LIBS "${LIBXLSXIO_READ_LIBS}") - CONFIGURE_FILE(libxlsxio_read.pc.in libxlsxio_read.pc @ONLY) - INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_read.pc" DESTINATION lib/pkgconfig) - IF(WITH_WIDE) - STRING(REPLACE ";" " " LIBXLSXIO_READW_LIBS "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}") - STRING(REGEX REPLACE "\([^ ]*\)[/\\]([^ /\\.]*).[^ ]*" "-L\\1 -l\\2" LIBXLSXIO_READW_LIBS "${LIBXLSXIO_READW_LIBS}") - CONFIGURE_FILE(libxlsxio_readw.pc.in libxlsxio_readw.pc @ONLY) - INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxlsxio_readw.pc" DESTINATION lib/pkgconfig) +# generate .cmake and .pc files +MACRO(generate_and_install_config_files _NAME _DESC _LIBS _HEADER) + SET(XLSXIO_NAME "${_NAME}") + SET(XLSXIO_DESC "${_DESC}") + SET(XLSXIO_HEADER "${_HEADER}") + STRING(REGEX REPLACE "^lib\([^ ]*\)" "\\1" XLSXIO_LIB "${XLSXIO_NAME}") + STRING(REPLACE ";" " " XLSXIO_LDFLAGS "-l${XLSXIO_LIB} ${_LIBS}") + STRING(REGEX REPLACE "\([^ ]*\)[/\\]lib([^ /\\.]*).[^ ]*" "-L\\1 -l\\2" XLSXIO_LDFLAGS "${XLSXIO_LDFLAGS}") + CONFIGURE_FILE(templateConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}Config.cmake" @ONLY) + CONFIGURE_FILE(templateConfigVersion.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}ConfigVersion.cmake" @ONLY) + INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}ConfigVersion.cmake" DESTINATION cmake/) + IF (BUILD_PC_FILES) + CONFIGURE_FILE(template.pc.in "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}.pc" @ONLY) + INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${XLSXIO_NAME}.pc" DESTINATION lib/pkgconfig) ENDIF() +ENDMACRO() +generate_and_install_config_files("libxlsxio_write" "C library for writing .xlsx files" "${ANYZIP_LIBRARIES} ${THREADLIB}" "xlsxio_write.h") +generate_and_install_config_files("libxlsxio_read" "C library for writing .xlsx files" "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}" "xlsxio_read.h") +IF(WITH_WIDE) + generate_and_install_config_files("libxlsxio_readw" "C library for reading .xlsx files using wide characters" "${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES}" "xlsxio_read.h") ENDIF() diff --git a/template.pc.in b/template.pc.in new file mode 100644 index 0000000..f5c9593 --- /dev/null +++ b/template.pc.in @@ -0,0 +1,13 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: @XLSXIO_NAME@ +Version: @XLSXIO_VER@ +Description: @XLSXIO_DESC@ +URL: https://github.com/brechtsanders/xlsxio +#Requires: +Cflags: -I${includedir} +Libs: -L${libdir} @XLSXIO_LDFLAGS@ +#Libs.private: diff --git a/templateConfig.cmake.in b/templateConfig.cmake.in new file mode 100644 index 0000000..d52fa18 --- /dev/null +++ b/templateConfig.cmake.in @@ -0,0 +1,33 @@ +# cmake version configuration file for @XLSXIO_NAME@ +GET_FILENAME_COMPONENT(XLSXIOREAD_ROOT "${CMAKE_CURRENT_LIST_FILE}" PATH) + +FIND_LIBRARY( + @XLSXIO_LIB@_LIBRARY @XLSXIO_LIB@ + PATHS ${XLSXIOREAD_ROOT}/lib + PATH_SUFFIXES ${CMAKE_LIBRARY_ARCHITECTURE} + NO_DEFAULT_PATH + ) +IF(NOT @XLSXIO_LIB@_LIBRARY) + MESSAGE(FATAL_ERROR "cannot find @XLSXIO_LIB@ library in ${MUPARSERX_ROOT}/lib") +ENDIF() +SET(@XLSXIO_LIB@_LIBRARIES ${@XLSXIO_LIB@_LIBRARY} @XLSXIO_LDFLAGS@) + +FIND_PATH( + @XLSXIO_LIB@_INCLUDE_DIR @XLSXIO_HEADER@ + PATHS ${@XLSXIO_LIB@_ROOT}/include + NO_DEFAULT_PATH +) +IF(NOT @XLSXIO_LIB@_INCLUDE_DIR) + MESSAGE(FATAL_ERROR "cannot find @XLSXIO_LIB@ includes in ${@XLSXIO_LIB@_ROOT}/include/@XLSXIO_LIB@") +ENDIF() +SET(@XLSXIO_LIB@_INCLUDE_DIRS ${@XLSXIO_LIB@_INCLUDE_DIR}) + + + +#set(FOOBAR_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") + +## Our library dependencies (contains definitions for IMPORTED targets) +#if(NOT TARGET xlsxio_read_SHARED AND NOT FooBar_BINARY_DIR) +# include("${XLSXIOREAD_ROOT}/FooBarTargets.cmake") +#endif() + diff --git a/templateConfigVersion.cmake.in b/templateConfigVersion.cmake.in new file mode 100644 index 0000000..241a305 --- /dev/null +++ b/templateConfigVersion.cmake.in @@ -0,0 +1,12 @@ +# cmake version configuration file for @XLSXIO_NAME@ +set(PACKAGE_VERSION "@XLSXIO_VER@") + +# check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif()