@@ -38,7 +38,6 @@ include(FeatureSummary)
3838
3939find_package (PkgConfig REQUIRED)
4040find_package (pybind11 CONFIG)
41- find_package (OpenMP)
4241# Find CUDA if GPU option is enabled 
4342if  (USE_GPU)
4443    find_package (CUDA REQUIRED)  # Adjust this if you're using modern CMake with FindCUDAToolkit. 
@@ -59,6 +58,23 @@ feature_summary(
5958pkg_check_modules(SDSLLITE sdsl-lite)
6059pkg_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+ 
6278if (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,14 +156,18 @@ 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" )
143- elseif  (${CMAKE_SYSTEM_NAME}  MATCHES  "Linux" )
144-   find_package (OpenMP REQUIRED)
159+   set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}  -lomp" )  # explicitly link OpenMP for building shared libs 
145160  # add the flags it detects to the compile flags 
146161  set  (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  ${OpenMP_C_FLAGS}  -fopenmp" )
147162  set  (CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS}  ${OpenMP_CXX_FLAGS}  -fopenmp" )
148163  set  (CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS}  ${OpenMP_EXE_LINKER_FLAGS} " )
149164endif ()
150165
166+ if (${CMAKE_VERSION}  VERSION_GREATER_EQUAL  "4.0" )
167+   # Compatibility with CMake < 3.5 has been removed from CMake starting 4.0 
168+   set (CMAKE_ARGS "${CMAKE_ARGS} ;-DCMAKE_POLICY_VERSION_MINIMUM=3.5" )
169+ endif ()
170+ 
151171# Set the output folder where your program will be created 
152172set (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? 
153173set (EXECUTABLE_OUTPUT_PATH  ${CMAKE_BINARY_DIR} )
@@ -323,6 +343,7 @@ endif (NOT INLINE_HANDLEGRAPH_SOURCES)
323343# taywee's C++ args library, header only 
324344ExternalProject_Add(tayweeargs
325345  SOURCE_DIR "${CMAKE_SOURCE_DIR} /deps/args" 
346+   CMAKE_ARGS "${CMAKE_ARGS} " 
326347  UPDATE_COMMAND "" 
327348  INSTALL_COMMAND "" )
328349ExternalProject_Get_property(tayweeargs SOURCE_DIR)
@@ -709,7 +730,7 @@ if (USE_GPU)
709730endif  (USE_GPU)
710731
711732set (odgi_LIBS
712-   jemalloc 
733+   ${JEMALLOC_LINK_LIBRARIES} 
713734  ${SDSLLITE_LINK_LIBRARIES} 
714735  ${LIBDIVSUFSORT_LINK_LIBRARIES} 
715736  "-L${CMAKE_SOURCE_DIR} /lib" 
0 commit comments