Skip to content

Commit 892c702

Browse files
Merge pull request #612 from hlakshmidevi10/macos-fixes
added checks for apple sillicon and cmake4.0+ version
2 parents bf5a48f + 3e79c91 commit 892c702

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

CMakeLists.txt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ include(FeatureSummary)
3838

3939
find_package(PkgConfig REQUIRED)
4040
find_package(pybind11 CONFIG)
41-
find_package(OpenMP)
4241
# Find CUDA if GPU option is enabled
4342
if (USE_GPU)
4443
find_package(CUDA REQUIRED) # Adjust this if you're using modern CMake with FindCUDAToolkit.
@@ -59,6 +58,23 @@ feature_summary(
5958
pkg_check_modules(SDSLLITE sdsl-lite)
6059
pkg_check_modules(LIBDIVSUFSORT libdivsufsort)
6160

61+
# --- Start: Logic for using JEMALLOC on Apple Silicon ---
62+
set(JEMALLOC_LINK_LIBRARIES "jemalloc")
63+
64+
if (APPLE AND (CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64"))
65+
pkg_check_modules(HOMEBREW_JEMALLOC QUIET jemalloc)
66+
if (HOMEBREW_JEMALLOC_FOUND)
67+
set(JEMALLOC_LINK_LIBRARIES ${HOMEBREW_JEMALLOC_LINK_LIBRARIES})
68+
message(STATUS "Apple Silicon: Found Homebrew Jemalloc. Will use it.")
69+
message(STATUS " Homebrew jemalloc Includes: ${HOMEBREW_JEMALLOC_INCLUDE_DIRS}")
70+
message(STATUS " Homebrew jemalloc Link Libraries: ${HOMEBREW_JEMALLOC_LINK_LIBRARIES}")
71+
else()
72+
message(WARNING "Apple Silicon: Homebrew jemalloc not found via pkg-config. Will try using default jemalloc.")
73+
endif ()
74+
message(STATUS "jemalloc Link Library: ${JEMALLOC_LINK_LIBRARIES}")
75+
endif ()
76+
# --- End: Logic for using Homebrew HTSlib, GSL, and LibDeflate on Apple Silicon ---
77+
6278
if(NOT CMAKE_BUILD_TYPE)
6379
set(CMAKE_BUILD_TYPE Release CACHE STRING
6480
"Choose the type of build, options are: Release Debug Generic." FORCE)
@@ -140,6 +156,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # untested
140156
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
141157
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
142158
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS} -lomp")
159+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lomp") # explicitly link OpenMP for building shared libs
143160
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
144161
find_package(OpenMP REQUIRED)
145162
# add the flags it detects to the compile flags
@@ -148,6 +165,11 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
148165
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
149166
endif()
150167

168+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "4.0")
169+
# Compatibility with CMake < 3.5 has been removed from CMake starting 4.0
170+
set(CMAKE_ARGS "${CMAKE_ARGS};-DCMAKE_POLICY_VERSION_MINIMUM=3.5")
171+
endif()
172+
151173
# Set the output folder where your program will be created
152174
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) # TODO Do we want to comment out this line so the binary lands in the actual build directory?
153175
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
@@ -323,6 +345,7 @@ endif (NOT INLINE_HANDLEGRAPH_SOURCES)
323345
# taywee's C++ args library, header only
324346
ExternalProject_Add(tayweeargs
325347
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/args"
348+
CMAKE_ARGS "${CMAKE_ARGS}"
326349
UPDATE_COMMAND ""
327350
INSTALL_COMMAND "")
328351
ExternalProject_Get_property(tayweeargs SOURCE_DIR)
@@ -709,7 +732,7 @@ if (USE_GPU)
709732
endif (USE_GPU)
710733

711734
set(odgi_LIBS
712-
jemalloc
735+
${JEMALLOC_LINK_LIBRARIES}
713736
${SDSLLITE_LINK_LIBRARIES}
714737
${LIBDIVSUFSORT_LINK_LIBRARIES}
715738
"-L${CMAKE_SOURCE_DIR}/lib"

0 commit comments

Comments
 (0)