Я пытаюсь скомпилировать библиотеку с именем xlsxio , используя Cmake.Файл Cmake использует команду FIND_PACKAGE
для Zlib (или miniz).
Вместо этого я хочу разместить исходный код Zlib в качестве подкаталога и выполнить компиляцию из исходного кода, но я не могу в достаточной степени изменить файл xlsxio Cmakeчтобы сделать это.
У меня есть репозиторий xlsxio, и в него я поместил подкаталог zlib-1.2.11
.
Исходный файл xlsxio Cmake:
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(xlsxio)
# parameters
OPTION(BUILD_STATIC "Build static libraries" ON)
OPTION(BUILD_SHARED "Build shared libraries" ON)
OPTION(BUILD_TOOLS "Build tools" ON)
OPTION(BUILD_EXAMPLES "Build examples" ON)
OPTION(WITH_LIBZIP "Use libzip instead of Minizip" OFF)
OPTION(WITH_WIDE "Also build UTF-16 library (libxlsxio_readw)" OFF)
# conditions
IF(NOT BUILD_STATIC AND NOT BUILD_SHARED)
MESSAGE(FATAL_ERROR "Cannot build with both BUILD_STATIC and BUILD_SHARED disabled")
ENDIF()
# dependancies
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
IF(WITH_LIBZIP)
FIND_PACKAGE(LibZip REQUIRED)
SET(ANYZIP_INCLUDE_DIRS ${LIBZIP_INCLUDE_DIRS})
SET(ANYZIP_LIBRARIES ${LIBZIP_LIBRARIES})
SET(ANYZIP_DEF USE_LIBZIP)
ELSE()
FIND_PACKAGE(Minizip REQUIRED)
SET(ANYZIP_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIRS})
SET(ANYZIP_LIBRARIES ${MINIZIP_LIBRARIES})
SET(ANYZIP_DEF USE_MINIZIP)
ENDIF()
FIND_PACKAGE(EXPAT REQUIRED)
IF(WITH_WIDE)
FIND_LIBRARY(EXPATW_LIBRARY NAMES expatw)
ENDIF()
FIND_PACKAGE(Doxygen)
# build parameters
OPTION(BUILD_DOCUMENTATION "Create and install API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
#SET(CMAKE_CXX_FLAGS "-g -Wall")
#ADD_SUBDIRECTORY(src)
IF(NOT WIN32 AND NOT APPLE)
SET(THREADLIB "-pthread")
ENDIF()
INCLUDE_DIRECTORIES(include)
INCLUDE_DIRECTORIES(${ANYZIP_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIRS})
# build definitions
SET(ALLTARGETS)
SET(LINKTYPES)
IF(BUILD_STATIC)
LIST(APPEND LINKTYPES "STATIC")
ENDIF()
IF(BUILD_SHARED)
LIST(APPEND LINKTYPES "SHARED")
ENDIF()
FOREACH(LINKTYPE ${LINKTYPES})
ADD_LIBRARY(xlsxio_read_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF}")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_read)
TARGET_INCLUDE_DIRECTORIES(xlsxio_read_${LINKTYPE} PRIVATE lib)
TARGET_LINK_LIBRARIES(xlsxio_read_${LINKTYPE} ${ANYZIP_LIBRARIES} ${EXPAT_LIBRARIES})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_read_${LINKTYPE})
ADD_LIBRARY(xlsxio_write_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF}")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write)
TARGET_LINK_LIBRARIES(xlsxio_write_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_write_${LINKTYPE})
IF(WITH_WIDE)
ADD_LIBRARY(xlsxio_readw_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_readw)
TARGET_INCLUDE_DIRECTORIES(xlsxio_readw_${LINKTYPE} PRIVATE lib)
TARGET_LINK_LIBRARIES(xlsxio_readw_${LINKTYPE} ${ANYZIP_LIBRARIES} ${EXPATW_LIBRARY})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_readw_${LINKTYPE})
#ADD_LIBRARY(xlsxio_writew_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write_w)
#TARGET_LINK_LIBRARIES(xlsxio_writew_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
#SET(ALLTARGETS ${ALLTARGETS} xlsxio_writew_${LINKTYPE})
ENDIF()
SET(EXELINKTYPE ${LINKTYPE})
ENDFOREACH()
IF(BUILD_TOOLS)
ADD_EXECUTABLE(xlsxio_xlsx2csv src/xlsxio_xlsx2csv.c)
TARGET_LINK_LIBRARIES(xlsxio_xlsx2csv xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_xlsx2csv)
ADD_EXECUTABLE(xlsxio_csv2xlsx src/xlsxio_csv2xlsx.c)
TARGET_LINK_LIBRARIES(xlsxio_csv2xlsx xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_csv2xlsx)
ENDIF()
IF(BUILD_EXAMPLES)
ADD_EXECUTABLE(example_xlsxio_write_getversion examples/example_xlsxio_write_getversion.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write_getversion xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write_getversion)
ADD_EXECUTABLE(example_xlsxio_write examples/example_xlsxio_write.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write)
ADD_EXECUTABLE(example_xlsxio_read examples/example_xlsxio_read.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read)
ADD_EXECUTABLE(example_xlsxio_read_advanced examples/example_xlsxio_read_advanced.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read_advanced xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read_advanced)
IF(WITH_WIDE)
ADD_EXECUTABLE(example_xlsxio_readw examples/example_xlsxio_read.c)
SET_TARGET_PROPERTIES(example_xlsxio_readw PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE")
TARGET_LINK_LIBRARIES(example_xlsxio_readw xlsxio_readw_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_readw)
ENDIF()
ENDIF()
IF(BUILD_DOCUMENTATION)
IF(NOT DOXYGEN_FOUND)
MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.")
ENDIF()
ADD_CUSTOM_TARGET(doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile
#WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/man
DESTINATION .
)
#INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/html
# DESTINATION share/doc
#)
ENDIF()
# install definitions
INSTALL(TARGETS ${ALLTARGETS}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
INSTALL(DIRECTORY include/
DESTINATION include
FILES_MATCHING PATTERN "xlsxio*.h"
)
Я изменил это следующим образом:
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT(xlsxio)
# parameters
OPTION(BUILD_STATIC "Build static libraries" ON)
OPTION(BUILD_SHARED "Build shared libraries" OFF)
OPTION(BUILD_TOOLS "Build tools" ON)
OPTION(BUILD_EXAMPLES "Build examples" OFF)
OPTION(WITH_LIBZIP "Use libzip instead of Minizip" ON)
OPTION(WITH_WIDE "Also build UTF-16 library (libxlsxio_readw)" OFF)
# conditions
IF(NOT BUILD_STATIC AND NOT BUILD_SHARED)
MESSAGE(FATAL_ERROR "Cannot build with both BUILD_STATIC and BUILD_SHARED disabled")
ENDIF()
# dependancies
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
SET(ANYZIP_INCLUDE_DIRS zlib-1.2.11)
SET(ANYZIP_LIBRARIES zlib-1.2.11)
SET(ANYZIP_DEF USE_LIBZIP)
FIND_PACKAGE(EXPAT REQUIRED)
IF(WITH_WIDE)
FIND_LIBRARY(EXPATW_LIBRARY NAMES expatw)
ENDIF()
FIND_PACKAGE(Doxygen)
# build parameters
OPTION(BUILD_DOCUMENTATION "Create and install API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
#SET(CMAKE_CXX_FLAGS "-g -Wall")
#ADD_SUBDIRECTORY(src)
IF(NOT WIN32 AND NOT APPLE)
SET(THREADLIB "-pthread")
ENDIF()
INCLUDE_DIRECTORIES(include)
INCLUDE_DIRECTORIES(${ANYZIP_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIRS})
# build definitions
SET(ALLTARGETS)
SET(LINKTYPES)
IF(BUILD_STATIC)
LIST(APPEND LINKTYPES "STATIC")
ENDIF()
IF(BUILD_SHARED)
LIST(APPEND LINKTYPES "SHARED")
ENDIF()
FOREACH(LINKTYPE ${LINKTYPES})
ADD_LIBRARY(xlsxio_read_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF}")
SET_TARGET_PROPERTIES(xlsxio_read_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_read)
TARGET_INCLUDE_DIRECTORIES(xlsxio_read_${LINKTYPE} PRIVATE lib)
add_subdirectory(zlib-1.2.11)
TARGET_LINK_LIBRARIES(xlsxio_read_${LINKTYPE} zlib-1.2.11 ${EXPAT_LIBRARIES})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_read_${LINKTYPE})
ADD_LIBRARY(xlsxio_write_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "BUILD_XLSXIO;${ANYZIP_DEF}")
SET_TARGET_PROPERTIES(xlsxio_write_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write)
add_subdirectory(zlib-1.2.11)
TARGET_LINK_LIBRARIES(xlsxio_write_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_write_${LINKTYPE})
IF(WITH_WIDE)
ADD_LIBRARY(xlsxio_readw_${LINKTYPE} ${LINKTYPE} lib/xlsxio_read.c lib/xlsxio_read_sharedstrings.c)
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
SET_TARGET_PROPERTIES(xlsxio_readw_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_readw)
TARGET_INCLUDE_DIRECTORIES(xlsxio_readw_${LINKTYPE} PRIVATE lib)
add_subdirectory(zlib-1.2.11)
TARGET_LINK_LIBRARIES(xlsxio_readw_${LINKTYPE} ${ANYZIP_LIBRARIES} ${EXPATW_LIBRARY})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_readw_${LINKTYPE})
#ADD_LIBRARY(xlsxio_writew_${LINKTYPE} ${LINKTYPE} lib/xlsxio_write.c)
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES DEFINE_SYMBOL "BUILD_XLSXIO_DLL")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE;BUILD_XLSXIO;${ANYZIP_DEF}")
#SET_TARGET_PROPERTIES(xlsxio_writew_${LINKTYPE} PROPERTIES OUTPUT_NAME xlsxio_write_w)
#TARGET_LINK_LIBRARIES(xlsxio_writew_${LINKTYPE} ${ANYZIP_LIBRARIES} ${THREADLIB})
#SET(ALLTARGETS ${ALLTARGETS} xlsxio_writew_${LINKTYPE})
ENDIF()
SET(EXELINKTYPE ${LINKTYPE})
ENDFOREACH()
IF(BUILD_TOOLS)
ADD_EXECUTABLE(xlsxio_xlsx2csv src/xlsxio_xlsx2csv.c)
TARGET_LINK_LIBRARIES(xlsxio_xlsx2csv xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_xlsx2csv)
ADD_EXECUTABLE(xlsxio_csv2xlsx src/xlsxio_csv2xlsx.c)
TARGET_LINK_LIBRARIES(xlsxio_csv2xlsx xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} xlsxio_csv2xlsx)
ENDIF()
IF(BUILD_EXAMPLES)
ADD_EXECUTABLE(example_xlsxio_write_getversion examples/example_xlsxio_write_getversion.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write_getversion xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write_getversion)
ADD_EXECUTABLE(example_xlsxio_write examples/example_xlsxio_write.c)
TARGET_LINK_LIBRARIES(example_xlsxio_write xlsxio_write_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_write)
ADD_EXECUTABLE(example_xlsxio_read examples/example_xlsxio_read.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read)
ADD_EXECUTABLE(example_xlsxio_read_advanced examples/example_xlsxio_read_advanced.c)
TARGET_LINK_LIBRARIES(example_xlsxio_read_advanced xlsxio_read_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_read_advanced)
IF(WITH_WIDE)
ADD_EXECUTABLE(example_xlsxio_readw examples/example_xlsxio_read.c)
SET_TARGET_PROPERTIES(example_xlsxio_readw PROPERTIES COMPILE_DEFINITIONS "XML_UNICODE")
TARGET_LINK_LIBRARIES(example_xlsxio_readw xlsxio_readw_${EXELINKTYPE})
SET(ALLTARGETS ${ALLTARGETS} example_xlsxio_readw)
ENDIF()
ENDIF()
IF(BUILD_DOCUMENTATION)
IF(NOT DOXYGEN_FOUND)
MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.")
ENDIF()
ADD_CUSTOM_TARGET(doc ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile
#WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/man
DESTINATION .
)
#INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/html
# DESTINATION share/doc
#)
ENDIF()
# install definitions
INSTALL(TARGETS ${ALLTARGETS}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
INSTALL(DIRECTORY include/
DESTINATION include
FILES_MATCHING PATTERN "xlsxio*.h"
)
Cmake жалуется:
CMake Error at CMakeLists.txt:78 (add_subdirectory):
The binary directory
/Users/x/Documents/repos/xlsx-test/xlsxio/cmake-build-debug/zlib-1.2.11
is already used to build a source directory. It cannot be used to build
source directory
/Users/x/Documents/repos/xlsx-test/xlsxio/zlib-1.2.11
Specify a unique binary directory name.
Я потратил несколько часов, пробуя разные подходы, но безуспешно.Любая помощь будет оценена.Рабочий файл Cmake был бы находкой.Я могу использовать более высокую минимальную версию Cmake, если это поможет.