diff --git a/CMakeLists.txt b/CMakeLists.txt index 402632e9..b6bd46b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,9 +56,17 @@ pkg_check_modules(EXPAT REQUIRED expat) pkg_check_modules(SQLITE3 sqlite3) include_directories(${RPM_INCLUDE_DIRS}) include_directories(${EXPAT_INCLUDE_DIRS}) +if(APPLE) + include_directories(${OPENSSL_INCLUDE_DIRS}) + link_directories(${RPM_LIBRARY_DIRS}) + link_directories(${EXPAT_LIBRARY_DIRS}) +endif() ### External dependency: libsolv find_package(LibSolv REQUIRED ext) +if(APPLE) + include_directories(${LibSolv_INCLUDE_DIRS}) +endif() ### External dependency: libcurl find_package(CURL REQUIRED) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 521ca6ac..21c45c49 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -43,6 +43,12 @@ add_library(${LIB_TDNF} SHARED varsdir.c ) +if(APPLE) + # On macOS, explicitly find and link libsolvext + find_library(LIBSOLVEXT_LIBRARY NAMES solvext) + target_link_libraries(${LIB_TDNF} ${LIBSOLVEXT_LIBRARY}) +endif() + target_link_libraries(${LIB_TDNF} ${LIB_TDNF_COMMON} ${LIB_TDNF_SOLV} diff --git a/client/includes.h b/client/includes.h index f1dcff4a..3f155eb6 100644 --- a/client/includes.h +++ b/client/includes.h @@ -27,7 +27,12 @@ #include #include #include +#ifdef __APPLE__ +#include +#include +#else #include +#endif #include #include diff --git a/cmake/CFlags.cmake b/cmake/CFlags.cmake index 3100a1d3..cc4a0c0c 100644 --- a/cmake/CFlags.cmake +++ b/cmake/CFlags.cmake @@ -10,6 +10,11 @@ set(WARN_CFLAGS -Wno-sign-compare ) +if(APPLE) + # Add macOS-specific warning suppressions for external headers + list(APPEND WARN_CFLAGS -Wno-unused-parameter) +endif() + set(OPTIMIZE_CFLAGS -O2 -fno-strict-aliasing @@ -67,20 +72,36 @@ set(RELEASE_CFLAGS -s ) -set(FEATURE_FLAGS - -D_XOPEN_SOURCE=500 - -D_DEFAULT_SOURCE -) +if(APPLE) + set(FEATURE_FLAGS + -D_DARWIN_C_SOURCE + ) +else() + set(FEATURE_FLAGS + -D_XOPEN_SOURCE=500 + -D_DEFAULT_SOURCE + ) +endif() ### Combine all flags -set(TDNF_CFLAGS - ${WARN_CFLAGS} - ${OPTIMIZE_CFLAGS} - ${SECURITY_CFLAGS} - ${EXTRA_WARN_CFLAGS} - ${EXTRA_SECURITY_CFLAGS} - ${FEATURE_FLAGS} -) +if(APPLE) + # On macOS, skip GCC-specific flags that don't work with Clang + set(TDNF_CFLAGS + ${WARN_CFLAGS} + ${OPTIMIZE_CFLAGS} + ${SECURITY_CFLAGS} + ${FEATURE_FLAGS} + ) +else() + set(TDNF_CFLAGS + ${WARN_CFLAGS} + ${OPTIMIZE_CFLAGS} + ${SECURITY_CFLAGS} + ${EXTRA_WARN_CFLAGS} + ${EXTRA_SECURITY_CFLAGS} + ${FEATURE_FLAGS} + ) +endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") list(APPEND TDNF_CFLAGS ${DEBUG_CFLAGS}) diff --git a/cmake/FindGpgme.cmake b/cmake/FindGpgme.cmake index 88162f03..2eb8db61 100644 --- a/cmake/FindGpgme.cmake +++ b/cmake/FindGpgme.cmake @@ -10,8 +10,13 @@ find_library(GPGME_LIBRARY NAMES gpgme) # handle the QUIETLY and REQUIRED arguments and set GPGME_FOUND to TRUE # if all listed variables are TRUE -find_package_handle_standard_args(gpgme DEFAULT_MSG - GPGME_LIBRARY GPGME_INCLUDE_DIR) +if(APPLE) + find_package_handle_standard_args(Gpgme DEFAULT_MSG + GPGME_LIBRARY GPGME_INCLUDE_DIR) +else() + find_package_handle_standard_args(gpgme DEFAULT_MSG + GPGME_LIBRARY GPGME_INCLUDE_DIR) +endif() mark_as_advanced(GPGME_INCLUDE_DIR GPGME_LIBRARY ) diff --git a/cmake/FindLibSolv.cmake b/cmake/FindLibSolv.cmake index 81e22f3a..f1b538cf 100644 --- a/cmake/FindLibSolv.cmake +++ b/cmake/FindLibSolv.cmake @@ -73,7 +73,11 @@ FOREACH(COMPONENT ${LibSolv_FIND_COMPONENTS}) FIND_LIBRARY(LIBSOLV_${_UPPERCOMPONENT}_LIBRARY NAMES solv${COMPONENT}) SET(LibSolv_${COMPONENT}_FIND_REQUIRED ${LibSolv_FIND_REQUIRED}) SET(LibSolv_${COMPONENT}_FIND_QUIETLY ${LibSolv_FIND_QUIETLY}) - FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv_${COMPONENT} DEFAULT_MSG LIBSOLV_${_UPPERCOMPONENT}_LIBRARY) + IF(APPLE) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv DEFAULT_MSG LIBSOLV_${_UPPERCOMPONENT}_LIBRARY) + ELSE() + FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv_${COMPONENT} DEFAULT_MSG LIBSOLV_${_UPPERCOMPONENT}_LIBRARY) + ENDIF() MARK_AS_ADVANCED( LIBSOLV_${_UPPERCOMPONENT}_FOUND LIBSOLV_${_UPPERCOMPONENT}_LIBRARY @@ -91,5 +95,6 @@ IF(Solv_USE_STATIC_LIBS) ENDIF() IF(LibSolv_FOUND AND NOT LibSolv_FIND_QUIETLY) - MESSAGE(STATUS "Found LibSolv: ${LibSolv_INCLUDE_DIRS} ${LibSolv_LIBRARIES}") + MESSAGE(STATUS "Found LibSolv: ${LibSolv_INCLUDE_DIRS}") + MESSAGE(STATUS " Libraries: ${LibSolv_LIBRARIES}") ENDIF() diff --git a/cmake/FindOpenSSL.cmake b/cmake/FindOpenSSL.cmake index a6043bcd..42c4f135 100644 --- a/cmake/FindOpenSSL.cmake +++ b/cmake/FindOpenSSL.cmake @@ -4,10 +4,24 @@ # OPENSSL_LIBRARIES - The libraries needed to use openssl-devel find_path(OPENSSL_INCLUDE_DIR openssl/sha.h) -find_library(OPENSSL_LIBRARY NAMES libssl.so) +if(APPLE) + # This *should* also work on Linux, but needs to be tested. + # Keeping this guarded for now. + find_library(OPENSSL_SSL_LIBRARY NAMES ssl) + find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto) + find_package_handle_standard_args(OpenSSL DEFAULT_MSG + OPENSSL_SSL_LIBRARY OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) + set(OPENSSL_LIBRARY ${OPENSSL_SSL_LIBRARY}) -find_package_handle_standard_args(libssl DEFAULT_MSG - OPENSSL_LIBRARY OPENSSL_INCLUDE_DIR) +else() + find_library(OPENSSL_LIBRARY NAMES libssl.so) + find_package_handle_standard_args(libssl DEFAULT_MSG + OPENSSL_LIBRARY OPENSSL_INCLUDE_DIR) +endif() -set(OPENSSL_LIBRARIES ${OPENSSL_LIBRARY}) +if(APPLE) + set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}) +else() + set(OPENSSL_LIBRARIES ${OPENSSL_LIBRARY}) +endif() set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) diff --git a/common/defines.h b/common/defines.h index 90029450..fde745d4 100644 --- a/common/defines.h +++ b/common/defines.h @@ -27,3 +27,10 @@ * in fedora docker images and as a result ci fails */ #define TDNF_INSTANCE_LOCK_FILE "/var/run/.tdnf-instance-lockfile" + +/* macOS compatibility: EBADFD doesn't exist on macOS */ +#ifdef __APPLE__ +#ifndef EBADFD +#define EBADFD EIO +#endif +#endif diff --git a/history/CMakeLists.txt b/history/CMakeLists.txt index 133bb06f..51b0f0a3 100644 --- a/history/CMakeLists.txt +++ b/history/CMakeLists.txt @@ -26,8 +26,6 @@ set_target_properties(${LIB_TDNF_HISTORY} PROPERTIES POSITION_INDEPENDENT_CODE O install(TARGETS ${TDNF_HISTORY_UTIL_BIN} RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/tdnf COMPONENT binary) target_link_libraries(${TDNF_HISTORY_UTIL_BIN} - ${RPM_LIBRARIES} - ${SQLITE3_LIBRARIES} ${LIB_TDNF_HISTORY} ) diff --git a/tools/cli/lib/CMakeLists.txt b/tools/cli/lib/CMakeLists.txt index 7f5e3ab4..08603237 100644 --- a/tools/cli/lib/CMakeLists.txt +++ b/tools/cli/lib/CMakeLists.txt @@ -31,8 +31,15 @@ add_library(${LIB_TDNF_CLI} SHARED target_link_libraries(${LIB_TDNF_CLI} ${LIB_TDNF_JSONDUMP} + ${LIB_TDNF} ) +if(APPLE) + target_link_libraries(${LIB_TDNF_CLI} + ${OPENSSL_LIBRARIES} + ) +endif() + set_target_properties(${LIB_TDNF_CLI} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}