Skip to content

Commit 0b1cf19

Browse files
committed
fixes build issues on macOS
This commit fixes a number of cmake, compilation, and linker issues on macOS. All changes have been wrapped in guard blocks, so they should not have any impact on Linux builds. With these changes, tdnf now builds cleanly on macOS with external dependencies installed via Homebrew. Tested on macOS Tahoe, version 26.1 (25B78) Key fixes are: - Corrected detection of both libssl and libcrypto - Added _DARWIN_C_SOURCE to allow non-POSIX interfaces - Added EBADFD compatibility - Added workaround for missing vfs.h include - Added linker flags explicitly
1 parent d3108a9 commit 0b1cf19

10 files changed

Lines changed: 98 additions & 22 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,17 @@ pkg_check_modules(EXPAT REQUIRED expat)
5656
pkg_check_modules(SQLITE3 sqlite3)
5757
include_directories(${RPM_INCLUDE_DIRS})
5858
include_directories(${EXPAT_INCLUDE_DIRS})
59+
if(APPLE)
60+
include_directories(${OPENSSL_INCLUDE_DIRS})
61+
link_directories(${RPM_LIBRARY_DIRS})
62+
link_directories(${EXPAT_LIBRARY_DIRS})
63+
endif()
5964

6065
### External dependency: libsolv
6166
find_package(LibSolv REQUIRED ext)
67+
if(APPLE)
68+
include_directories(${LibSolv_INCLUDE_DIRS})
69+
endif()
6270

6371
### External dependency: libcurl
6472
find_package(CURL REQUIRED)

client/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ add_library(${LIB_TDNF} SHARED
4343
varsdir.c
4444
)
4545

46+
if(APPLE)
47+
# On macOS, explicitly find and link libsolvext
48+
find_library(LIBSOLVEXT_LIBRARY NAMES solvext)
49+
target_link_libraries(${LIB_TDNF} ${LIBSOLVEXT_LIBRARY})
50+
endif()
51+
4652
target_link_libraries(${LIB_TDNF}
4753
${LIB_TDNF_COMMON}
4854
${LIB_TDNF_SOLV}

client/includes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
#include <sys/file.h>
2828
#include <time.h>
2929
#include <sys/utsname.h>
30+
#ifdef __APPLE__
31+
#include <sys/param.h>
32+
#include <sys/mount.h>
33+
#else
3034
#include <sys/vfs.h>
35+
#endif
3136
#include <sys/types.h>
3237

3338
#include <dirent.h>

cmake/CFlags.cmake

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ set(WARN_CFLAGS
1010
-Wno-sign-compare
1111
)
1212

13+
if(APPLE)
14+
# Add macOS-specific warning suppressions for external headers
15+
list(APPEND WARN_CFLAGS -Wno-unused-parameter)
16+
endif()
17+
1318
set(OPTIMIZE_CFLAGS
1419
-O2
1520
-fno-strict-aliasing
@@ -67,20 +72,36 @@ set(RELEASE_CFLAGS
6772
-s
6873
)
6974

70-
set(FEATURE_FLAGS
71-
-D_XOPEN_SOURCE=500
72-
-D_DEFAULT_SOURCE
73-
)
75+
if(APPLE)
76+
set(FEATURE_FLAGS
77+
-D_DARWIN_C_SOURCE
78+
)
79+
else()
80+
set(FEATURE_FLAGS
81+
-D_XOPEN_SOURCE=500
82+
-D_DEFAULT_SOURCE
83+
)
84+
endif()
7485

7586
### Combine all flags
76-
set(TDNF_CFLAGS
77-
${WARN_CFLAGS}
78-
${OPTIMIZE_CFLAGS}
79-
${SECURITY_CFLAGS}
80-
${EXTRA_WARN_CFLAGS}
81-
${EXTRA_SECURITY_CFLAGS}
82-
${FEATURE_FLAGS}
83-
)
87+
if(APPLE)
88+
# On macOS, skip GCC-specific flags that don't work with Clang
89+
set(TDNF_CFLAGS
90+
${WARN_CFLAGS}
91+
${OPTIMIZE_CFLAGS}
92+
${SECURITY_CFLAGS}
93+
${FEATURE_FLAGS}
94+
)
95+
else()
96+
set(TDNF_CFLAGS
97+
${WARN_CFLAGS}
98+
${OPTIMIZE_CFLAGS}
99+
${SECURITY_CFLAGS}
100+
${EXTRA_WARN_CFLAGS}
101+
${EXTRA_SECURITY_CFLAGS}
102+
${FEATURE_FLAGS}
103+
)
104+
endif()
84105

85106
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
86107
list(APPEND TDNF_CFLAGS ${DEBUG_CFLAGS})

cmake/FindGpgme.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ find_library(GPGME_LIBRARY NAMES gpgme)
1010

1111
# handle the QUIETLY and REQUIRED arguments and set GPGME_FOUND to TRUE
1212
# if all listed variables are TRUE
13-
find_package_handle_standard_args(gpgme DEFAULT_MSG
14-
GPGME_LIBRARY GPGME_INCLUDE_DIR)
13+
if(APPLE)
14+
find_package_handle_standard_args(Gpgme DEFAULT_MSG
15+
GPGME_LIBRARY GPGME_INCLUDE_DIR)
16+
else()
17+
find_package_handle_standard_args(gpgme DEFAULT_MSG
18+
GPGME_LIBRARY GPGME_INCLUDE_DIR)
19+
endif()
1520

1621
mark_as_advanced(GPGME_INCLUDE_DIR GPGME_LIBRARY )
1722

cmake/FindLibSolv.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ FOREACH(COMPONENT ${LibSolv_FIND_COMPONENTS})
7373
FIND_LIBRARY(LIBSOLV_${_UPPERCOMPONENT}_LIBRARY NAMES solv${COMPONENT})
7474
SET(LibSolv_${COMPONENT}_FIND_REQUIRED ${LibSolv_FIND_REQUIRED})
7575
SET(LibSolv_${COMPONENT}_FIND_QUIETLY ${LibSolv_FIND_QUIETLY})
76-
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv_${COMPONENT} DEFAULT_MSG LIBSOLV_${_UPPERCOMPONENT}_LIBRARY)
76+
IF(APPLE)
77+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv DEFAULT_MSG LIBSOLV_${_UPPERCOMPONENT}_LIBRARY)
78+
ELSE()
79+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSolv_${COMPONENT} DEFAULT_MSG LIBSOLV_${_UPPERCOMPONENT}_LIBRARY)
80+
ENDIF()
7781
MARK_AS_ADVANCED(
7882
LIBSOLV_${_UPPERCOMPONENT}_FOUND
7983
LIBSOLV_${_UPPERCOMPONENT}_LIBRARY
@@ -91,5 +95,6 @@ IF(Solv_USE_STATIC_LIBS)
9195
ENDIF()
9296

9397
IF(LibSolv_FOUND AND NOT LibSolv_FIND_QUIETLY)
94-
MESSAGE(STATUS "Found LibSolv: ${LibSolv_INCLUDE_DIRS} ${LibSolv_LIBRARIES}")
98+
MESSAGE(STATUS "Found LibSolv: ${LibSolv_INCLUDE_DIRS}")
99+
MESSAGE(STATUS " Libraries: ${LibSolv_LIBRARIES}")
95100
ENDIF()

cmake/FindOpenSSL.cmake

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,24 @@
44
# OPENSSL_LIBRARIES - The libraries needed to use openssl-devel
55

66
find_path(OPENSSL_INCLUDE_DIR openssl/sha.h)
7-
find_library(OPENSSL_LIBRARY NAMES libssl.so)
7+
if(APPLE)
8+
# This *should* also work on Linux, but needs to be tested.
9+
# Keeping this guarded for now.
10+
find_library(OPENSSL_SSL_LIBRARY NAMES ssl)
11+
find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto)
12+
find_package_handle_standard_args(OpenSSL DEFAULT_MSG
13+
OPENSSL_SSL_LIBRARY OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)
14+
set(OPENSSL_LIBRARY ${OPENSSL_SSL_LIBRARY})
815

