diff --git a/.github/workflows/cmake_actions.yml b/.github/workflows/cmake_actions.yml index 6f4eea9e..d974ab9a 100644 --- a/.github/workflows/cmake_actions.yml +++ b/.github/workflows/cmake_actions.yml @@ -36,13 +36,17 @@ jobs: sudo apt-get -y install libssl-dev - name: Configure CMake - working-directory: ${{ github.workspace }}/cmake - run: cmake .. -DBUILD_TESTS=ON ${{ matrix.cmake_flags }} -DCMAKE_BUILD_TYPE=Release + run: | + mkdir build + cd build + cmake .. -DBUILD_TESTS=ON ${{ matrix.cmake_flags }} -DCMAKE_BUILD_TYPE=Release - name: Build - working-directory: ${{ github.workspace }}/cmake - run: cmake --build . --config Release --parallel + run: | + cd build + cmake --build . --config Release --parallel - name: Test - working-directory: ${{ github.workspace }}/cmake - run: ctest -C Release -V + run: | + cd build + ctest -C Release -V diff --git a/.github/workflows/windows_build.yml b/.github/workflows/windows_build.yml index 98fe07f6..af60878c 100644 --- a/.github/workflows/windows_build.yml +++ b/.github/workflows/windows_build.yml @@ -11,8 +11,8 @@ jobs: matrix: cmake_flags: ["-DBUILD_EXAMPLES=ON -DBUILD_TESTS=ON", "-DUSE_DTOA_LIBRARY=ON -DBUILD_TESTS=ON", - #"-DUSE_SYSTEM_MINIZIP=ON -DBUILD_TESTS=ON", - #"-DUSE_SYSTEM_MINIZIP=ON -DUSE_OPENSSL_MD5=ON -DBUILD_TESTS=ON", + "-DUSE_SYSTEM_MINIZIP=ON -DBUILD_TESTS=ON", + "-DUSE_SYSTEM_MINIZIP=ON -DUSE_OPENSSL_MD5=ON -DBUILD_TESTS=ON", "-DUSE_OPENSSL_MD5=ON -DBUILD_TESTS=ON", ] @@ -33,7 +33,8 @@ jobs: working-directory: ${{env.GITHUB_WORKSPACE}} shell: cmd run: | - cd cmake + mkdir build + cd build call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" cmake .. -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_flags }} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -A x64 @@ -41,7 +42,7 @@ jobs: working-directory: ${{env.GITHUB_WORKSPACE}} shell: cmd run: | - cd cmake + cd build call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" cmake --build . --config Release @@ -49,6 +50,6 @@ jobs: working-directory: ${{env.GITHUB_WORKSPACE}} shell: cmd run: | - cd cmake - copy test\functional\src\Release\*.exe test\functional\src + cd build + copy test\functional\src\Release\*.* test\functional\src pytest -v test/functional diff --git a/.gitignore b/.gitignore index 773d015d..6c07a13d 100644 --- a/.gitignore +++ b/.gitignore @@ -54,11 +54,6 @@ third_party/zlib-1.2.8/minigzip third_party/zlib-1.2.8/minigzipsh third_party/zlib-1.2.8/zlib.pc -cmake -!cmake/FindMINIZIP.cmake -!cmake/FindPackage.cmake -!cmake/i686-toolchain.cmake - .vscode *zig-cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 99263ece..c9ceb6c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,9 +204,6 @@ endif() # ------------------------- # Configure the compilation # ------------------------- -if(NOT MSVC) - find_package(PkgConfig) -endif() if(USE_SYSTEM_MINIZIP) list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS USE_SYSTEM_MINIZIP) @@ -307,36 +304,25 @@ enable_language(CXX) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Set the zlib includes. -if(PKG_CONFIG_FOUND) - pkg_check_modules(ZLIB zlib) - list(APPEND LXW_PRIVATE_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS}) -endif() -if(NOT ZLIB_FOUND) - find_package(ZLIB "1.0" REQUIRED) - list(APPEND LXW_PRIVATE_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS}) -endif() +find_package(ZLIB "1.2.8" REQUIRED) +list(APPEND LXW_PRIVATE_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS}) # Set the minizip includes. if(USE_SYSTEM_MINIZIP) - if(PKG_CONFIG_FOUND) + if(MSVC) + find_package(MINIZIP NAMES unofficial-minizip REQUIRED) + set(MINIZIP_LIBRARIES unofficial::minizip::minizip) + else() + find_package(PkgConfig REQUIRED) pkg_check_modules(MINIZIP minizip) list(APPEND LXW_PRIVATE_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIRS}/..) endif() - if(NOT MINIZIP_FOUND) - find_package(MINIZIP "1.0" REQUIRED) - list(APPEND LXW_PRIVATE_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIRS}) - endif() endif() # Set the openssl includes. if(USE_OPENSSL_MD5) - if(PKG_CONFIG_FOUND) - pkg_check_modules(LIBCRYPTO libcrypto) - include_directories(${LIBCRYPTO_INCLUDE_DIRS}) - else() - find_package(OpenSSL REQUIRED) - include_directories(${OPENSSL_INCLUDE_DIR}) - endif() + find_package(OpenSSL REQUIRED) + include_directories(${OPENSSL_INCLUDE_DIR}) endif() # ---------------------------- @@ -398,25 +384,19 @@ add_library(${PROJECT_NAME} "") set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${SOVERSION}) target_sources(${PROJECT_NAME} PRIVATE ${LXW_SOURCES} PUBLIC ${LXW_HEADERS}) -if(ZLIB_LDFLAGS) - target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${ZLIB_LDFLAGS}) +target_link_libraries(${PROJECT_NAME} PRIVATE ZLIB::ZLIB) + +if(MINIZIP_LINK_LIBRARIES) + target_link_libraries(${PROJECT_NAME} PRIVATE ${MINIZIP_LINK_LIBRARIES}) else() - target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${ZLIB_LIBRARIES}) -endif() -if(MINIZIP_LDFLAGS) - target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${MINIZIP_LDFLAGS}) -else() - target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${MINIZIP_LIBRARIES}) -endif() -if(LIBCRYPTO_LDFLAGS) - target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${LIBCRYPTO_LDFLAGS}) -else() - target_link_libraries( - ${PROJECT_NAME} - LINK_PUBLIC ${LIB_CRYPTO} ${OPENSSL_CRYPTO_LIBRARY} - ) + target_link_libraries(${PROJECT_NAME} PRIVATE ${MINIZIP_LIBRARIES}) endif() +target_link_libraries( + ${PROJECT_NAME} + PRIVATE ${LIB_CRYPTO} ${OPENSSL_CRYPTO_LIBRARY} +) + target_compile_definitions( ${PROJECT_NAME} PRIVATE ${LXW_PRIVATE_COMPILE_DEFINITIONS} diff --git a/Makefile b/Makefile index 4fb2dd00..291d3e1c 100644 --- a/Makefile +++ b/Makefile @@ -126,7 +126,10 @@ test_cpp : all test_cmake : ifneq ($(findstring m32,$(CFLAGS)),m32) $(Q)$(MAKE) -C src clean - $(Q)cd cmake; cmake .. -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON; make clean; make; cp libxlsxwriter.a ../src/ + $(Q)mkdir -p build + $(Q)cd build + $(Q)cmake .. -DBUILD_TESTS=ON -DBUILD_EXAMPLES=ON + $(Q)make clean; make; cp libxlsxwriter.a ../src/ $(Q)cmake/xlsxwriter_unit $(Q)$(MAKE) -C test/functional/src $(Q)$(PYTEST) test/functional -v -k $(PYTESTFILES) diff --git a/cmake/FindMINIZIP.cmake b/cmake/FindMINIZIP.cmake deleted file mode 100644 index bef784f5..00000000 --- a/cmake/FindMINIZIP.cmake +++ /dev/null @@ -1,121 +0,0 @@ -# :copyright: (c) 2017 Alex Huszagh. -# :license: FreeBSD, see LICENSE.txt for more details. - -# FindMINIZIP -# ----------- -# -# Find MINIZIP include dirs and libraries -# -# Use this module by invoking find_package with the form:: -# -# find_package(MINIZIP -# [version] [EXACT] # Minimum or EXACT version e.g. 1.0.6 -# [REQUIRED] # Fail with error if MINIZIP is not found -# ) -# -# You may also set `MINIZIP_USE_STATIC_LIBS` to prefer static libraries -# to shared ones. -# -# If found, `MINIZIP_FOUND` will be set to true, and `MINIZIP_LIBRARIES` -# and `MINIZIP_INCLUDE_DIRS` will both be set. -# -# You may optionally set `MINIZIP_ROOT` to specify a custom root directory -# for the MINIZIP installation. -# - -include(CheckCXXSourceCompiles) -include(FindPackage) - -# PATHS -# ----- - -set(MINIZIP_SEARCH_PATHS) - -if(MINIZIP_ROOT) - list(APPEND MINIZIP_SEARCH_PATHS ${MINIZIP_ROOT}) -endif() - -if(WIN32) - list(APPEND ZLIB_SEARCH_PATHS - "$ENV{PROGRAMFILES}/minizip" - ) -endif() - -unset(MINIZIP_SYSTEM_ROOT) -unset(MINIZIP_CUSTOM_ROOT) -unset(MINIZIP_SEARCH_HKEY) - -# FIND -# ---- - -# INCLUDE DIRECTORY -SetSuffixes(MINIZIP) -foreach(search ${MINIZIP_SEARCH_PATHS}) - FIND_PATH(MINIZIP_INCLUDE_DIR - NAMES minizip/zip.h - PATHS ${search} - PATH_SUFFIXES include - ) -endforeach(search) - -if(NOT MINIZIP_INCLUDE_DIR) - FIND_PATH(MINIZIP_INCLUDE_DIR minizip/zip.h PATH_SUFFIXES include) -endif() - -# LIBRARY PATHS -set(MINIZIP_LIBRARY_NAMES minizip) -if(CMAKE_BUILD_TYPE MATCHES Debug) - list(APPEND MINIZIP_LIBRARY_NAMES minizipd) -endif() - -foreach(search ${MINIZIP_SEARCH_PATHS}) - FIND_LIBRARY(MINIZIP_LIBRARY - NAMES ${MINIZIP_LIBRARY_NAMES} - PATHS ${search} - PATH_SUFFIXES lib - ) -endforeach(search) - -if(NOT MINIZIP_LIBRARY) - FIND_LIBRARY(MINIZIP_LIBRARY NAMES ${MINIZIP_LIBRARY_NAMES} PATH_SUFFIXES lib) -endif() - -set(MINIZIP_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIR}) -set(MINIZIP_LIBRARIES ${MINIZIP_LIBRARY}) - -CheckFound(MINIZIP) -FindStaticLibs(MINIZIP) - -# VERSION -# ------- - -if(MINIZIP_FOUND) - file(STRINGS "${MINIZIP_INCLUDE_DIRS}/zlib.h" MINIZIP_VERSION_CONTENTS REGEX "version [0-9]+\\.[0-9]+(\\.[0-9]+)?") - string(REGEX REPLACE ".*version ([0-9]+)\\.[0-9]+" "\\1" MINIZIP_VERSION_MAJOR "${MINIZIP_VERSION_CONTENTS}") - string(REGEX REPLACE ".*version [0-9]+\\.([0-9]+)" "\\1" MINIZIP_VERSION_MINOR "${MINIZIP_VERSION_CONTENTS}") - set(MINIZIP_VERSION_PATCH 0) - - set(MINIZIP_VERSION_STRING "${MINIZIP_VERSION_MAJOR}.${MINIZIP_VERSION_MINOR}.${MINIZIP_VERSION_PATCH}") - set(MINIZIP_VERSION ${MINIZIP_VERSION_STRING}) - - MatchVersion(MINIZIP) -endif() - -# COMPILATION -# ----------- - -set(MINIZIP_CODE " -#include -int main(void) -{ - zip_fileinfo zipfile_info; - - return 0; -} -" -) - -if(MINIZIP_FOUND) - CheckCompiles(MINIZIP) -endif() -RequiredPackageFound(MINIZIP) diff --git a/cmake/FindPackage.cmake b/cmake/FindPackage.cmake deleted file mode 100644 index f9b381ef..00000000 --- a/cmake/FindPackage.cmake +++ /dev/null @@ -1,183 +0,0 @@ -# :copyright: (c) 2017 Alex Huszagh. -# :license: FreeBSD, see LICENSE.txt for more details. - -# FindPackage -# ----------- -# -# Macros and functions to help find packages. Do not invoke this module -# directly, it merely provides library definitions to be invoked -# by other find utilities. - -include(CheckCXXSourceCompiles) - - -# Return if the package name has previously been found -# -# Args: -# packageName Name of the package -# -# Example: -# ReturnFound(Iconv) -# -macro(ReturnFound packageName) - if(${packageName}_FOUND) - return() - endif() -endmacro(ReturnFound) - - -# Set the library extensions for a given package dependent on whether -# to search for static or dynamic libraries. -# -# Args: -# packageName Name of the package -# -# Example: -# SetSuffixes(IConv) -# -macro(SetSuffixes packageName) - if(${packageName}_USE_STATIC_LIBS) - if(MSVC) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - endif() - else() - if(WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a" ".dll" ".lib" ".a") - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a") - endif() - endif() -endmacro(SetSuffixes) - - -# Check if the package was found. -# -# Args: -# packageName Name of the package -# -# Example: -# CheckFound(IConv) -# -macro(CheckFound packageName) - if(${packageName}_INCLUDE_DIRS AND ${packageName}_LIBRARIES) - set(${packageName}_FOUND TRUE) - endif() -endmacro(CheckFound) - - -# Replace a dynamic library with a `.dll.a` extension with the corresponding -# library removing the `.dll`. -# -# Args: -# libraryName Variable name for path to found library -# -# Example: -# ReplaceDynamic(/mingw64/lib/libiconv.dll.a) -# -macro(ReplaceDynamic libraryName) - if(${libraryName} MATCHES ".dll.a") - string(REPLACE ".dll.a" ".a" static ${${libraryName}}) - if(EXISTS ${static}) - set(${libraryName} ${static}) - endif() - endif() -endmacro(ReplaceDynamic) - - -# Replace a dynamic libraries with the static variants, with integrity -# checks for the package. -# -# Args: -# packageName Name of the package -# -# Example: -# FindStaticLibs(IConv) -# -macro(FindStaticLibs packageName) - if(${packageName}_USE_STATIC_LIBS AND MSYS) - # convert `.dll.a` to `.a` - set(${packageName}_LIBRARY_SOURCE ${${packageName}_LIBRARIES}) - set(${packageName}_LIBRARIES "") - foreach(library ${${packageName}_LIBRARY_SOURCE}) - # replace each dynamic library with a single one - set(static_library ${library}) - ReplaceDynamic(static_library) - list(APPEND ${packageName}_LIBRARIES ${static_library}) - endforeach(library) - endif() -endmacro(FindStaticLibs) - - -# Checks if a suitable version for the found library was identified, -# if provided. The library can either force exact or inexact matching. -# -# Args: -# packageName Name of the package -# -# Example: -# MatchVersion(ICU) -# -macro(MatchVersion packageName) - if(${packageName}_FOUND AND ${packageName}_FIND_VERSION) - # MATCH VERSION - if(${packageName}_FIND_VERSION_EXACT) - # EXACT VERSION - if(${packageName}_FIND_VERSION VERSION_EQUAL ${packageName}_VERSION) - else() - set(${packageName}_FOUND FALSE) - endif() - else() - # GREATER THAN VERSION - if(${packageName}_VERSION VERSION_LESS ${packageName}_FIND_VERSION) - set(${packageName}_FOUND FALSE) - endif() - endif() - endif() -endmacro(MatchVersion) - - -# Check if a sample program compiles, if not, set the library to not found. -# -# Args: -# packageName Name of the package -# code String of simple program depending on the library -# -# Example: -# set(IConv_CODE "int main(int argc, char **argv){ return 0; }") -# CheckCompiles(IConv) -# -macro(CheckCompiles packageName) - # FLAGS - set(CMAKE_REQUIRED_INCLUDES ${${packageName}_INCLUDE_DIRS}) - set(CMAKE_REQUIRED_LIBRARIES ${${packageName}_LIBRARIES}) - - # COMPILATION - check_cxx_source_compiles("${${packageName}_CODE}" ${packageName}_COMPILES) - if(NOT ${${packageName}_COMPILES}) - set(${packageName}_FOUND FALSE) - message(SEND_ERROR "Cannot compile a simple ${packageName} program.") - endif() - -endmacro(CheckCompiles) - - -# Send an error if a required package was not found. Otherwise, if the -# package is found, report to the user it was identified. -# -# Args: -# packageName Name of the package -# -# Example: -# RequiredPackageFound(ICU) -# -macro(RequiredPackageFound packageName) - if(${packageName}_FOUND) - message("Found ${packageName}.") - else() - if(${packageName}_FIND_REQUIRED) - message(SEND_ERROR "Unable to find requested ${packageName} libraries.") - endif() - endif() -endmacro(RequiredPackageFound) diff --git a/cmake/i686-toolchain.cmake b/cmake/i686-toolchain.cmake deleted file mode 100644 index 864f2bff..00000000 --- a/cmake/i686-toolchain.cmake +++ /dev/null @@ -1,7 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_VERSION 1) -set(CMAKE_SYSTEM_PROCESSOR "i686") - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags") -set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32" CACHE STRING "asm flags") diff --git a/docs/src/getting_started.dox b/docs/src/getting_started.dox index 50d5fced..285c00d5 100644 --- a/docs/src/getting_started.dox +++ b/docs/src/getting_started.dox @@ -81,7 +81,8 @@ To see a verbose summary of the compilation steps use `V=1`: With CMake you can build the library as follows: - cd cmake # Or another sub-directory. + mkdir build # Or another sub-directory. + cd build cmake .. cmake --build . @@ -95,7 +96,8 @@ directory and try one of them out: make examples # or CMake: - cd cmake + mkdir build + cd build cmake .. -DBUILD_EXAMPLES=ON cmake --build . @@ -129,7 +131,8 @@ installation location but actually install to `./staging/usr/third_party`. With CMake you can install the library as follows: - cd cmake + mkdir build + cd build cmake .. cmake --build . --target install @@ -559,7 +562,8 @@ The compilation options would be used as follows: make examples USE_DTOA_LIBRARY=1 # CMake - cd cmake + mkdir build + cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON -DUSE_DTOA_LIBRARY=ON cmake --build . --config Release @@ -732,7 +736,8 @@ You can compile a universal binary with standard make as follows: Or with CMake: - cd cmake + mkdir build + cd build cmake .. -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" make @@ -762,7 +767,8 @@ be compiled without them by relying on external libraries as follows: make USE_OPENSSL_MD5=1 USE_SYSTEM_MINIZIP=1 USE_STANDARD_TMPFILE=1 # CMake: - cd cmake + mkdir build + cd build cmake .. -DUSE_OPENSSL_MD5=ON -DUSE_SYSTEM_MINIZIP=ON -DUSE_STANDARD_TMPFILE=ON cmake --build . diff --git a/docs/src/running_the_tests.dox b/docs/src/running_the_tests.dox index 83fa38c3..f958a2f8 100644 --- a/docs/src/running_the_tests.dox +++ b/docs/src/running_the_tests.dox @@ -80,7 +80,8 @@ Both functional and unit test can be run together: You can run the unit and functional tests via CMake as follows: - cd cmake + mkdir build + cd build cmake .. -DBUILD_TESTS=ON cmake --build . ctest -V