From dc28f0366aa5c9f423adeb9614ed6f5b31fdb3a0 Mon Sep 17 00:00:00 2001 From: Adrien Bertrand Date: Thu, 22 Aug 2024 17:18:11 +0200 Subject: [PATCH] full vcpkg test --- .cmake/FindIconv.cmake | 136 ------------ .cmake/configure_and_install_pc_file.cmake | 4 +- .cmake/create_targets_both_lib_types.cmake | 45 ++-- .cmake/try_static_libs.cmake | 95 --------- .github/workflows/build.linux.workflow.yml | 88 ++++---- .github/workflows/build.mac.workflow.yml | 92 ++++---- .github/workflows/build.windows.workflow.yml | 102 ++++----- CMakeLists.txt | 88 +++----- CMakePresets.json | 212 ++++++++++++++----- libticables/trunk/CMakeLists.txt | 33 ++- libticables/trunk/tests/CMakeLists.txt | 28 +-- libticalcs/trunk/CMakeLists.txt | 44 ++-- libticalcs/trunk/tests/CMakeLists.txt | 35 +-- libticonv/trunk/CMakeLists.txt | 12 +- libticonv/trunk/tests/CMakeLists.txt | 12 +- libtifiles/trunk/CMakeLists.txt | 20 +- libtifiles/trunk/tests/CMakeLists.txt | 12 +- tifileutil/CMakeLists.txt | 38 +--- vcpkg.json | 16 +- 19 files changed, 461 insertions(+), 651 deletions(-) delete mode 100644 .cmake/FindIconv.cmake delete mode 100644 .cmake/try_static_libs.cmake diff --git a/.cmake/FindIconv.cmake b/.cmake/FindIconv.cmake deleted file mode 100644 index 3d67d90e3..000000000 --- a/.cmake/FindIconv.cmake +++ /dev/null @@ -1,136 +0,0 @@ -# Copied from cmake 3.12's https://github.com/Kitware/CMake/blob/95646591d62966043f0bc25364211594adc8d963/Modules/FindIconv.cmake -# with modified include() statements to remove the parent path (just use the name). Everything else is the same. - -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -FindIconv ---------- - -This module finds the ``iconv()`` POSIX.1 functions on the system. -These functions might be provided in the regular C library or externally -in the form of an additional library. - -The following variables are provided to indicate iconv support: - -.. variable:: Iconv_FOUND - - Variable indicating if the iconv support was found. - -.. variable:: Iconv_INCLUDE_DIRS - - The directories containing the iconv headers. - -.. variable:: Iconv_LIBRARIES - - The iconv libraries to be linked. - -.. variable:: Iconv_IS_BUILT_IN - - A variable indicating whether iconv support is stemming from the - C library or not. Even if the C library provides `iconv()`, the presence of - an external `libiconv` implementation might lead to this being false. - -Additionally, the following :prop_tgt:`IMPORTED` target is being provided: - -.. variable:: Iconv::Iconv - - Imported target for using iconv. - -The following cache variables may also be set: - -.. variable:: Iconv_INCLUDE_DIR - - The directory containing the iconv headers. - -.. variable:: Iconv_LIBRARY - - The iconv library (if not implicitly given in the C library). - -.. note:: - On POSIX platforms, iconv might be part of the C library and the cache - variables ``Iconv_INCLUDE_DIR`` and ``Iconv_LIBRARY`` might be empty. - -#]=======================================================================] - -include(CMakePushCheckState) -if(CMAKE_C_COMPILER_LOADED) - include(CheckCSourceCompiles) -elseif(CMAKE_CXX_COMPILER_LOADED) - include(CheckCXXSourceCompiles) -else() - # If neither C nor CXX are loaded, implicit iconv makes no sense. - set(Iconv_IS_BUILT_IN FALSE) -endif() - -# iconv can only be provided in libc on a POSIX system. -# If any cache variable is already set, we'll skip this test. -if(NOT DEFINED Iconv_IS_BUILT_IN) - if(UNIX AND NOT DEFINED Iconv_INCLUDE_DIR AND NOT DEFINED Iconv_LIBRARY) - cmake_push_check_state(RESET) - # We always suppress the message here: Otherwise on supported systems - # not having iconv in their C library (e.g. those using libiconv) - # would always display a confusing "Looking for iconv - not found" message - set(CMAKE_FIND_QUIETLY TRUE) - # The following code will not work, but it's sufficient to see if it compiles. - # Note: libiconv will define the iconv functions as macros, so CheckSymbolExists - # will not yield correct results. - set(Iconv_IMPLICIT_TEST_CODE - " - #include - #include - int main() { - char *a, *b; - size_t i, j; - iconv_t ic; - ic = iconv_open(\"to\", \"from\"); - iconv(ic, &a, &i, &b, &j); - iconv_close(ic); - } - " - ) - if(CMAKE_C_COMPILER_LOADED) - check_c_source_compiles("${Iconv_IMPLICIT_TEST_CODE}" Iconv_IS_BUILT_IN) - else() - check_cxx_source_compiles("${Iconv_IMPLICIT_TEST_CODE}" Iconv_IS_BUILT_IN) - endif() - cmake_pop_check_state() - else() - set(Iconv_IS_BUILT_IN FALSE) - endif() -endif() - -if(NOT Iconv_IS_BUILT_IN) - find_path(Iconv_INCLUDE_DIR - NAMES "iconv.h" - DOC "iconv include directory") - set(Iconv_LIBRARY_NAMES "iconv" "libiconv") -else() - set(Iconv_INCLUDE_DIR "" CACHE FILEPATH "iconv include directory") - set(Iconv_LIBRARY_NAMES "c") -endif() - -find_library(Iconv_LIBRARY - NAMES ${Iconv_LIBRARY_NAMES} - DOC "iconv library (potentially the C library)") - -mark_as_advanced(Iconv_INCLUDE_DIR) -mark_as_advanced(Iconv_LIBRARY) - -include(FindPackageHandleStandardArgs) -if(NOT Iconv_IS_BUILT_IN) - find_package_handle_standard_args(Iconv REQUIRED_VARS Iconv_LIBRARY Iconv_INCLUDE_DIR) -else() - find_package_handle_standard_args(Iconv REQUIRED_VARS Iconv_LIBRARY) -endif() - -if(Iconv_FOUND) - set(Iconv_INCLUDE_DIRS "${Iconv_INCLUDE_DIR}") - set(Iconv_LIBRARIES "${Iconv_LIBRARY}") - if(NOT TARGET Iconv::Iconv) - add_library(Iconv::Iconv INTERFACE IMPORTED) - endif() - set_property(TARGET Iconv::Iconv PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${Iconv_INCLUDE_DIRS}") - set_property(TARGET Iconv::Iconv PROPERTY INTERFACE_LINK_LIBRARIES "${Iconv_LIBRARIES}") -endif() diff --git a/.cmake/configure_and_install_pc_file.cmake b/.cmake/configure_and_install_pc_file.cmake index 16c083e8a..b625af289 100644 --- a/.cmake/configure_and_install_pc_file.cmake +++ b/.cmake/configure_and_install_pc_file.cmake @@ -1,8 +1,8 @@ function(configure_and_install_pc_file name version) set(prefix "${CMAKE_INSTALL_PREFIX}") set(exec_prefix "\${prefix}") - set(libdir "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") - set(includedir "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") + set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") + set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") set(VERSION "${version}") configure_file(${name}.pc.in ${PROJECT_BINARY_DIR}/${name}.pc @ONLY) diff --git a/.cmake/create_targets_both_lib_types.cmake b/.cmake/create_targets_both_lib_types.cmake index 701a158de..e29fb2a2d 100644 --- a/.cmake/create_targets_both_lib_types.cmake +++ b/.cmake/create_targets_both_lib_types.cmake @@ -10,6 +10,18 @@ function(create_targets_both_lib_types basename) add_library(${lib_shared} SHARED $) add_library(${lib_static} STATIC $) + include(CheckIPOSupported) + check_ipo_supported(RESULT lto_supported OUTPUT error) + if(lto_supported) + set_target_properties(${lib_objlib} PROPERTIES + INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE + INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE + INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE + ) + else() + message(STATUS "IPO/LTO not supported: <${error}>") + endif() + # Internal deps foreach(idep ${ARGN}) add_dependencies(${lib_objlib} ${idep}_objlib) @@ -22,11 +34,19 @@ function(create_targets_both_lib_types basename) set(INTERNAL_DEP_INC_DIR ${PROJECT_SOURCE_DIR}/../../lib${idep}/trunk/src) endif() target_include_directories(${lib_objlib} PRIVATE ${INTERNAL_DEP_INC_DIR}) - if(TRY_STATIC_LIBS) - target_link_libraries(${lib_shared} "${INTERNAL_DEP_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${idep}${CMAKE_STATIC_LIBRARY_SUFFIX}") + if (WIN32 AND NOT VCPKG_TARGET_TRIPLET MATCHES "-static") + if (CMAKE_GENERATOR STREQUAL "Ninja Multi-Config") + target_link_libraries(${lib_shared} PRIVATE "${INTERNAL_DEP_LIB_DIR}/$") + else() + target_link_libraries(${lib_shared} PRIVATE "${INTERNAL_DEP_LIB_DIR}") + endif() + target_link_libraries(${lib_shared} PRIVATE ${idep}) else() - target_link_directories(${lib_shared} PRIVATE "${INTERNAL_DEP_LIB_DIR}") - target_link_libraries(${lib_shared} "${idep}") + if (CMAKE_GENERATOR STREQUAL "Ninja Multi-Config") + target_link_libraries(${lib_shared} PRIVATE "${INTERNAL_DEP_LIB_DIR}/$/${CMAKE_STATIC_LIBRARY_PREFIX}${idep}${CMAKE_STATIC_LIBRARY_SUFFIX}") + else() + target_link_libraries(${lib_shared} PRIVATE "${INTERNAL_DEP_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${idep}${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() endif() endforeach() @@ -46,23 +66,6 @@ function(create_targets_both_lib_types basename) # Defines target_compile_definitions(${lib_objlib} PRIVATE PACKAGE="${PROJECT_NAME}" VERSION="${PROJECT_VERSION}") - # CFLAGS and include dirs - if(TRY_STATIC_LIBS) - target_compile_options(${lib_objlib} PRIVATE ${DEPS_STATIC_CFLAGS}) - else() - target_compile_options(${lib_objlib} PRIVATE ${DEPS_CFLAGS}) - endif() - target_include_directories(${lib_objlib} PRIVATE src) - - # Link-related properties, flags... - if(TRY_STATIC_LIBS) - target_link_directories(${lib_shared} PRIVATE ${TRY_STATIC_DEPS_LIBSDIRS}) - target_link_libraries(${lib_shared} ${TRY_STATIC_DEPS_LDFLAGS_OTHER} ${TRY_STATIC_DEPS_LIBS}) - else() - target_link_directories(${lib_shared} PRIVATE ${DEPS_LIBRARY_DIRS}) - target_link_libraries(${lib_shared} ${DEPS_LDFLAGS_OTHER} ${DEPS_LIBRARIES}) - endif() - # Stuff to install and developer-related things install(TARGETS ${lib_shared} ${lib_static} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" diff --git a/.cmake/try_static_libs.cmake b/.cmake/try_static_libs.cmake deleted file mode 100644 index 4f984452d..000000000 --- a/.cmake/try_static_libs.cmake +++ /dev/null @@ -1,95 +0,0 @@ -macro(try_static_libs_if_needed) - if (TRY_STATIC_LIBS) - list(APPEND DEPS_LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") - list(APPEND DEPS_STATIC_LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") - if(APPLE) - list(APPEND DEPS_LIBRARY_DIRS "/usr/lib" "${CMAKE_OSX_SYSROOT}/usr/lib" "/opt/homebrew/opt" "/opt/homebrew/lib" "/usr/local/opt" "/usr/local/lib") - list(APPEND DEPS_STATIC_LIBRARY_DIRS "/opt/homebrew/lib" "/opt/homebrew/opt" "/usr/local/opt" "/usr/local/lib" "${CMAKE_OSX_SYSROOT}/usr/lib" ) - endif() - - list(REMOVE_DUPLICATES DEPS_STATIC_LDFLAGS_OTHER) - list(REMOVE_DUPLICATES DEPS_STATIC_LIBRARIES) - list(REMOVE_DUPLICATES DEPS_STATIC_LIBRARY_DIRS) - list(REMOVE_DUPLICATES DEPS_LIBRARY_DIRS) - - set(TRY_STATIC_DEPS_LIBS "") - set(TRY_STATIC_DEPS_LIBSDIRS "") - set(TRY_STATIC_DEPS_LDFLAGS_OTHER "") - - foreach(LIB_NAME ${DEPS_STATIC_LIBRARIES}) - set(LIB_NAME_FULL ${LIB_NAME}) - foreach(LIB_DIR ${DEPS_STATIC_LIBRARY_DIRS}) - if(NOT EXISTS ${LIB_DIR}) - continue() - endif() - # there's a weird libarchive/zlib issue with static on linux right now: - # /usr/lib/x86_64-linux-gnu/libarchive.a(archive_read_support_filter_gzip.o): undefined reference to symbol 'inflateEnd' - # /lib/x86_64-linux-gnu/libz.so.1: error adding symbols: DSO missing from command line - if(LIB_NAME STREQUAL "archive" AND CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") - message(WARNING "[GCC Linux] Skipping libarchive static lib search due to a linking issue, will fallback on the shared lib") - list(APPEND TRY_STATIC_DEPS_LIBS "${LIB_NAME}") - set(${LIB_NAME}_FOUND YES) - break() - endif() - # there are relocation issues when linking some libs on linux: - # /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libbz2.a(bzlib.o): relocation R_X86_64_PC32 against symbol `BZ2_crc32Table' - # /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libz.a(deflate.o): relocation R_X86_64_PC32 against symbol `z_errmsg' - # /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libusb-1.0.a(libusb_1_0_la-core.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' - # can not be used when making a shared object; recompile with -fPIC - if(LIB_NAME MATCHES "^(bz2|z|m|cairo|cairo-gobject|usb-1.0|png16|fontconfig|freetype|harfbuzz|harfbuzz-gobject|icu.+)$" AND CMAKE_SYSTEM_NAME STREQUAL "Linux") - message(WARNING "[Linux] Skipping '${LIB_NAME}' static lib search due to a linking issue, will fallback on the shared lib") - list(APPEND TRY_STATIC_DEPS_LIBS "${LIB_NAME}") - set(${LIB_NAME}_FOUND YES) - break() - endif() - set(LIB_FULLPATH "${LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}") - if(NOT EXISTS ${LIB_FULLPATH}) - set(LIB_FULLPATH "${LIB_DIR}/${LIB_NAME_FULL}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}-static${CMAKE_STATIC_LIBRARY_SUFFIX}") - endif() - if(NOT EXISTS ${LIB_FULLPATH}) - set(LIB_FULLPATH "${LIB_DIR}/lib${LIB_NAME_FULL}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}") - endif() - if(NOT EXISTS ${LIB_FULLPATH}) - if(LIB_NAME_FULL STREQUAL "bz2") - set(LIB_NAME_FULL "bzip2") - elseif(LIB_NAME_FULL STREQUAL "z") - set(LIB_NAME_FULL "zlib") - endif() - set(LIB_FULLPATH "${LIB_DIR}/${LIB_NAME_FULL}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}") - endif() - if(EXISTS ${LIB_FULLPATH}) - message("[Info] Found static lib '${LIB_NAME}' for '${PROJECT_NAME}': ${LIB_FULLPATH}") - list(APPEND TRY_STATIC_DEPS_LIBS ${LIB_FULLPATH}) - set(${LIB_NAME}_FOUND YES) - break() - endif() - endforeach() - if(NOT ${LIB_NAME}_FOUND) - message("[Warning] Could not find static nor shared lib '${LIB_NAME}' for '${PROJECT_NAME}'. Adding the lib directly anyway!") - list(APPEND TRY_STATIC_DEPS_LIBS "${LIB_NAME}") - set(${LIB_NAME}_FOUND YES) - endif() - endforeach() - list(REMOVE_DUPLICATES TRY_STATIC_DEPS_LIBS) - - # Lib dirs - foreach(LIB_DIR ${DEPS_LIBRARY_DIRS}) - if(EXISTS ${LIB_DIR}) - list(APPEND TRY_STATIC_DEPS_LIBSDIRS "${LIB_DIR}") - endif() - endforeach() - list(REMOVE_DUPLICATES TRY_STATIC_DEPS_LIBSDIRS) - - # Raw flags - if(APPLE) - list(APPEND TRY_STATIC_DEPS_LDFLAGS_OTHER "-pthread") - foreach(framework CoreFoundation Foundation Carbon Cocoa ApplicationServices AppKit IOKit Security) - if (DEPS_STATIC_LDFLAGS_OTHER MATCHES "${framework}") - list(APPEND TRY_STATIC_DEPS_LDFLAGS_OTHER "-framework ${framework}") - endif() - endforeach() - else() - list(APPEND TRY_STATIC_DEPS_LDFLAGS_OTHER "${DEPS_STATIC_LDFLAGS_OTHER}") - endif() - endif() -endmacro() diff --git a/.github/workflows/build.linux.workflow.yml b/.github/workflows/build.linux.workflow.yml index 30691c943..71c2868db 100644 --- a/.github/workflows/build.linux.workflow.yml +++ b/.github/workflows/build.linux.workflow.yml @@ -2,7 +2,7 @@ name: Build Linux on: push: - branches: [ master, experimental, experimental2 ] + branches: [ master, experimental, experimental2, fullvcpkg ] pull_request: branches: [ master, experimental, experimental2 ] release: @@ -10,60 +10,60 @@ on: jobs: build: - name: "Build: ${{ matrix.os }} - ${{ matrix.deps_type }} deps" + name: "Build: ${{ matrix.arch }} ${{ matrix.os }} - ${{ matrix.upload_suffix }}" runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - os: [ubuntu-22.04, ubuntu-20.04] - try_static_deps: ['OFF','ON'] + os: [ubuntu-20.04] + arch: [x64] + config: [Release] + statictype: [ON, OFF] include: - - try_static_deps: 'OFF' - deps_type: shared - - try_static_deps: 'ON' - deps_type: static + - statictype: ON + host_triplet: release + upload_suffix: static + - statictype: OFF + host_triplet: dynamic + upload_suffix: shared steps: - - name: Checkout Git Repo - uses: actions/checkout@v3 - with: - submodules: 'recursive' + - name: Checkout Git Repo + uses: actions/checkout@v3 + with: + submodules: 'recursive' - - name: workaround for default apt mirror connectivity issues - run: | - sudo sed -i 's/azure\.//' /etc/apt/sources.list + - name: workaround for default apt mirror connectivity issues + run: | + sudo sed -i 's/azure\.//' /etc/apt/sources.list - - name: Install dependencies - run: | - set -e - sudo add-apt-repository universe - sudo apt update - sudo apt install -y cmake ninja-build libarchive-dev libzstd-dev zlib1g-dev libusb-1.0-0-dev libglib2.0-dev gettext nettle-dev libacl1-dev liblzma-dev liblz4-dev libudev-dev libc6-dev + - name: Install dependencies + run: sudo apt install -y libudev-dev - - name: Build tilibs - run: | - set -e - mkdir prefix - prefixpath="$(pwd)/prefix" - mkdir build && cd build - cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DTRY_STATIC_LIBS=${{ matrix.try_static_deps }} -DCMAKE_INSTALL_PREFIX=${prefixpath} .. - cmake --build . --target all + - name: Install latest CMake + uses: lukka/get-cmake@a70f1cfa1857a3eecfe0d34962269e1b1e8be56c # latest as of 2024-08-08 - - name: Test tilibs - run: | - cd build - cmake --build . --target check + - name: Restore artifacts, or setup vcpkg (do not install any package) + uses: lukka/run-vcpkg@d87e7fac99f22776a4973d7e413921ea254c1fc9 # latest as of 2024-08-08 - - name: Install tilibs - run: | - cd build - cmake --build . --target install + - name: create install folder + run: | + mkdir -p "${{ github.workspace }}/tilibs.build/Linux-${{ matrix.arch }}/prefix" - - name: Prepare install folder for upload - run: mv prefix tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps + - name: Build tilibs ${{ matrix.config }} on Linux ${{ matrix.arch }} + uses: lukka/run-cmake@4b1adc1944be8367be9f4e08303ce49918db8e3c # latest as of 2024-08-08 + with: + cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' + configurePreset: 'Linux-${{ matrix.arch }}' + configurePresetAdditionalArgs: "['-DDEPS_RELEASE_ONLY=ON']" + buildPreset: 'Linux-${{ matrix.arch }}-${{ matrix.config }}' + env: + CMAKE_INSTALL_PREFIX_OVERRIDE: ${{ github.workspace }}/tilibs.build/Linux-${{ matrix.arch }}/prefix + VCPKG_DEFAULT_HOST_TRIPLET: ${{ matrix.arch }}-linux-${{ matrix.host_triplet }} + VCPKG_FORCE_SYSTEM_BINARIES: 1 - - name: Upload install folder - uses: actions/upload-artifact@v3 - with: - name: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps - path: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps/ + - name: Upload install folder + uses: actions/upload-artifact@v3 + with: + name: tilibs_${{ matrix.os }}_${{ matrix.upload_suffix }}Deps + path: ${{ github.workspace }}/tilibs.build/Linux-${{ matrix.arch }}/prefix diff --git a/.github/workflows/build.mac.workflow.yml b/.github/workflows/build.mac.workflow.yml index 0ef7fdf86..5bf1325a8 100644 --- a/.github/workflows/build.mac.workflow.yml +++ b/.github/workflows/build.mac.workflow.yml @@ -2,7 +2,7 @@ name: Build macOS on: push: - branches: [ master, experimental, experimental2 ] + branches: [ master, experimental, experimental2, fullvcpkg ] pull_request: branches: [ master, experimental, experimental2 ] release: @@ -10,61 +10,61 @@ on: jobs: build: - name: "Build: ${{ matrix.os }} - ${{ matrix.deps_type }} deps" + name: "Build: ${{ matrix.arch }} ${{ matrix.os }} - ${{ matrix.upload_suffix }}" runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [macos-12, macos-14] - try_static_deps: ['OFF','ON'] + config: [Release] + statictype: [ON, OFF] include: - - try_static_deps: 'OFF' - deps_type: shared - - try_static_deps: 'ON' - deps_type: static - - steps: - - name: Checkout Git Repo - uses: actions/checkout@v3 - with: - submodules: 'recursive' + - os: macos-12 + arch: x64 + - os: macos-14 + arch: arm64 + - statictype: ON + host_triplet: release + upload_suffix: static + - statictype: OFF + host_triplet: dynamic + upload_suffix: shared - - name: Install dependencies - run: | - set -e - brew install cmake ninja gettext libarchive glib libusb libiconv intltool expat bzip2 zlib + steps: + - name: Checkout Git Repo + uses: actions/checkout@v3 + with: + submodules: 'recursive' - # Workaround! - # libarchive.pc now has (lib)iconv in Requires.private, which doesn't work here - # See https://github.com/libarchive/libarchive/pull/1813 and other issues - - name: Fix libarchive pkg-config file - run: | - sudo sed -i '' -E '/^Requires.private: (lib)?iconv/d' $(brew --prefix libarchive)/lib/pkgconfig/libarchive.pc + - name: Install dependencies + run: | + brew install automake autoconf libtool python-setuptools + pip install -U setuptools - - name: Build tilibs - run: | - set -e - mkdir prefix - prefixpath="$(pwd)/prefix" - mkdir build && cd build - cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DTRY_STATIC_LIBS=${{ matrix.try_static_deps }} -DCMAKE_INSTALL_PREFIX=${prefixpath} .. - cmake --build . --target all + - name: Install latest CMake + uses: lukka/get-cmake@a70f1cfa1857a3eecfe0d34962269e1b1e8be56c # latest as of 2024-08-08 - - name: Test tilibs - run: | - cd build - cmake --build . --target check + - name: Restore artifacts, or setup vcpkg (do not install any package) + uses: lukka/run-vcpkg@d87e7fac99f22776a4973d7e413921ea254c1fc9 # latest as of 2024-08-08 - - name: Install tilibs - run: | - cd build - cmake --build . --target install + - name: create install folder + run: | + mkdir -p "${{ github.workspace }}/tilibs.build/Mac-${{ matrix.arch }}/prefix" - - name: Prepare install folder for upload - run: mv prefix tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps + - name: Build tilibs ${{ matrix.config }} on Mac ${{ matrix.arch }} + uses: lukka/run-cmake@4b1adc1944be8367be9f4e08303ce49918db8e3c # latest as of 2024-08-08 + with: + cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' + configurePreset: 'Mac-${{ matrix.arch }}' + configurePresetAdditionalArgs: "['-DDEPS_RELEASE_ONLY=ON']" + buildPreset: 'Mac-${{ matrix.arch }}-${{ matrix.config }}' + env: + CMAKE_INSTALL_PREFIX_OVERRIDE: ${{ github.workspace }}/tilibs.build/Mac-${{ matrix.arch }}/prefix + VCPKG_DEFAULT_HOST_TRIPLET: ${{ matrix.arch }}-osx-${{ matrix.host_triplet }} + VCPKG_FORCE_SYSTEM_BINARIES: 1 - - name: Upload install folder - uses: actions/upload-artifact@v3 - with: - name: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps - path: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps/ + - name: Upload install folder + uses: actions/upload-artifact@v3 + with: + name: tilibs_${{ matrix.os }}_${{ matrix.upload_suffix }}Deps + path: ${{ github.workspace }}/tilibs.build/Mac-${{ matrix.arch }}/prefix diff --git a/.github/workflows/build.windows.workflow.yml b/.github/workflows/build.windows.workflow.yml index 484d55076..70f15b6d4 100644 --- a/.github/workflows/build.windows.workflow.yml +++ b/.github/workflows/build.windows.workflow.yml @@ -2,7 +2,7 @@ name: Build Windows on: push: - branches: [ master, experimental, experimental2 ] + branches: [ master, experimental, experimental2, fullvcpkg ] pull_request: branches: [ master, experimental, experimental2 ] release: @@ -10,64 +10,52 @@ on: jobs: build: - name: "Build: ${{ matrix.arch }} - ${{ matrix.deps_type }} deps" - runs-on: windows-latest + name: "Build: ${{ matrix.arch }} ${{ matrix.os }} - ${{ matrix.upload_suffix }}" + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - arch: [x64] - config: [ReleaseDynamic,ReleaseStatic] - include: - - arch: x64 - arch_name: 64-bit - arch_suffix: "64" - - config: ReleaseDynamic - deps_type: shared - - config: ReleaseStatic - deps_type: static + os: [windows-latest] + arch: [x86,x64] + config: [Release] + upload_suffix: [static] steps: - - name: Checkout Git Repo - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Install latest CMake - uses: lukka/get-cmake@a70f1cfa1857a3eecfe0d34962269e1b1e8be56c # latest as of 2024-08-08 - - - name: Restore artifacts, or setup vcpkg (do not install any package) - uses: lukka/run-vcpkg@d87e7fac99f22776a4973d7e413921ea254c1fc9 # latest as of 2024-08-08 - with: - vcpkgGitCommitId: 'a993be073c6baea8674117f3eaed6e2d2486aaae' # latest as of 2024-08-20 - prependedCacheKey: '${{ matrix.deps_type }}Deps' - - - name: Create prefix folder - shell: cmd - run: mkdir prefix - - - name: Build tilibs - uses: lukka/run-cmake@4b1adc1944be8367be9f4e08303ce49918db8e3c # latest as of 2024-08-08 - with: - cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' - configurePreset: '${{ matrix.arch }}-${{ matrix.config }}' - buildPreset: '${{ matrix.arch }}-${{ matrix.config }}' - env: - VCPKG_FORCE_SYSTEM_BINARIES: 1 - CMAKE_INSTALL_PREFIX_OVERRIDE: '${{ github.workspace }}/prefix' - - - name: Install tilibs - uses: lukka/run-cmake@4b1adc1944be8367be9f4e08303ce49918db8e3c # latest as of 2024-08-08 - with: - cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' - buildPreset: '${{ matrix.arch }}-${{ matrix.config }}' - buildPresetAdditionalArgs: "['--target install']" - - - name: Prepare install folder for upload - shell: cmd - run: rename prefix tilibs_windows_${{ matrix.deps_type }}Deps - - - name: Upload install folder - uses: actions/upload-artifact@v3 - with: - name: tilibs_windows_${{ matrix.deps_type }}Deps - path: tilibs_windows_${{ matrix.deps_type }}Deps + - name: Remove Perl Strawberry installation + # Removes conflicting headers from include paths + run: | + Remove-Item -Recurse -Force C:/Strawberry + + - name: Checkout Git Repo + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Install latest CMake + uses: lukka/get-cmake@a70f1cfa1857a3eecfe0d34962269e1b1e8be56c # latest as of 2024-08-08 + + - name: Restore artifacts, or setup vcpkg (do not install any package) + uses: lukka/run-vcpkg@d87e7fac99f22776a4973d7e413921ea254c1fc9 # latest as of 2024-08-08 + + - name: create install folder + run: | + mkdir "${{ github.workspace }}/tilibs.build/Win-${{ matrix.arch }}/prefix" + + - name: Build tilibs ${{ matrix.config }} on Win ${{ matrix.arch }} + uses: lukka/run-cmake@4b1adc1944be8367be9f4e08303ce49918db8e3c # latest as of 2024-08-08 + with: + cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' + configurePreset: 'Win-${{ matrix.arch }}' + configurePresetAdditionalArgs: "['-DDEPS_RELEASE_ONLY=ON']" + buildPreset: 'Win-${{ matrix.arch }}-${{ matrix.config }}' + env: + CMAKE_INSTALL_PREFIX_OVERRIDE: ${{ github.workspace }}/tilibs.build/Win-${{ matrix.arch }}/prefix + VCPKG_DEFAULT_TRIPLET: ${{ matrix.arch }}-windows + VCPKG_DEFAULT_HOST_TRIPLET: x64-windows-static-release + VCPKG_FORCE_SYSTEM_BINARIES: 1 + + - name: Upload install folder + uses: actions/upload-artifact@v3 + with: + name: tilibs_${{ matrix.os }}-${{ matrix.arch }}_${{ matrix.upload_suffix }}Deps + path: ${{ github.workspace }}/tilibs.build/Win-${{ matrix.arch }}/prefix diff --git a/CMakeLists.txt b/CMakeLists.txt index 53ac514e4..1065e6c77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,10 +24,6 @@ project(tilibs C CXX) # # Notes: # - this has been succesfully tested on recent macOS, Linux, and Windows (with vcpkg). -# - The TRY_STATIC_LIBS CMake option will try to build the libs (both shared and static) using as many static -# dependent libraries as possible. -# Let's note however that there is currently not much advantage in building that way, using shared libs is preferred, -# but at least you have the choice to do whatever you want should you ever really need a static build (may be useful on Windows) # # In the future...: # - TODO: add support to build the ROM dumpers (will end up just launching the external tools...) @@ -47,9 +43,23 @@ if(CMAKE_INSTALL_PREFIX) message("CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") endif() +option(DEPS_RELEASE_ONLY "Build only release versions of vcpkg dependencies" OFF) +if(DEPS_RELEASE_ONLY) + if(NOT DEFINED VCPKG_TARGET_TRIPLET) + message(FATAL_ERROR "Must provide a VCPKG_TARGET_TRIPLET to set as release only") + endif() + if(NOT VCPKG_TARGET_TRIPLET MATCHES "-release$") + set(VCPKG_TARGET_TRIPLET "${VCPKG_TARGET_TRIPLET}-release") + message("Updated VCPKG_TARGET_TRIPLET to ${VCPKG_TARGET_TRIPLET}") + endif() +endif() + if(WIN32 AND VCPKG_TARGET_TRIPLET MATCHES "-static(-|$)" AND NOT VCPKG_TARGET_TRIPLET MATCHES "-md(-|$)") message("Using static MSVC runtime...") set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + if(MSVC) + add_link_options("/NODEFAULTLIB:LIBCMTD") + endif() endif() # Our modules @@ -62,38 +72,6 @@ endforeach() set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE) message(STATUS "Detected system: ${CMAKE_SYSTEM_NAME} - host processor: ${CMAKE_HOST_SYSTEM_PROCESSOR} - CXX_COMPILER: ${CMAKE_CXX_COMPILER_ID}") -if(CMAKE_BUILD_TYPE STREQUAL Release OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) - include(CheckIPOSupported) - check_ipo_supported(RESULT supported OUTPUT error) - if(supported) - message(STATUS "IPO/LTO enabled") - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) - else() - message(STATUS "IPO/LTO not supported: <${error}>") - endif() -else() - message("IPO/LTO not enabled because this is not a release build") -endif() - -option(TRY_STATIC_LIBS "Build using as many static libs as possible" OFF) -if (VCPKG_TARGET_TRIPLET MATCHES "-static") - if(NOT TRY_STATIC_LIBS) - message(WARNING "Setting TRY_STATIC_LIBS to ON anyway due to static vcpkg target") - set(TRY_STATIC_LIBS ON) - endif() -endif() - -if(TRY_STATIC_LIBS) - message("Will try to build as statically as possible...") - if(WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif() - # When we link statically, we don't want the dllimport stuff, so let's workaround that here - add_compile_definitions(TICALCS_EXPORTS TIFILES_EXPORTS TICONV_EXPORTS TICABLES_EXPORTS) -endif() - include(GNUInstallDirs) include(CheckSymbolExists) @@ -108,7 +86,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GLOBAL_COMPILE_FLAGS} -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=missing-prototypes") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GLOBAL_COMPILE_FLAGS}") # useful flags for debugging - set(GLOBAL_DEBUG_FLAGS "-fno-omit-frame-pointer -fsanitize=address,bounds -fsanitize-undefined-trap-on-error") + set(GLOBAL_DEBUG_FLAGS "-fno-omit-frame-pointer") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ") @@ -137,25 +115,18 @@ if(Intl_FOUND AND GETTEXT_FOUND) set(ENABLE_NLS 1) include_directories(${Intl_INCLUDE_DIR}) add_compile_definitions(ENABLE_NLS=1) - if(TRY_STATIC_LIBS) - # needed by __nl_find_msg in libintl.a(dcigettext.o)... - find_package(Iconv REQUIRED) - if(Iconv_FOUND AND NOT Iconv_IS_BUILT_IN) - include_directories(${Iconv_INCLUDE_DIRS}) - if(Iconv_LIBRARY_DIRS) - link_directories(${Iconv_LIBRARY_DIRS}) - endif() - link_libraries(${Iconv_LIBRARIES}) - endif() - else() - link_directories(${Intl_LIBRARY_DIRS}) - link_libraries(${Intl_LIBRARIES}) - endif() + link_directories(${Intl_LIBRARY_DIRS}) + link_libraries(${Intl_LIBRARIES}) else() message(WARNING "The Intl and GetText libs are needed for translations - Only English will be available") endif() set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}") +if(LINUX) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) +endif() + # Global defines add_compile_definitions(LOCALEDIR="${LOCALEDIR}") check_symbol_exists(ctime_r "time.h" HAVE_CTIME_R) @@ -180,20 +151,11 @@ add_definitions(-DHAVE_STRTOK_S=1) endif() # For libs finding +#set(ENV{PKG_CONFIG_PATH} "${LIB_DIR}/libarchive/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") +#message(FATAL_ERROR "PKG_CONFIG_PATH = $ENV{PKG_CONFIG_PATH}") +set(ENV{PKG_CONFIG_PATH} "") find_package(PkgConfig) -# Set manually when installed with Homebrew, see https://github.com/Homebrew/legacy-homebrew/issues/45891 -# Note: we can't do the same for libiconv because it exports libiconv_* symbols and not iconv_*, so we fallback on the non-static system lib... -if(APPLE) - set(BREW_LIB_PATHS "/opt/homebrew/lib" "/opt/homebrew/opt" "/usr/local/opt" "/usr/local/lib") - foreach(LIB_DIR ${BREW_LIB_PATHS}) - if(EXISTS "${LIB_DIR}/libarchive/lib/pkgconfig") - set(ENV{PKG_CONFIG_PATH} "${LIB_DIR}/libarchive/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") - break() - endif() - endforeach() -endif() - add_subdirectory(libticonv/trunk) add_subdirectory(libtifiles/trunk) add_subdirectory(libticables/trunk) diff --git a/CMakePresets.json b/CMakePresets.json index ac996d730..c69a82ad5 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,7 +9,7 @@ { "name": "ninja-vcpkg", "hidden": true, - "generator": "Ninja", + "generator": "Ninja Multi-Config", "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", "binaryDir": "${sourceDir}/tilibs.build/${presetName}", "installDir": "${sourceDir}/tilibs.build/${presetName}", @@ -21,6 +21,10 @@ "VCPKG_MANIFEST_INSTALL": { "type": "BOOL", "value": "True" + }, + "VCPKG_INSTALL_OPTIONS": { + "type": "STRING", + "value": "--allow-unsupported" } } }, @@ -31,89 +35,199 @@ "architecture": { "strategy": "external", "value": "x64" - }, + } + }, + { + "name": "ninja-vcpkg-x86", + "hidden": true, + "inherits": "ninja-vcpkg", + "architecture": { + "strategy": "external", + "value": "x86" + } + }, + { + "name": "ninja-vcpkg-arm64", + "hidden": true, + "inherits": "ninja-vcpkg", + "architecture": { + "strategy": "external", + "value": "arm64" + } + }, + { + "name": "win-only", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "mac-only", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "linux-only", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "Win-x64", + "inherits": [ "ninja-vcpkg-x64", "win-only" ], "cacheVariables": { - "TRY_STATIC_LIBS": { - "type": "BOOL", - "value": "OFF" - }, "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "x64-windows-release" + "value": "x64-windows-static" } } }, { - "name": "x64-Debug", - "inherits": "ninja-vcpkg-x64", + "name": "Win-x86", + "inherits": [ "ninja-vcpkg-x86", "win-only" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": { + "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "Debug" + "value": "x86-windows-static" } } }, { - "name": "x64-ReleaseStatic", - "inherits": "ninja-vcpkg-x64", + "name": "Mac-x64", + "inherits": [ "ninja-vcpkg-x64", "mac-only" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": { - "type": "STRING", - "value": "Release" - }, - "TRY_STATIC_LIBS": { - "type": "BOOL", - "value": "ON" - }, - "VCPKG_HOST_TRIPLET": { - "type": "STRING", - "value": "x64-windows-static-release" - }, "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "x64-windows-static-release" - }, - "VCPKG_INSTALL_OPTIONS": { - "type": "STRING", - "value": "--allow-unsupported" + "value": "x64-osx" } } }, { - "name": "x64-ReleaseDynamic", - "inherits": "ninja-vcpkg-x64", + "name": "Mac-arm64", + "inherits": [ "ninja-vcpkg-arm64", "mac-only" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": { + "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "Release" - }, - "TRY_STATIC_LIBS": { - "type": "BOOL", - "value": "ON" - }, - "VCPKG_HOST_TRIPLET": { + "value": "arm64-osx" + } + } + }, + { + "name": "Linux-x64", + "inherits": [ "ninja-vcpkg-x64", "linux-only" ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "x64-windows-release" - }, + "value": "x64-linux" + } + } + }, + { + "name": "Linux-x64-Dynamic", + "inherits": [ "ninja-vcpkg-x64", "linux-only" ], + "cacheVariables": { "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "x64-windows-release" + "value": "x64-linux-dynamic" } } } ], "buildPresets": [ { - "name": "x64-Debug", - "configurePreset": "x64-Debug" + "name": "Win-x64-Debug", + "configurePreset": "Win-x64", + "configuration": "Debug" + }, + { + "name": "Win-x64-RelWithDebInfo", + "configurePreset": "Win-x64", + "configuration": "RelWithDebInfo" + }, + { + "name": "Win-x64-Release", + "configurePreset": "Win-x64", + "configuration": "Release" + }, + { + "name": "Win-x86-Debug", + "configurePreset": "Win-x86", + "configuration": "Debug" + }, + { + "name": "Win-x86-RelWithDebInfo", + "configurePreset": "Win-x86", + "configuration": "RelWithDebInfo" + }, + { + "name": "Win-x86-Release", + "configurePreset": "Win-x86", + "configuration": "Release" + }, + { + "name": "Mac-x64-Debug", + "configurePreset": "Mac-x64", + "configuration": "Debug" + }, + { + "name": "Mac-x64-Release", + "configurePreset": "Mac-x64", + "configuration": "Release" + }, + { + "name": "Mac-arm64-Debug", + "configurePreset": "Mac-arm64", + "configuration": "Debug" + }, + { + "name": "Mac-arm64-RelWithDebInfo", + "configurePreset": "Mac-arm64", + "configuration": "RelWithDebInfo" + }, + { + "name": "Mac-arm64-Release", + "configurePreset": "Mac-arm64", + "configuration": "Release" + }, + { + "name": "Linux-x64-Debug", + "configurePreset": "Linux-x64", + "configuration": "Debug" + }, + { + "name": "Linux-x64-RelWithDebInfo", + "configurePreset": "Linux-x64", + "configuration": "RelWithDebInfo" + }, + { + "name": "Linux-x64-Release", + "configurePreset": "Linux-x64", + "configuration": "Release" + }, + { + "name": "Linux-x64-Dynamic-Debug", + "configurePreset": "Linux-x64-Dynamic", + "configuration": "Debug" }, { - "name": "x64-ReleaseStatic", - "configurePreset": "x64-ReleaseStatic" + "name": "Linux-x64-Dynamic-RelWithDebInfo", + "configurePreset": "Linux-x64-Dynamic", + "configuration": "RelWithDebInfo" }, { - "name": "x64-ReleaseDynamic", - "configurePreset": "x64-ReleaseDynamic" + "name": "Linux-x64-Dynamic-Release", + "configurePreset": "Linux-x64-Dynamic", + "configuration": "Release" } ] } diff --git a/libticables/trunk/CMakeLists.txt b/libticables/trunk/CMakeLists.txt index 964733225..9ebbc5936 100644 --- a/libticables/trunk/CMakeLists.txt +++ b/libticables/trunk/CMakeLists.txt @@ -43,21 +43,34 @@ if(WIN32) list(APPEND SRC_FILES "src/win64/rwp.c") endif() +# auto-creation of all targets with flags etc. +create_targets_both_lib_types(ticables2) + +if(APPLE) + find_library(IOKitFramework IOKit REQUIRED) + find_library(SecurityFramework Security REQUIRED) + target_link_libraries(ticables2_objlib PRIVATE ${IOKitFramework} ${SecurityFramework}) + target_link_libraries(ticables2_shared PRIVATE ${IOKitFramework} ${SecurityFramework}) +endif() + +if(LINUX) + target_link_libraries(ticables2_objlib PRIVATE Threads::Threads) +endif() + # external deps lookup if(WIN32) - pkg_check_modules(DEPS REQUIRED glib-2.0) - list(APPEND DEPS_LIBRARIES "libusb0") - list(APPEND DEPS_STATIC_LIBRARIES "libusb0") + find_library(LIBUSB0 NAMES libusb0.lib usb0 REQUIRED) + target_link_libraries(ticables2_objlib PRIVATE ${LIBUSB0}) + target_link_libraries(ticables2_shared PRIVATE ${LIBUSB0}) else() - pkg_check_modules(DEPS REQUIRED glib-2.0 libusb-1.0>=1.0.16) - # Needed for the .pc files configured in the function below. + pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.16) + target_link_libraries(ticables2_objlib PRIVATE PkgConfig::libusb) + target_link_libraries(ticables2_shared PRIVATE PkgConfig::libusb) set(TICABLES_LIBUSB_REQUIRES_PRIVATE "libusb-1.0") endif() - -try_static_libs_if_needed() - -# auto-creation of all targets with flags etc. -create_targets_both_lib_types(ticables2) +pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) +target_link_libraries(ticables2_objlib PRIVATE PkgConfig::glib) +target_link_libraries(ticables2_shared PRIVATE PkgConfig::glib) if(NOT WIN32) # additional internal defines diff --git a/libticables/trunk/tests/CMakeLists.txt b/libticables/trunk/tests/CMakeLists.txt index efc737306..5f938f98d 100644 --- a/libticables/trunk/tests/CMakeLists.txt +++ b/libticables/trunk/tests/CMakeLists.txt @@ -6,29 +6,17 @@ project(libticables2-tests add_executable(torture_ticables torture_ticables.c) add_executable(test_ticables_2 test_ticables_2.cc) -if(WIN32) - pkg_check_modules(DEPS REQUIRED glib-2.0) - list(APPEND DEPS_LIBRARIES "libusb0") - list(APPEND DEPS_STATIC_LIBRARIES "libusb0") -else() - pkg_check_modules(DEPS REQUIRED glib-2.0 libusb-1.0>=1.0.16) -endif() - foreach(tar torture_ticables test_ticables_2) - target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) - - target_include_directories(${tar} PRIVATE - ${PROJECT_SOURCE_DIR}/../src) - - if(TRY_STATIC_LIBS) - target_compile_options(${tar} PRIVATE ${DEPS_STATIC_CFLAGS}) - target_link_directories(${tar} PRIVATE ${TRY_STATIC_DEPS_LIBSDIRS}) - target_link_libraries(${tar} ${TRY_STATIC_DEPS_LDFLAGS_OTHER} ${TRY_STATIC_DEPS_LIBS} ticables2_objlib) + if(WIN32) + find_library(LIBUSB0 NAMES libusb0.lib usb0 REQUIRED) + target_link_libraries(${tar} PRIVATE ${LIBUSB0}) else() - target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) - target_link_directories(${tar} PRIVATE ${DEPS_LIBRARY_DIRS} ${PROJECT_BINARY_DIR}/..) - target_link_libraries(${tar} ${DEPS_LIBRARIES} ticables2_objlib) + pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.16) + target_link_libraries(${tar} PRIVATE PkgConfig::libusb) endif() + target_include_directories(${tar} PRIVATE ${PROJECT_SOURCE_DIR}/../src) + target_link_directories(${tar} PRIVATE ${PROJECT_BINARY_DIR}/..) + target_link_libraries(${tar} PRIVATE PkgConfig::glib ticables2_objlib) endforeach() set(builddirlibpaths "${PROJECT_BINARY_DIR}") diff --git a/libticalcs/trunk/CMakeLists.txt b/libticalcs/trunk/CMakeLists.txt index f523de461..21d68e83f 100644 --- a/libticalcs/trunk/CMakeLists.txt +++ b/libticalcs/trunk/CMakeLists.txt @@ -64,36 +64,30 @@ set(PUBLIC_HEADERS src/cmd68k.h src/calclabequipmentdata.h) -# external deps lookup -if(TRY_STATIC_LIBS) - # from libticables and libtifiles... - if(WIN32) - set(external_deps_if_static "libarchive") - else() - set(external_deps_if_static "libusb-1.0>=1.0.16" "libarchive") - endif() -endif() -pkg_check_modules(DEPS REQUIRED glib-2.0 ${external_deps_if_static}) -if(WIN32) - list(APPEND DEPS_LIBRARIES "libusb0") - list(APPEND DEPS_STATIC_LIBRARIES "libusb0") -endif() - -try_static_libs_if_needed() - # auto-creation of all targets with flags etc., alongside with internal deps create_targets_both_lib_types(ticalcs2 tifiles2 ticables2 ticonv) -set_target_properties(ticalcs2_shared PROPERTIES VERSION 13.0.3 SOVERSION 13) +if(LINUX) + target_link_libraries(ticalcs2_objlib PRIVATE Threads::Threads) +endif() -# there are relocation issues when linking BZip2 and zlib on linux: -# /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libbz2.a(bzlib.o): relocation R_X86_64_PC32 against symbol `BZ2_crc32Table' -# /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libz.a(deflate.o): relocation R_X86_64_PC32 against symbol `z_errmsg' -# can not be used when making a shared object; recompile with -fPIC -if(TRY_STATIC_LIBS AND NOT LINUX) - find_package(BZip2 REQUIRED) # Needed for some reason - target_link_libraries(ticalcs2_shared ${BZIP2_LIBRARIES}) +# external deps lookup +if(WIN32) + find_library(LIBUSB0 NAMES libusb0.lib usb0 REQUIRED) + target_link_libraries(ticalcs2_objlib PRIVATE ${LIBUSB0}) + target_link_libraries(ticalcs2_shared PRIVATE ${LIBUSB0}) +else() + pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.16) + target_link_libraries(ticalcs2_objlib PRIVATE PkgConfig::libusb) + target_link_libraries(ticalcs2_shared PRIVATE PkgConfig::libusb) endif() +pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) +find_package(ZLIB REQUIRED) # for libtifiles +find_package(LibArchive REQUIRED) # for libticables +target_link_libraries(ticalcs2_objlib PRIVATE ZLIB::ZLIB PkgConfig::glib LibArchive::LibArchive) +target_link_libraries(ticalcs2_shared PRIVATE ZLIB::ZLIB PkgConfig::glib LibArchive::LibArchive) + +set_target_properties(ticalcs2_shared PROPERTIES VERSION 13.0.3 SOVERSION 13) # Takes care of the i18n po/pot/gmo/mo files if(ENABLE_NLS) diff --git a/libticalcs/trunk/tests/CMakeLists.txt b/libticalcs/trunk/tests/CMakeLists.txt index 76fb29c39..2c6410b10 100644 --- a/libticalcs/trunk/tests/CMakeLists.txt +++ b/libticalcs/trunk/tests/CMakeLists.txt @@ -8,14 +8,21 @@ if(NOT WIN32) # not compatible for now add_executable(test_ticalcs_2 test_ticalcs_2.cc) endif() +# external deps lookup if(WIN32) - pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive) - list(APPEND DEPS_LIBRARIES "libusb0") - list(APPEND DEPS_STATIC_LIBRARIES "libusb0") + find_library(LIBUSB0 NAMES libusb0.lib usb0 REQUIRED) + target_link_libraries(torture_ticalcs PRIVATE ${LIBUSB0}) else() - pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive libusb-1.0>=1.0.16) - # Needed for the .pc files configured in the function below. - set(TICABLES_LIBUSB_REQUIRES_PRIVATE "libusb-1.0") + pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.16) + target_link_libraries(torture_ticalcs PRIVATE PkgConfig::libusb) + target_link_libraries(test_ticalcs_2 PRIVATE PkgConfig::libusb) +endif() +pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) +find_package(ZLIB REQUIRED) # for libtifiles +find_package(LibArchive REQUIRED) # for libticables +target_link_libraries(torture_ticalcs PRIVATE ZLIB::ZLIB PkgConfig::glib LibArchive::LibArchive) +if(NOT WIN32) # not compatible for now + target_link_libraries(test_ticalcs_2 PRIVATE ZLIB::ZLIB PkgConfig::glib LibArchive::LibArchive) endif() if(WIN32 AND NOT MINGW) @@ -35,11 +42,11 @@ foreach(tar torture_ticalcs test_ticalcs_2) if(Iconv_FOUND AND NOT Iconv_IS_BUILT_IN) target_include_directories(${tar} PRIVATE ${Iconv_INCLUDE_DIRS}) - target_link_libraries(${tar} ${Iconv_LIBRARIES}) + target_link_libraries(${tar} PRIVATE ${Iconv_LIBRARIES}) endif() if(GETOPT_LIB) - target_link_libraries(${tar} ${GETOPT_LIB}) + target_link_libraries(${tar} PRIVATE ${GETOPT_LIB}) endif() target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) @@ -50,15 +57,9 @@ foreach(tar torture_ticalcs test_ticalcs_2) ${PROJECT_SOURCE_DIR}/../../../libticables/trunk/src ${PROJECT_SOURCE_DIR}/../src) - if(TRY_STATIC_LIBS) - target_compile_options(${tar} PRIVATE ${DEPS_STATIC_CFLAGS}) - target_link_directories(${tar} PRIVATE ${TRY_STATIC_DEPS_LIBSDIRS}) - target_link_libraries(${tar} ${TRY_STATIC_DEPS_LDFLAGS_OTHER} ${TRY_STATIC_DEPS_LIBS} ticonv_objlib tifiles2_objlib ticables2_objlib ticalcs2_objlib) - else() - target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) - target_link_directories(${tar} PRIVATE ${DEPS_LIBRARY_DIRS} ${PROJECT_BINARY_DIR}/..) - target_link_libraries(${tar} ${DEPS_LIBRARIES} ticonv_objlib tifiles2_objlib ticables2_objlib ticalcs2_objlib) - endif() + target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) + target_link_directories(${tar} PRIVATE ${DEPS_LIBRARY_DIRS} ${PROJECT_BINARY_DIR}/..) + target_link_libraries(${tar} PRIVATE ${DEPS_LIBRARIES} ticonv_objlib tifiles2_objlib ticables2_objlib ticalcs2_objlib) endforeach() set(builddirlibpaths "${PROJECT_BINARY_DIR}/../../../libticonv/trunk:${PROJECT_BINARY_DIR}/../../../libtifiles/trunk:${PROJECT_BINARY_DIR}/../../../libticables/trunk:${PROJECT_BINARY_DIR}/..") diff --git a/libticonv/trunk/CMakeLists.txt b/libticonv/trunk/CMakeLists.txt index 222353bf0..30aa6dcf0 100644 --- a/libticonv/trunk/CMakeLists.txt +++ b/libticonv/trunk/CMakeLists.txt @@ -25,13 +25,17 @@ set(PUBLIC_HEADERS option(USE_ICONV "Use libiconv at runtime for libticonv (whether to link with the lib)" ON) # external deps lookup -pkg_check_modules(DEPS REQUIRED glib-2.0) - -try_static_libs_if_needed() +pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) # auto-creation of all targets with flags etc., alongside with internal deps create_targets_both_lib_types(ticonv) +if(LINUX) + target_link_libraries(ticonv_objlib PRIVATE Threads::Threads) +endif() +target_link_libraries(ticonv_objlib PRIVATE PkgConfig::glib) +target_link_libraries(ticonv_shared PRIVATE PkgConfig::glib) + set_target_properties(ticonv_shared PROPERTIES VERSION 9.0.4 SOVERSION 9) if(USE_ICONV) @@ -40,7 +44,7 @@ if(USE_ICONV) add_compile_definitions(USE_ICONV) if(Iconv_FOUND AND NOT Iconv_IS_BUILT_IN) target_include_directories(ticonv_objlib PRIVATE ${Iconv_INCLUDE_DIRS}) - target_link_libraries(ticonv_shared ${Iconv_LIBRARIES}) + target_link_libraries(ticonv_shared PRIVATE ${Iconv_LIBRARIES}) endif() endif() diff --git a/libticonv/trunk/tests/CMakeLists.txt b/libticonv/trunk/tests/CMakeLists.txt index 6a68db626..05cd6938a 100644 --- a/libticonv/trunk/tests/CMakeLists.txt +++ b/libticonv/trunk/tests/CMakeLists.txt @@ -22,15 +22,9 @@ foreach(tar torture_ticonv test_ticonv) target_include_directories(${tar} PRIVATE ${PROJECT_SOURCE_DIR}/../src) - if(TRY_STATIC_LIBS) - target_compile_options(${tar} PRIVATE ${DEPS_STATIC_CFLAGS}) - target_link_directories(${tar} PRIVATE ${TRY_STATIC_DEPS_LIBSDIRS}) - target_link_libraries(${tar} ${TRY_STATIC_DEPS_LDFLAGS_OTHER} ${TRY_STATIC_DEPS_LIBS} ticonv_objlib) - else() - target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) - target_link_directories(${tar} PRIVATE ${DEPS_LIBRARY_DIRS} ${PROJECT_BINARY_DIR}/..) - target_link_libraries(${tar} ${DEPS_LIBRARIES} ticonv_objlib) - endif() + target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) + target_link_directories(${tar} PRIVATE ${DEPS_LIBRARY_DIRS} ${PROJECT_BINARY_DIR}/..) + target_link_libraries(${tar} ${DEPS_LIBRARIES} ${DEPS_LDFLAGS_OTHER} ticonv_objlib) endforeach() set(builddirlibpaths "${PROJECT_BINARY_DIR}/..") diff --git a/libtifiles/trunk/CMakeLists.txt b/libtifiles/trunk/CMakeLists.txt index 2277c419b..b4daec520 100644 --- a/libtifiles/trunk/CMakeLists.txt +++ b/libtifiles/trunk/CMakeLists.txt @@ -50,22 +50,20 @@ set(PUBLIC_HEADERS src/typesxx.h) # external deps lookup -pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive) -try_static_libs_if_needed() +find_package(ZLIB REQUIRED) +find_package(LibArchive REQUIRED) +pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) # auto-creation of all targets with flags etc., alongside with internal deps create_targets_both_lib_types(tifiles2 ticonv) -set_target_properties(tifiles2_shared PROPERTIES VERSION 11.0.2 SOVERSION 11) - -# there are relocation issues when linking BZip2 and zlib on linux: -# /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libbz2.a(bzlib.o): relocation R_X86_64_PC32 against symbol `BZ2_crc32Table' -# /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libz.a(deflate.o): relocation R_X86_64_PC32 against symbol `z_errmsg' -# can not be used when making a shared object; recompile with -fPIC -if(TRY_STATIC_LIBS AND NOT LINUX) - find_package(BZip2 REQUIRED) # Needed for some reason - target_link_libraries(tifiles2_shared ${BZIP2_LIBRARIES}) +if(LINUX) + target_link_libraries(tifiles2_objlib PRIVATE Threads::Threads) endif() +target_link_libraries(tifiles2_objlib PRIVATE PkgConfig::glib ZLIB::ZLIB LibArchive::LibArchive) +target_link_libraries(tifiles2_shared PRIVATE PkgConfig::glib ZLIB::ZLIB LibArchive::LibArchive) + +set_target_properties(tifiles2_shared PROPERTIES VERSION 11.0.2 SOVERSION 11) # Takes care of the i18n po/pot/gmo/mo files if(ENABLE_NLS) diff --git a/libtifiles/trunk/tests/CMakeLists.txt b/libtifiles/trunk/tests/CMakeLists.txt index 27b3d87ee..cf258769e 100644 --- a/libtifiles/trunk/tests/CMakeLists.txt +++ b/libtifiles/trunk/tests/CMakeLists.txt @@ -25,15 +25,9 @@ foreach(tar torture_tifiles test_tifiles_2) ${PROJECT_SOURCE_DIR}/../../../libticonv/trunk/src ${PROJECT_SOURCE_DIR}/../src) - if(TRY_STATIC_LIBS) - target_compile_options(${tar} PRIVATE ${DEPS_STATIC_CFLAGS}) - target_link_directories(${tar} PRIVATE ${TRY_STATIC_DEPS_LIBSDIRS}) - target_link_libraries(${tar} ${TRY_STATIC_DEPS_LDFLAGS_OTHER} ${TRY_STATIC_DEPS_LIBS} ticonv_objlib tifiles2_objlib) - else() - target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) - target_link_directories(${tar} PRIVATE ${DEPS_LIBRARY_DIRS} ${PROJECT_BINARY_DIR}/..) - target_link_libraries(${tar} ${DEPS_LIBRARIES} ticonv_objlib tifiles2_objlib) - endif() + target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) + target_link_directories(${tar} PRIVATE ${DEPS_LIBRARY_DIRS} ${PROJECT_BINARY_DIR}/..) + target_link_libraries(${tar} ${DEPS_LIBRARIES} ticonv_objlib tifiles2_objlib) endforeach() set(builddirlibpaths "${PROJECT_BINARY_DIR}/../../../libticonv/trunk:${PROJECT_BINARY_DIR}/..") diff --git a/tifileutil/CMakeLists.txt b/tifileutil/CMakeLists.txt index 5ce637c51..0ac427e39 100644 --- a/tifileutil/CMakeLists.txt +++ b/tifileutil/CMakeLists.txt @@ -12,20 +12,15 @@ set(SRC_FILES src/main.cc) # external deps lookup -pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive) -add_executable(tifileutil ${SRC_FILES}) +find_package(LibArchive REQUIRED) +pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) -try_static_libs_if_needed() +add_executable(tifileutil ${SRC_FILES}) # Defines target_compile_definitions(tifileutil PRIVATE PACKAGE="TIFILEUTIL" PACKAGE_VERSION="${PROJECT_VERSION}") # CFLAGS and include dirs -if(TRY_STATIC_LIBS) - target_compile_options(tifileutil PRIVATE ${DEPS_STATIC_CFLAGS}) -else() - target_compile_options(tifileutil PRIVATE ${DEPS_CFLAGS}) -endif() target_include_directories(tifileutil PRIVATE src) if(USE_ICONV) @@ -40,28 +35,11 @@ target_include_directories(tifileutil PRIVATE ${CMAKE_SOURCE_DIR}/libtifiles/trunk/src) # Link-related properties, flags... -if(TRY_STATIC_LIBS) - add_dependencies(tifileutil ticonv_static tifiles2_static) - target_link_directories(tifileutil PRIVATE ${TRY_STATIC_DEPS_LIBSDIRS}) - target_link_libraries(tifileutil ${TRY_STATIC_DEPS_LDFLAGS_OTHER} ${TRY_STATIC_DEPS_LIBS} ticonv_objlib tifiles2_objlib) - if(Iconv_FOUND AND NOT Iconv_IS_BUILT_IN) - target_include_directories(tifileutil PRIVATE ${Iconv_INCLUDE_DIRS}) - if(Iconv_LIBRARY_DIRS) - target_link_directories(tifileutil PRIVATE ${Iconv_LIBRARY_DIRS}) - endif() - target_link_libraries(tifileutil ${Iconv_LIBRARIES}) - endif() - if(LINUX) - target_link_libraries(tifileutil ${CMAKE_DL_LIBS} -static-libgcc -static-libstdc++) - endif() -else() - add_dependencies(tifileutil ticonv_shared tifiles2_shared) - target_link_directories(tifileutil PRIVATE - ${DEPS_LIBRARY_DIRS} - ${CMAKE_BINARY_DIR}/libticonv/trunk - ${CMAKE_BINARY_DIR}/libtifiles/trunk) - target_link_libraries(tifileutil ${DEPS_LDFLAGS_OTHER} ${DEPS_LIBRARIES} ticonv_objlib tifiles2_objlib) -endif() +add_dependencies(tifileutil ticonv_shared tifiles2_shared) +target_link_directories(tifileutil PRIVATE + ${CMAKE_BINARY_DIR}/libticonv/trunk + ${CMAKE_BINARY_DIR}/libtifiles/trunk) +target_link_libraries(tifileutil PkgConfig::glib LibArchive::LibArchive ticonv_objlib tifiles2_objlib) # Takes care of the i18n po/pot/gmo/mo files if(ENABLE_NLS) diff --git a/vcpkg.json b/vcpkg.json index f1da5ea57..41e346687 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -4,16 +4,26 @@ "homepage": "https://github.com/debrouxl/tilibs", "description": "libs to transfer things from/to TI graphing calculators", "dependencies": [ - "bzip2", + "zlib", "pkgconf", { "name": "libarchive", "default-features": false }, "getopt", - "libusb-win32", + { + "name": "libusb", + "platform": "!windows" + }, + { + "name": "libusb-win32", + "platform": "windows" + }, "glib", - "gettext" + { + "name": "gettext", + "features": [ "tools" ] + } ], "builtin-baseline": "a993be073c6baea8674117f3eaed6e2d2486aaae" }