9-
find_package_handle_standard_args(libssl DEFAULT_MSG
10-
OPENSSL_LIBRARY OPENSSL_INCLUDE_DIR)
16+
else()
17+
find_library(OPENSSL_LIBRARY NAMES libssl.so)
18+
find_package_handle_standard_args(libssl DEFAULT_MSG
19+
OPENSSL_LIBRARY OPENSSL_INCLUDE_DIR)
20+
endif()
1121

12-
set(OPENSSL_LIBRARIES ${OPENSSL_LIBRARY})
22+
if(APPLE)
23+
set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
24+
else()
25+
set(OPENSSL_LIBRARIES ${OPENSSL_LIBRARY})
26+
endif()
1327
set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})

common/defines.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@
2727
* in fedora docker images and as a result ci fails
2828
*/
2929
#define TDNF_INSTANCE_LOCK_FILE "/var/run/.tdnf-instance-lockfile"
30+
31+
/* macOS compatibility: EBADFD doesn't exist on macOS */
32+
#ifdef __APPLE__
33+
#ifndef EBADFD
34+
#define EBADFD EIO
35+
#endif
36+
#endif

history/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ set_target_properties(${LIB_TDNF_HISTORY} PROPERTIES POSITION_INDEPENDENT_CODE O
2626
install(TARGETS ${TDNF_HISTORY_UTIL_BIN} RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/tdnf COMPONENT binary)
2727

2828
target_link_libraries(${TDNF_HISTORY_UTIL_BIN}
29-
${RPM_LIBRARIES}
30-
${SQLITE3_LIBRARIES}
3129
${LIB_TDNF_HISTORY}
3230
)
3331

tools/cli/lib/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ add_library(${LIB_TDNF_CLI} SHARED
3131

3232
target_link_libraries(${LIB_TDNF_CLI}
3333
${LIB_TDNF_JSONDUMP}
34+
${LIB_TDNF}
3435
)
3536

37+
if(APPLE)
38+
target_link_libraries(${LIB_TDNF_CLI}
39+
${OPENSSL_LIBRARIES}
40+
)
41+
endif()
42+
3643
set_target_properties(${LIB_TDNF_CLI} PROPERTIES
3744
VERSION ${PROJECT_VERSION}
3845
SOVERSION ${PROJECT_VERSION_MAJOR}

0 commit comments

Comments
 (0)