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_lib_target_with_deps.cmake b/.cmake/create_lib_target_with_deps.cmake new file mode 100644 index 000000000..9ba64b053 --- /dev/null +++ b/.cmake/create_lib_target_with_deps.cmake @@ -0,0 +1,52 @@ +function(create_lib_target_with_deps lib) + add_library(${lib} ${SRC_FILES}) + + include(CheckIPOSupported) + check_ipo_supported(RESULT lto_supported OUTPUT error) + if(lto_supported) + set_target_properties(${lib} 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} ${idep}) + if(${idep} MATCHES "^(ti[a-z]+)2$") + set(INTERNAL_DEP_LIB_DIR ${PROJECT_BINARY_DIR}/../../lib${CMAKE_MATCH_1}/trunk) + set(INTERNAL_DEP_INC_DIR ${PROJECT_SOURCE_DIR}/../../lib${CMAKE_MATCH_1}/trunk/src) + else() + set(INTERNAL_DEP_LIB_DIR ${PROJECT_BINARY_DIR}/../../lib${idep}/trunk) + set(INTERNAL_DEP_INC_DIR ${PROJECT_SOURCE_DIR}/../../lib${idep}/trunk/src) + endif() + if(GEN_IS_MULTI_CONFIG) + set(INTERNAL_DEP_LIB_DIR "${INTERNAL_DEP_LIB_DIR}/$") + endif() + target_include_directories(${lib} PRIVATE ${INTERNAL_DEP_INC_DIR}) + if (BUILD_SHARED_LIBS) + target_link_directories(${lib} PRIVATE "${INTERNAL_DEP_LIB_DIR}") + target_link_libraries(${lib} PRIVATE ${idep}) + else() + target_link_libraries(${lib} PRIVATE "${INTERNAL_DEP_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${idep}${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() + endforeach() + + # Main properties + set_target_properties(${lib} PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}") + + # Defines + target_compile_definitions(${lib} PRIVATE PACKAGE="${PROJECT_NAME}" VERSION="${PROJECT_VERSION}") + + # Stuff to install and developer-related things + install(TARGETS ${lib} + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tilp2") + + configure_and_install_pc_file(${lib} ${PROJECT_VERSION}) +endfunction() diff --git a/.cmake/create_targets_both_lib_types.cmake b/.cmake/create_targets_both_lib_types.cmake deleted file mode 100644 index 701a158de..000000000 --- a/.cmake/create_targets_both_lib_types.cmake +++ /dev/null @@ -1,74 +0,0 @@ -function(create_targets_both_lib_types basename) - set(lib_objlib ${basename}_objlib) - set(lib_shared ${basename}_shared) - set(lib_static ${basename}_static) - - # Object target to unify source building for both (shared/static) real targets - add_library(${lib_objlib} OBJECT ${SRC_FILES}) - - # The two real targets - add_library(${lib_shared} SHARED $) - add_library(${lib_static} STATIC $) - - # Internal deps - foreach(idep ${ARGN}) - add_dependencies(${lib_objlib} ${idep}_objlib) - add_dependencies(${lib_shared} ${idep}_shared) - if(${idep} MATCHES "^(ti[a-z]+)2$") - set(INTERNAL_DEP_LIB_DIR ${PROJECT_BINARY_DIR}/../../lib${CMAKE_MATCH_1}/trunk) - set(INTERNAL_DEP_INC_DIR ${PROJECT_SOURCE_DIR}/../../lib${CMAKE_MATCH_1}/trunk/src) - else() - set(INTERNAL_DEP_LIB_DIR ${PROJECT_BINARY_DIR}/../../lib${idep}/trunk) - 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}") - else() - target_link_directories(${lib_shared} PRIVATE "${INTERNAL_DEP_LIB_DIR}") - target_link_libraries(${lib_shared} "${idep}") - endif() - endforeach() - - # Main properties - if(MSVC) - set(static_lib_output_name "${basename}-static") - else() - set(static_lib_output_name "${basename}") - endif() - set_target_properties(${lib_shared} PROPERTIES - OUTPUT_NAME ${basename} - PUBLIC_HEADER "${PUBLIC_HEADERS}") - set_target_properties(${lib_static} PROPERTIES - OUTPUT_NAME ${static_lib_output_name} - PUBLIC_HEADER "${PUBLIC_HEADERS}") - - # 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}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tilp2") - - configure_and_install_pc_file(${basename} ${PROJECT_VERSION}) -endfunction() 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/.cmake/vcpkg_overlay_triplets/x64-linux-dynamic-release.cmake b/.cmake/vcpkg_overlay_triplets/x64-linux-dynamic-release.cmake new file mode 100644 index 000000000..a317a8a6f --- /dev/null +++ b/.cmake/vcpkg_overlay_triplets/x64-linux-dynamic-release.cmake @@ -0,0 +1,8 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) + +set(VCPKG_CMAKE_SYSTEM_NAME Linux) +set(VCPKG_BUILD_TYPE release) + +set(VCPKG_FIXUP_ELF_RPATH ON) \ No newline at end of file diff --git a/.cmake/vcpkg_overlay_triplets/x86-windows-static-release.cmake b/.cmake/vcpkg_overlay_triplets/x86-windows-static-release.cmake new file mode 100644 index 000000000..b4c73deca --- /dev/null +++ b/.cmake/vcpkg_overlay_triplets/x86-windows-static-release.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE x86) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_BUILD_TYPE release) \ No newline at end of file diff --git a/.github/workflows/build.linux.workflow.yml b/.github/workflows/build.linux.workflow.yml index 30691c943..a7b93845c 100644 --- a/.github/workflows/build.linux.workflow.yml +++ b/.github/workflows/build.linux.workflow.yml @@ -10,60 +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: [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 + preset_suffix: "" + upload_suffix: static + - statictype: OFF + preset_suffix: "-Dynamic" + upload_suffix: shared steps: - - name: Checkout Git Repo - uses: actions/checkout@v3 - with: - submodules: 'recursive' + - name: Checkout Git Repo + uses: actions/checkout@v4 + 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 and install 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 }}${{ matrix.preset_suffix }}' + configurePresetAdditionalArgs: "['-DDEPS_RELEASE_ONLY=ON']" + buildPreset: 'Linux-${{ matrix.arch }}${{ matrix.preset_suffix }}-${{ matrix.config }}' + buildPresetAdditionalArgs: "['--target', 'check', 'install']" + env: + CMAKE_INSTALL_PREFIX_OVERRIDE: ${{ github.workspace }}/tilibs.build/Linux-${{ matrix.arch }}/prefix + VCPKG_DEFAULT_HOST_TRIPLET: ${{ matrix.arch }}-linux-release + 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@v4 + with: + name: tilibs_${{ matrix.os }}-${{ matrix.arch }}_${{ 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 611f75363..abf919b7c 100644 --- a/.github/workflows/build.mac.workflow.yml +++ b/.github/workflows/build.mac.workflow.yml @@ -10,61 +10,55 @@ on: jobs: build: - name: "Build: ${{ matrix.os }} - ${{ matrix.deps_type }} deps" + name: "Build: ${{ matrix.arch }} ${{ matrix.os }}" runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - os: [macos-11, macos-12] - try_static_deps: ['OFF','ON'] + os: [macos-13, macos-14] + config: [Release] 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-13 + arch: x64 + - os: macos-14 + arch: arm64 - - 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@v4 + 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' /usr/local/opt/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 and install 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 }}' + buildPresetAdditionalArgs: "['--target', 'check', 'install']" + env: + CMAKE_INSTALL_PREFIX_OVERRIDE: ${{ github.workspace }}/tilibs.build/Mac-${{ matrix.arch }}/prefix + VCPKG_DEFAULT_HOST_TRIPLET: ${{ matrix.arch }}-osx-release + 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@v4 + with: + name: tilibs_${{ matrix.os }}-${{ matrix.arch }} + 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 553d8b9f7..2223d94ba 100644 --- a/.github/workflows/build.windows.workflow.yml +++ b/.github/workflows/build.windows.workflow.yml @@ -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 }}" + 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-2022] + arch: [x86,x64] + config: [Release] steps: - - name: Checkout Git Repo - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Install latest CMake - uses: lukka/get-cmake@9781783c006d9d607cb391b971a1dcbed768a25a # latest as of 2023-11-12 - - - name: Restore artifacts, or setup vcpkg (do not install any package) - uses: lukka/run-vcpkg@6fe69898af670ac05f4a8427cc5cff4fb361cee5 # latest as of 2023-11-12 - with: - vcpkgGitCommitId: '61f610845fb206298a69f708104a51d651872877' # latest as of 2023-11-12 - prependedCacheKey: '${{ matrix.deps_type }}Deps' - - - name: Create prefix folder - shell: cmd - run: mkdir prefix - - - name: Build tilibs - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # latest as of 2023-11-12 - 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@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # latest as of 2023-11-12 - 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@v4 + 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 and install 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 }}' + buildPresetAdditionalArgs: "['--target', 'check', 'install']" + 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@v4 + with: + name: tilibs_${{ matrix.os }}-${{ matrix.arch }} + path: ${{ github.workspace }}/tilibs.build/Win-${{ matrix.arch }}/prefix diff --git a/CMakeLists.txt b/CMakeLists.txt index f300ad1ee..55b3fe491 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,5 @@ cmake_minimum_required(VERSION 3.12) -project(tilibs C CXX) - ############################ # CMake support for tilibs # ############################ @@ -24,10 +22,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...) @@ -36,6 +30,8 @@ project(tilibs C CXX) # - WISH: provide Find* CMake modules for the libs themselves? # +get_property(GEN_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + # In case there was an env-var override... if(DEFINED ENV{CMAKE_INSTALL_PREFIX_OVERRIDE}) set(CMAKE_INSTALL_PREFIX "$ENV{CMAKE_INSTALL_PREFIX_OVERRIDE}") @@ -47,6 +43,28 @@ 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>") +endif() + +project(tilibs C CXX) + +option(BUILD_TESTS "Whether to build tests" ON) +option(BUILD_TIFILEUTIL "Whether to build the tifileutil tool" ON) +option(BUILD_SHARED_LIBS "Whether to build shared libs instead of static ones" ON) + # Our modules list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.cmake) file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/.cmake/*.cmake") @@ -57,38 +75,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) @@ -97,7 +83,10 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") +if(MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8 /D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /D_CRT_SECURE_NO_WARNINGS") +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") # sane defaults + hardening set(GLOBAL_COMPILE_FLAGS "-W -Wall -Wextra -Wno-unused-parameter -Werror=shadow -Werror=write-strings -Wredundant-decls -Werror=date-time -Werror=return-type -Werror=pointer-arith") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GLOBAL_COMPILE_FLAGS} -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=missing-prototypes") @@ -132,25 +121,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) @@ -168,35 +150,54 @@ if(HAVE_ASCTIME_R) add_compile_definitions(HAVE_ASCTIME_R=1) endif() if(HAVE_STRTOK_R) -add_definitions(-DHAVE_STRTOK_R=1) + add_definitions(-DHAVE_STRTOK_R=1) endif() if(HAVE_STRTOK_S) -add_definitions(-DHAVE_STRTOK_S=1) + add_definitions(-DHAVE_STRTOK_S=1) endif() -# For libs finding -find_package(PkgConfig) +if (NOT BUILD_SHARED_LIBS OR VCPKG_TARGET_TRIPLET MATCHES "-static" OR NOT VCPKG_TARGET_TRIPLET MATCHES "-dynamic") + # 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() -# 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" "/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() +# Don't mess up vcpkg libs finding +if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg" AND DEFINED VCPKG_TARGET_TRIPLET) + set(ENV{PKG_CONFIG_PATH} "") +else() + # 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_* + 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/include/archive.h") + set(LibArchive_INCLUDE_DIR "${LIB_DIR}/libarchive/include" CACHE INTERNAL "LibArchive_INCLUDE_DIR") + break() + endif() + endforeach() + endif() endif() +find_package(PkgConfig) add_subdirectory(libticonv/trunk) add_subdirectory(libtifiles/trunk) add_subdirectory(libticables/trunk) add_subdirectory(libticalcs/trunk) -add_subdirectory(tifileutil) -add_custom_target(check - DEPENDS ticonv_check tifiles2_check ticables2_check ticalcs2_check - COMMENT "Run all torture tests" - EXCLUDE_FROM_ALL -) +if(BUILD_TIFILEUTIL) + add_subdirectory(tifileutil) +endif() + +if(BUILD_TESTS) + add_custom_target(check + DEPENDS ticonv_check tifiles2_check ticables2_check ticalcs2_check + COMMENT "Run all torture tests" + EXCLUDE_FROM_ALL + ) +else() + add_custom_target(check + COMMAND ${CMAKE_COMMAND} -E echo "BUILD_TESTS was OFF, so no tests to run" + COMMENT "Run all torture tests" + EXCLUDE_FROM_ALL + ) +endif() diff --git a/CMakePresets.json b/CMakePresets.json index ac996d730..9980b77db 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,14 @@ "VCPKG_MANIFEST_INSTALL": { "type": "BOOL", "value": "True" + }, + "VCPKG_OVERLAY_TRIPLETS": { + "type": "STRING", + "value": "${sourceDir}/.cmake/vcpkg_overlay_triplets" + }, + "VCPKG_INSTALL_OPTIONS": { + "type": "STRING", + "value": "--allow-unsupported" } } }, @@ -31,89 +39,223 @@ "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" + }, + "BUILD_SHARED_LIBS": { + "type": "BOOL", + "value": "OFF" } } }, { - "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" + }, + "BUILD_SHARED_LIBS": { + "type": "BOOL", + "value": "OFF" } } }, { - "name": "x64-ReleaseStatic", - "inherits": "ninja-vcpkg-x64", + "name": "Mac-x64", + "inherits": [ "ninja-vcpkg-x64", "mac-only" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": { + "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "Release" + "value": "x64-osx" }, - "TRY_STATIC_LIBS": { + "BUILD_SHARED_LIBS": { "type": "BOOL", - "value": "ON" - }, - "VCPKG_HOST_TRIPLET": { + "value": "OFF" + } + } + }, + { + "name": "Mac-arm64", + "inherits": [ "ninja-vcpkg-arm64", "mac-only" ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "x64-windows-static-release" + "value": "arm64-osx" }, + "BUILD_SHARED_LIBS": { + "type": "BOOL", + "value": "OFF" + } + } + }, + { + "name": "Linux-x64", + "inherits": [ "ninja-vcpkg-x64", "linux-only" ], + "cacheVariables": { "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "x64-windows-static-release" + "value": "x64-linux" }, - "VCPKG_INSTALL_OPTIONS": { - "type": "STRING", - "value": "--allow-unsupported" + "BUILD_SHARED_LIBS": { + "type": "BOOL", + "value": "OFF" } } }, { - "name": "x64-ReleaseDynamic", - "inherits": "ninja-vcpkg-x64", + "name": "Linux-x64-Dynamic", + "inherits": [ "ninja-vcpkg-x64", "linux-only" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": { + "VCPKG_TARGET_TRIPLET": { "type": "STRING", - "value": "Release" + "value": "x64-linux-dynamic" }, - "TRY_STATIC_LIBS": { + "BUILD_SHARED_LIBS": { "type": "BOOL", "value": "ON" - }, - "VCPKG_HOST_TRIPLET": { - "type": "STRING", - "value": "x64-windows-release" - }, - "VCPKG_TARGET_TRIPLET": { - "type": "STRING", - "value": "x64-windows-release" } } } ], "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..a95774521 100644 --- a/libticables/trunk/CMakeLists.txt +++ b/libticables/trunk/CMakeLists.txt @@ -39,37 +39,49 @@ set(PUBLIC_HEADERS src/timeout.h) if(WIN32) - list(APPEND HEADER_FILES "src/win64/rwp.h") - list(APPEND SRC_FILES "src/win64/rwp.c") + list(APPEND HEADER_FILES "src/win64/rwp.h" "src/win32/dha.h") + list(APPEND SRC_FILES "src/win64/rwp.c" "src/win32/dha.c") 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") -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. +if(NOT WIN32) 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) +create_lib_target_with_deps(ticables2) + +if(APPLE) + find_library(IOKitFramework IOKit REQUIRED) + find_library(SecurityFramework Security REQUIRED) + target_link_libraries(ticables2 PRIVATE ${IOKitFramework} ${SecurityFramework}) +endif() + +if(LINUX) + target_link_libraries(ticables2 PRIVATE Threads::Threads) +endif() + +# external deps lookup +if(WIN32) + find_library(LIBUSB0 NAMES libusb0.lib usb0 REQUIRED) + target_link_libraries(ticables2 PRIVATE ${LIBUSB0}) +else() + pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.16) + target_link_libraries(ticables2 PRIVATE PkgConfig::libusb) +endif() +pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) +target_link_libraries(ticables2 PRIVATE PkgConfig::glib) if(NOT WIN32) # additional internal defines - target_compile_definitions(ticables2_objlib PUBLIC HAVE_LIBUSB_1_0=1 HAVE_LIBUSB10_STRERROR=1 HAVE_TERMIOS_H=1) + target_compile_definitions(ticables2 PUBLIC HAVE_LIBUSB_1_0=1 HAVE_LIBUSB10_STRERROR=1 HAVE_TERMIOS_H=1) endif() -set_target_properties(ticables2_shared PROPERTIES VERSION 8.0.0 SOVERSION 8) +set_target_properties(ticables2 PROPERTIES VERSION 8.0.0 SOVERSION 8) # Takes care of the i18n po/pot/gmo/mo files if(ENABLE_NLS) i18n_mo_from_po_pot() - add_dependencies(ticables2_objlib potfiles_2) + add_dependencies(ticables2 potfiles_2) endif() # check includes for parallel and serial support @@ -78,22 +90,24 @@ if(LINUX) CHECK_INCLUDE_FILE(linux/parport.h HAVE_LINUX_PARPORT_H) CHECK_INCLUDE_FILE(linux/serial.h HAVE_LINUX_SERIAL_H) if (HAVE_LINUX_PARPORT_H) - target_compile_definitions(ticables2_objlib PUBLIC HAVE_LINUX_PARPORT_H=1) + target_compile_definitions(ticables2 PUBLIC HAVE_LINUX_PARPORT_H=1) endif() if (HAVE_LINUX_SERIAL_H) - target_compile_definitions(ticables2_objlib PUBLIC HAVE_LINUX_SERIAL_H=1) + target_compile_definitions(ticables2 PUBLIC HAVE_LINUX_SERIAL_H=1) endif() endif() # public export define -target_compile_definitions(ticables2_objlib PUBLIC TICABLES_EXPORTS) +target_compile_definitions(ticables2 PUBLIC TICABLES_EXPORTS) option(ENABLE_LOGGING "Whether to build with cables logging enabled (default ON)" ON) if(ENABLE_LOGGING) - target_compile_definitions(ticables2_objlib PUBLIC ENABLE_LOGGING=1) + target_compile_definitions(ticables2 PUBLIC ENABLE_LOGGING=1) else() message("Building ${PROJECT_NAME} with logging disabled") endif() # tests -add_subdirectory(tests) +if (BUILD_TESTS) + add_subdirectory(tests) +endif() diff --git a/libticables/trunk/src/win32/dha.h b/libticables/trunk/src/win32/dha.h index 440ed918d..d8fb65ff8 100644 --- a/libticables/trunk/src/win32/dha.h +++ b/libticables/trunk/src/win32/dha.h @@ -22,9 +22,18 @@ #ifndef __DHA_H__ #define __DHA_H__ +#ifdef __cplusplus +extern "C" +{ +#endif + int dha_detect(int* result); int dha_enable(void); int dha_disable(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/libticables/trunk/tests/CMakeLists.txt b/libticables/trunk/tests/CMakeLists.txt index efc737306..fc8e52ba9 100644 --- a/libticables/trunk/tests/CMakeLists.txt +++ b/libticables/trunk/tests/CMakeLists.txt @@ -6,35 +6,21 @@ 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) endforeach() -set(builddirlibpaths "${PROJECT_BINARY_DIR}") - add_custom_target(ticables2_check - COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH="${builddirlibpaths}" ${CMAKE_CURRENT_BINARY_DIR}/torture_ticables + COMMAND "$" DEPENDS torture_ticables COMMENT "Run the ticables2 torture tests" EXCLUDE_FROM_ALL diff --git a/libticalcs/trunk/CMakeLists.txt b/libticalcs/trunk/CMakeLists.txt index f523de461..8be65c26e 100644 --- a/libticalcs/trunk/CMakeLists.txt +++ b/libticalcs/trunk/CMakeLists.txt @@ -64,45 +64,38 @@ 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) +create_lib_target_with_deps(ticalcs2 tifiles2 ticables2 ticonv) -set_target_properties(ticalcs2_shared PROPERTIES VERSION 13.0.3 SOVERSION 13) +if(LINUX) + target_link_libraries(ticalcs2 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 PRIVATE ${LIBUSB0}) +else() + pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0>=1.0.16) + target_link_libraries(ticalcs2 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 PRIVATE ZLIB::ZLIB PkgConfig::glib LibArchive::LibArchive) + +set_target_properties(ticalcs2 PROPERTIES VERSION 13.0.3 SOVERSION 13) # Takes care of the i18n po/pot/gmo/mo files if(ENABLE_NLS) i18n_mo_from_po_pot() - add_dependencies(ticalcs2_objlib potfiles_3) + add_dependencies(ticalcs2 potfiles_3) endif() # public export define -target_compile_definitions(ticalcs2_objlib PUBLIC TICALCS_EXPORTS) +target_compile_definitions(ticalcs2 PUBLIC TICALCS_EXPORTS) # tests -add_subdirectory(tests) +if (BUILD_TESTS) + add_subdirectory(tests) +endif() diff --git a/libticalcs/trunk/src/calc_nsp.cc b/libticalcs/trunk/src/calc_nsp.cc index 3813726c3..777200817 100644 --- a/libticalcs/trunk/src/calc_nsp.cc +++ b/libticalcs/trunk/src/calc_nsp.cc @@ -142,44 +142,48 @@ static int is_ready (CalcHandle* handle) break; } - // XXX when commenting this OS version detection code, sending many Status or Dirlist - // requests in quick succession often triggers memory corruption (hangs, reboots, - // a variable amount of black pixels on the screen) on (at least) Nspire (CAS) OS 1.7... - ticalcs_info(" waiting for LOGIN request (OS >= 1.2 check)..."); - const int old = ticables_options_set_timeout(handle->cable, 40); // 3s mini - - ret = nsp_cmd_r_login(handle); // no call to nsp_send_nack(handle) because nack is managed in nsp_recv_data() + // Only pre-Touchpad models may have OS 1.x + if (handle->model < CALC_NSPIRE_TOUCHPAD) + { + // XXX when commenting this OS version detection code, sending many Status or Dirlist + // requests in quick succession often triggers memory corruption (hangs, reboots, + // a variable amount of black pixels on the screen) on (at least) Nspire (CAS) OS 1.7... + ticalcs_info(" waiting for LOGIN request (OS >= 1.2 check)..."); + const int old = ticables_options_set_timeout(handle->cable, 40); // 3s mini - ticables_options_set_timeout(handle->cable, old); + ret = nsp_cmd_r_login(handle); // no call to nsp_send_nack(handle) because nack is managed in nsp_recv_data() - if (ret) - { - ticalcs_info("OS = 1.1"); - //rom_11 = !0; + ticables_options_set_timeout(handle->cable, old); - ret = nsp_addr_request(handle); - if (ret) - { - break; - } - ret = nsp_addr_assign(handle, NSP_DEV_ADDR); - if (ret) - { - break; - } - } - else - { - ret = nsp_recv_disconnect(handle); if (ret) { - ticalcs_info("OS = 1.2 or 1.3"); - //rom_14 = 0; + ticalcs_info("OS = 1.1"); + //rom_11 = !0; + + ret = nsp_addr_request(handle); + if (ret) + { + break; + } + ret = nsp_addr_assign(handle, NSP_DEV_ADDR); + if (ret) + { + break; + } } else { - ticalcs_info("OS = 1.4 or later"); - //rom_14 = !0; + ret = nsp_recv_disconnect(handle); + if (ret) + { + ticalcs_info("OS = 1.2 or 1.3"); + //rom_14 = 0; + } + else + { + ticalcs_info("OS = 1.4 or later"); + //rom_14 = !0; + } } } @@ -366,7 +370,7 @@ static int enumerate_folder(CalcHandle* handle, GNode** vars, const char * folde // We might have to remove some extensions. if (fe->type == NSP_TNS) { - char * ext = tifiles_fext_get(varname); + char * ext = (char*)tifiles_fext_get((const char*)varname); // Just a sanity check if (ext) { diff --git a/libticalcs/trunk/src/calc_xx.cc b/libticalcs/trunk/src/calc_xx.cc index df199986d..808c1f4dc 100644 --- a/libticalcs/trunk/src/calc_xx.cc +++ b/libticalcs/trunk/src/calc_xx.cc @@ -2096,9 +2096,7 @@ int TICALL ticalcs_calc_recv_cert2(CalcHandle* handle, const char* filename) break; } - gchar* e = tifiles_fext_get(basename); - - memcpy(e, "crt", 3); + memcpy((void*)tifiles_fext_get(basename), "crt", 3); content = tifiles_content_create_flash(handle->model); ret = ticalcs_calc_recv_cert(handle, content); diff --git a/libticalcs/trunk/tests/CMakeLists.txt b/libticalcs/trunk/tests/CMakeLists.txt index ecabc2f9b..00aef6d5d 100644 --- a/libticalcs/trunk/tests/CMakeLists.txt +++ b/libticalcs/trunk/tests/CMakeLists.txt @@ -4,16 +4,25 @@ project(libticalcs2-tests LANGUAGES CXX) add_executable(torture_ticalcs torture_ticalcs.cc) -add_executable(test_ticalcs_2 test_ticalcs_2.cc) +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) @@ -22,43 +31,35 @@ endif() if(USE_ICONV) find_package(Iconv REQUIRED) - # flags/link for external deps add_compile_definitions(USE_ICONV) endif() foreach(tar torture_ticalcs test_ticalcs_2) + if(tar STREQUAL test_ticalcs_2 AND WIN32) + continue() # not compatible for now + endif () + 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}) - target_include_directories(${tar} PRIVATE ${PROJECT_SOURCE_DIR}/../../../libticonv/trunk/src ${PROJECT_SOURCE_DIR}/../../../libtifiles/trunk/src ${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_link_directories(${tar} PRIVATE ${PROJECT_BINARY_DIR}/..) + target_link_libraries(${tar} PRIVATE ticonv tifiles2 ticables2 ticalcs2) endforeach() -set(builddirlibpaths "${PROJECT_BINARY_DIR}/../../../libticonv/trunk:${PROJECT_BINARY_DIR}/../../../libtifiles/trunk:${PROJECT_BINARY_DIR}/../../../libticables/trunk:${PROJECT_BINARY_DIR}/..") - add_custom_target(ticalcs2_check - COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH="${builddirlibpaths}" ${CMAKE_CURRENT_BINARY_DIR}/torture_ticalcs + COMMAND "$" DEPENDS torture_ticalcs COMMENT "Run the ticalcs2 torture tests" EXCLUDE_FROM_ALL diff --git a/libticonv/trunk/CMakeLists.txt b/libticonv/trunk/CMakeLists.txt index 222353bf0..e11fa3821 100644 --- a/libticonv/trunk/CMakeLists.txt +++ b/libticonv/trunk/CMakeLists.txt @@ -25,27 +25,33 @@ 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) +create_lib_target_with_deps(ticonv) + +if(LINUX) + target_link_libraries(ticonv PRIVATE Threads::Threads) +endif() +target_link_libraries(ticonv PRIVATE PkgConfig::glib) -set_target_properties(ticonv_shared PROPERTIES VERSION 9.0.4 SOVERSION 9) +set_target_properties(ticonv PROPERTIES VERSION 9.0.4 SOVERSION 9) if(USE_ICONV) find_package(Iconv REQUIRED) - # flags/link for external deps 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_include_directories(ticonv PRIVATE ${Iconv_INCLUDE_DIRS}) + target_link_libraries(ticonv PRIVATE ${Iconv_LIBRARIES}) + elseif(NOT Iconv_FOUND) + message(FATAL_ERROR "USE_ICONV true but it is not built-in and libiconv could not be found!") endif() endif() # public export define -target_compile_definitions(ticonv_objlib PUBLIC TICONV_EXPORTS) +target_compile_definitions(ticonv PUBLIC TICONV_EXPORTS) # tests -add_subdirectory(tests) +if (BUILD_TESTS) + add_subdirectory(tests) +endif() diff --git a/libticonv/trunk/tests/CMakeLists.txt b/libticonv/trunk/tests/CMakeLists.txt index 6a68db626..6a6b292d5 100644 --- a/libticonv/trunk/tests/CMakeLists.txt +++ b/libticonv/trunk/tests/CMakeLists.txt @@ -6,37 +6,27 @@ project(libticonv-tests add_executable(torture_ticonv torture_ticonv.c) add_executable(test_ticonv test_ticonv.cc) -pkg_check_modules(DEPS REQUIRED glib-2.0) +pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) if(USE_ICONV) find_package(Iconv REQUIRED) - # flags/link for external deps add_compile_definitions(USE_ICONV) endif() foreach(tar torture_ticonv test_ticonv) 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() 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_link_directories(${tar} PRIVATE ${PROJECT_BINARY_DIR}/..) + target_link_libraries(${tar} PRIVATE PkgConfig::glib ticonv) endforeach() -set(builddirlibpaths "${PROJECT_BINARY_DIR}/..") - add_custom_target(ticonv_check - COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH="${builddirlibpaths}" ${CMAKE_CURRENT_BINARY_DIR}/torture_ticonv + COMMAND "$" DEPENDS torture_ticonv COMMENT "Run the ticonv torture tests" EXCLUDE_FROM_ALL diff --git a/libtifiles/trunk/CMakeLists.txt b/libtifiles/trunk/CMakeLists.txt index 2277c419b..0717afcee 100644 --- a/libtifiles/trunk/CMakeLists.txt +++ b/libtifiles/trunk/CMakeLists.txt @@ -50,31 +50,30 @@ 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) +create_lib_target_with_deps(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 PRIVATE Threads::Threads) endif() +target_link_libraries(tifiles2 PRIVATE PkgConfig::glib ZLIB::ZLIB LibArchive::LibArchive) + +set_target_properties(tifiles2 PROPERTIES VERSION 11.0.2 SOVERSION 11) # Takes care of the i18n po/pot/gmo/mo files if(ENABLE_NLS) i18n_mo_from_po_pot() - add_dependencies(tifiles2_objlib potfiles_1) + add_dependencies(tifiles2 potfiles_1) endif() # public export define -target_compile_definitions(tifiles2_objlib PUBLIC TIFILES_EXPORTS) +target_compile_definitions(tifiles2 PUBLIC TIFILES_EXPORTS) # tests -add_subdirectory(tests) +if (BUILD_TESTS) + add_subdirectory(tests) +endif() diff --git a/libtifiles/trunk/tests/CMakeLists.txt b/libtifiles/trunk/tests/CMakeLists.txt index 27b3d87ee..6f6c0c1d3 100644 --- a/libtifiles/trunk/tests/CMakeLists.txt +++ b/libtifiles/trunk/tests/CMakeLists.txt @@ -6,40 +6,29 @@ project(libtifiles2-tests add_executable(torture_tifiles torture_tifiles.c) add_executable(test_tifiles_2 test_tifiles_2.cc) -pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive) +pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0) +find_package(LibArchive REQUIRED) if(USE_ICONV) find_package(Iconv REQUIRED) - # flags/link for external deps add_compile_definitions(USE_ICONV) endif() foreach(tar torture_tifiles test_tifiles_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() - target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) - target_include_directories(${tar} PRIVATE ${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_link_directories(${tar} PRIVATE ${PROJECT_BINARY_DIR}/..) + target_link_libraries(${tar} PRIVATE PkgConfig::glib LibArchive::LibArchive ticonv tifiles2) endforeach() -set(builddirlibpaths "${PROJECT_BINARY_DIR}/../../../libticonv/trunk:${PROJECT_BINARY_DIR}/..") - add_custom_target(tifiles2_check - COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH="${builddirlibpaths}" ${CMAKE_CURRENT_BINARY_DIR}/torture_tifiles + COMMAND "$" DEPENDS torture_tifiles COMMENT "Run the tifiles2 torture tests" EXCLUDE_FROM_ALL diff --git a/tifileutil/CMakeLists.txt b/tifileutil/CMakeLists.txt index 5ce637c51..d186eee31 100644 --- a/tifileutil/CMakeLists.txt +++ b/tifileutil/CMakeLists.txt @@ -12,26 +12,22 @@ 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) find_package(Iconv REQUIRED) - # flags/link for external deps add_compile_definitions(USE_ICONV) + if(Iconv_FOUND AND NOT Iconv_IS_BUILT_IN) + target_include_directories(tifileutil PRIVATE ${Iconv_INCLUDE_DIRS}) + target_link_libraries(tifileutil PRIVATE ${Iconv_LIBRARIES}) + endif() endif() # internal deps @@ -39,29 +35,11 @@ target_include_directories(tifileutil PRIVATE ${CMAKE_SOURCE_DIR}/libticonv/trunk/src ${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 tifiles2) +target_link_directories(tifileutil PRIVATE + ${CMAKE_BINARY_DIR}/libticonv/trunk + ${CMAKE_BINARY_DIR}/libtifiles/trunk) +target_link_libraries(tifileutil PRIVATE PkgConfig::glib LibArchive::LibArchive ticonv tifiles2) # Takes care of the i18n po/pot/gmo/mo files if(ENABLE_NLS) diff --git a/vcpkg.json b/vcpkg.json index 76462fa2f..4879fb8f6 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -4,16 +4,27 @@ "homepage": "https://github.com/debrouxl/tilibs", "description": "libs to transfer things from/to TI graphing calculators", "dependencies": [ - "bzip2", + "zlib", "pkgconf", + "libiconv", { "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": "61f610845fb206298a69f708104a51d651872877" + "builtin-baseline": "a993be073c6baea8674117f3eaed6e2d2486aaae" }