diff --git a/CMakeLists.txt b/CMakeLists.txt index 508a4462..41da32f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,8 @@ project(xlnt_all) # This indicates to CMakeLists in subdirectories that they are part of a larger project set(COMBINED_PROJECT TRUE) -option(BUILD_DEPS "Set to ON to build zlib and cryptopp from source otherwise system libraries will be used for these" OFF) - # Library type -option(STATIC "Set to ON to build ${PROJECT_NAME} as a static library instead of a shared library" OFF) +option(STATIC "Set to ON to build xlnt as a static library instead of a shared library" OFF) # Optional components option(SAMPLES "Set to ON to build executable code samples (in ./samples)" OFF) @@ -28,11 +26,14 @@ if(BENCHMARKS) endif() find_package(PythonInterp) +find_package(CxxTest) -if(PYTHONINTERP_FOUND) +if(PYTHONINTERP_FOUND AND CXXTEST_FOUND) add_subdirectory(tests) -else() +elseif(NOT PYTHONINTERP_FOUND) message("Python couldn't be found in the current PATH but is required for building tests. Tests will be skipped for now.") +else() + message("CxxTest couldn't be found in the current PATH but is required for building tests. Tests will be skipped for now.") endif() add_subdirectory(source) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 450d35b1..99136e8e 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -11,9 +11,6 @@ set(PROJECT_DESCRIPTION "cross-platform user-friendly xlsx library for C++14") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../third-party") -find_package(ZLIB REQUIRED) -find_package(CryptoPP REQUIRED) - if(APPLE) option(FRAMEWORK "Set to ON to package dylib and headers into a .framework, OSX only" OFF) endif() @@ -127,16 +124,25 @@ else() endif() endif() -target_link_libraries(xlnt - PRIVATE ${CRYPTOPP_LIBRARY} - PRIVATE ${ZLIB_LIBRARY_RELEASE} - PRIVATE libstudxml) +add_dependencies(xlnt xlnt.third-party) -target_include_directories(xlnt - PUBLIC ${XLNT_INCLUDE_DIR} - PRIVATE ${XLNT_SOURCE_DIR} - PRIVATE ${ZLIB_INCLUDE_DIR} - PRIVATE ${CRYPTOPP_INCLUDE_DIR}) +target_link_libraries(xlnt PRIVATE libstudxml) +target_include_directories(xlnt PUBLIC ${XLNT_INCLUDE_DIR}) +target_include_directories(xlnt PRIVATE ${XLNT_SOURCE_DIR}) + +if(LOCAL_ZLIB OR LOCAL_DEPENDENCIES) + target_link_libraries(xlnt PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third-party/zlib/zlib-download-prefix/src/zlib-download-build/libz.a) +else() + target_link_libraries(xlnt PRIVATE ${ZLIB_LIBRARY_RELEASE}) + target_include_directories(xlnt PRIVATE ${ZLIB_INCLUDE_DIR}) +endif() + +if(LOCAL_CRYPTOPP OR LOCAL_DEPENDENCIES) + target_link_libraries(xlnt PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third-party/cryptopp/cryptopp-download-prefix/src/cryptopp-download-build/libcryptopp.a) +else() + target_link_libraries(xlnt PRIVATE ${CRYPTOPP_LIBRARY_RELEASE}) + target_include_directories(xlnt PRIVATE ${CRYPTOPP_INCLUDE_DIR}) +endif() if(MSVC) set_target_properties(xlnt PROPERTIES COMPILE_FLAGS "/wd\"4251\" /wd\"4275\" /wd\"4068\" /MP") diff --git a/source/detail/zstream.hpp b/source/detail/zstream.hpp index 938b83b8..b1ae6473 100644 --- a/source/detail/zstream.hpp +++ b/source/detail/zstream.hpp @@ -49,7 +49,7 @@ namespace detail { /// A structure representing the header that occurs before each compressed file in a ZIP /// archive and again at the end of the file with more information. /// -struct zheader +struct XLNT_API zheader { std::uint16_t version = 20; std::uint16_t flags = 0; @@ -69,7 +69,7 @@ struct zheader /// Writes a series of uncompressed binary file data as ostreams into another ostream /// according to the ZIP format. /// -class ozstream +class XLNT_API ozstream { public: /// @@ -96,7 +96,7 @@ private: /// Reads an archive containing a number of files from an istream and allows them /// to be decompressed into an istream. /// -class izstream +class XLNT_API izstream { public: /// diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9841ba0e..3711a047 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,9 +8,6 @@ if(NOT COMBINED_PROJECT) add_subdirectory(${LIBRARY_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/source) endif() -find_package(CxxTest REQUIRED) -find_package(ZLIB REQUIRED) - file(GLOB CELL_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/cell/tests/test_*.hpp) file(GLOB CHARTS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/charts/tests/test_*.hpp) file(GLOB CHARTSHEET_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/chartsheet/tests/test_*.hpp) @@ -22,10 +19,6 @@ file(GLOB UTILS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/utils/tests/test_*.h file(GLOB WORKBOOK_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/workbook/tests/test_*.hpp) file(GLOB WORKSHEET_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/../source/worksheet/tests/test_*.hpp) -set(XLNT_ZIP - ${CMAKE_CURRENT_SOURCE_DIR}/../source/detail/zstream.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/../source/detail/zstream.hpp) - set(TESTS ${CELL_TESTS} ${CHARTS_TESTS} ${CHARTSHEET_TESTS} ${DRAWING_TESTS} ${FORMULA_TESTS} ${PACKAGING_TESTS} ${STYLES_TESTS} ${UTILS_TESTS} ${WORKBOOK_TESTS} ${WORKSHEET_TESTS}) @@ -43,10 +36,9 @@ if(COVERAGE) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov --coverage") endif() -add_executable(xlnt.test ${TEST_HELPERS} ${TESTS} ${RUNNER} ${XLNT_ZIP}) +add_executable(xlnt.test ${TEST_HELPERS} ${TESTS} ${RUNNER}) target_link_libraries(xlnt.test - PRIVATE xlnt - PRIVATE ${ZLIB_LIBRARIES}) + PRIVATE xlnt) target_include_directories(xlnt.test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../source @@ -79,6 +71,7 @@ else() endif() find_package(PythonInterp REQUIRED) +find_package(CxxTest REQUIRED) add_custom_command(OUTPUT ${RUNNER} COMMAND ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE} --runner=ErrorPrinter -o ${RUNNER} ${TESTS} diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 2b3d8f05..11e1fa2e 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -1,11 +1,10 @@ cmake_minimum_required(VERSION 3.2) -project(program) +project(xlnt.third-party) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}") -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libstudxml) -if(BUILD_DEPS) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/zlib) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cryptopp) - add_dependencies(libstudxml zlib-download cryptopp-download) -endif() +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libstudxml) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cxxtest) + +add_custom_target(xlnt.third-party + DEPENDS libstudxml cxxtest-download) diff --git a/third-party/cryptopp/CMakeLists.txt b/third-party/cryptopp/CMakeLists.txt deleted file mode 100644 index 56ce025e..00000000 --- a/third-party/cryptopp/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(cryptopp) - -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -include(ExternalProject) -ExternalProject_Add(cryptopp-download - GIT_REPOSITORY https://github.com/weidai11/cryptopp - INSTALL_COMMAND "") - -set(CRYPTOPP_ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR}/cryptopp-download-prefix/src/cryptopp-download) -set(CRYPTOPP_INCLUDE_DIR ${CRYPTOPP_ROOT_DIR}) -set(CRYPTOPP_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/cryptopp-download-prefix/src/cryptopp-download-build) - -add_library(cryptopp STATIC IMPORTED) -set_property(TARGET cryptopp PROPERTY IMPORTED_LOCATION ${CRYPTOPP_BUILD_DIR}/libcryptopp.a) -add_dependencies(cryptopp cryptopp-download) - -if(NOT STATIC) - set_target_properties(cryptopp PROPERTIES POSITION_INDEPENDENT_CODE 1) -endif() diff --git a/third-party/cxxtest/CMakeLists.txt b/third-party/cxxtest/CMakeLists.txt index 8ab37b2e..18d27c62 100644 --- a/third-party/cxxtest/CMakeLists.txt +++ b/third-party/cxxtest/CMakeLists.txt @@ -7,8 +7,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) include(ExternalProject) ExternalProject_Add(cxxtest-download GIT_REPOSITORY https://github.com/CxxTest/cxxtest + CONFIGURE_COMMAND "" + BUILD_COMMAND "" INSTALL_COMMAND "") set(CXXTEST_ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR}/cxxtest-download-prefix/src/cxxtest-download) set(CXXTEST_INCLUDE_DIR ${CXXTEST_ROOT_DIR}) +set(CXXTEST_PYTHON_TESTGEN_EXECUTABLE ${CXXTEST_ROOT_DIR}/bin/cxxtestgen CACHE INTERNAL "" FORCE) diff --git a/third-party/libstudxml/CMakeLists.txt b/third-party/libstudxml/CMakeLists.txt index 857c3241..fea24c28 100644 --- a/third-party/libstudxml/CMakeLists.txt +++ b/third-party/libstudxml/CMakeLists.txt @@ -25,7 +25,7 @@ set(GENX ${LIBSTUDXML_ROOT_DIR}/xml/details/genx/genx.c ${LIBSTUDXML_ROOT_DIR}/xml/details/genx/genx.h) -if(BUILD_DEPS) +if(LOCAL_EXPAT OR LOCAL_DEPENDENCIES) set(EXPAT ${LIBSTUDXML_ROOT_DIR}/xml/details/expat/xmlparse.c ${LIBSTUDXML_ROOT_DIR}/xml/details/expat/xmlrole.c @@ -51,7 +51,7 @@ add_library(libstudxml STATIC ${LIBSTUDXML} ${GENX} ${EXPAT}) target_compile_definitions(libstudxml PUBLIC LIBSTUDXML_STATIC_LIB=1) target_include_directories(libstudxml PUBLIC ${LIBSTUDXML_ROOT_DIR}) -if(NOT BUILD_DEPS) +if(NOT LOCAL_EXPAT AND NOT LOCAL_DEPENDENCIES) find_package(EXPAT REQUIRED) target_compile_definitions(libstudxml PRIVATE LIBSTUDXML_EXTERNAL_EXPAT=1) target_link_libraries(libstudxml PRIVATE expat) diff --git a/third-party/zlib/CMakeLists.txt b/third-party/zlib/CMakeLists.txt deleted file mode 100644 index a009c9e1..00000000 --- a/third-party/zlib/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(zlib) - -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -include(ExternalProject) -ExternalProject_Add(zlib-download - GIT_REPOSITORY https://github.com/madler/zlib - INSTALL_COMMAND "") - -set(ZLIB_ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR}/zlib-download-prefix/src/zlib-download) -set(ZLIB_INCLUDE_DIR ${ZLIB_ROOT_DIR}) -set(ZLIB_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/zlib-download-prefix/src/zlib-download-build) - -add_library(zlib STATIC IMPORTED) -set_property(TARGET zlib PROPERTY IMPORTED_LOCATION ${ZLIB_BUILD_DIR}/libz.a) -add_dependencies(zlib zlib-download)