Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 107 additions & 7 deletions CMake/GifConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ==============================================================================
# Helper: split checks into include / library macros and a small wrapper
macro(_nelson_check_gif_include PREFIX)
if(EXISTS "${PREFIX}/include/gif_lib.h")
if(PREFIX AND EXISTS "${PREFIX}/include/gif_lib.h")
set(
GIF_INCLUDE_DIR
"${PREFIX}/include"
Expand All @@ -24,7 +24,7 @@ macro(_nelson_check_gif_include PREFIX)
endmacro()
# ==============================================================================
macro(_nelson_check_gif_library PREFIX)
if(EXISTS "${PREFIX}/lib/libgif${CMAKE_SHARED_LIBRARY_SUFFIX}")
if(PREFIX AND EXISTS "${PREFIX}/lib/libgif${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(
GIF_LIBRARIES
"${PREFIX}/lib/libgif${CMAKE_SHARED_LIBRARY_SUFFIX}"
Expand All @@ -37,10 +37,58 @@ macro(_nelson_check_gif_library PREFIX)
endmacro()
# ==============================================================================
macro(_nelson_check_gif_prefix PREFIX)
_nelson_check_gif_include(${PREFIX})
_nelson_check_gif_library(${PREFIX})
if(PREFIX)
_nelson_check_gif_include("${PREFIX}")
_nelson_check_gif_library("${PREFIX}")
endif()
endmacro()
# ==============================================================================
macro(_nelson_check_gif_include_from_library LIBRARY)
if(LIBRARY AND EXISTS "${LIBRARY}")
get_filename_component(_nelson_gif_library_dir "${LIBRARY}" DIRECTORY)
get_filename_component(_nelson_gif_prefix
"${_nelson_gif_library_dir}"
DIRECTORY
)
_nelson_check_gif_include("${_nelson_gif_prefix}")
endif()
endmacro()
# ==============================================================================
set(_NELSON_MACOS_SONOMA FALSE)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if(CMAKE_SYSTEM_VERSION
MATCHES
"^23\\."
OR
CMAKE_HOST_SYSTEM_VERSION
MATCHES
"^23\\."
)
set(_NELSON_MACOS_SONOMA TRUE)
else()
execute_process(
COMMAND sw_vers -productVersion
OUTPUT_VARIABLE _NELSON_MACOS_VERSION
RESULT_VARIABLE _NELSON_SW_VERS_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)
if(NOT _NELSON_SW_VERS_RESULT AND _NELSON_MACOS_VERSION MATCHES "^14\\.")
set(_NELSON_MACOS_SONOMA TRUE)
endif()
endif()
endif()
if(_NELSON_MACOS_SONOMA)
message(STATUS "macOS Sonoma detected: GIF support disabled.")
set(WITHOUT_GIF TRUE CACHE BOOL "Disable GIF support" FORCE)
unset(GIF_INCLUDE_DIR CACHE)
unset(GIF_INCLUDE_DIR)
unset(GIF_LIBRARY CACHE)
unset(GIF_LIBRARY)
unset(GIF_LIBRARIES CACHE)
unset(GIF_LIBRARIES)
set(GIF_FOUND FALSE CACHE BOOL "GIF library disabled on macOS Sonoma" FORCE)
endif()
# ==============================================================================
# Run environment prefix checks only when GIF support is enabled
if(NOT WITHOUT_GIF)
if(DEFINED ENV{IN_NIX_SHELL})
Expand All @@ -49,9 +97,31 @@ if(NOT WITHOUT_GIF)
endif()
elseif(DEFINED ENV{CONDA_PREFIX})
_nelson_check_gif_prefix("$ENV{CONDA_PREFIX}")
elseif(DEFINED ENV{HOMEBREW_PREFIX})
if(NOT GIF_INCLUDE_DIR OR NOT GIF_LIBRARIES)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()

if(CMAKE_SYSTEM_NAME
MATCHES
"Darwin"
AND
GIF_INCLUDE_DIR
MATCHES
"/Library/Frameworks/Mono.framework/Headers"
)
unset(GIF_INCLUDE_DIR CACHE)
unset(GIF_INCLUDE_DIR)
endif()

if(NOT GIF_INCLUDE_DIR OR NOT GIF_LIBRARIES)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if(DEFINED ENV{HOMEBREW_PREFIX})
_nelson_check_gif_prefix("$ENV{HOMEBREW_PREFIX}")
_nelson_check_gif_prefix("$ENV{HOMEBREW_PREFIX}/opt/giflib")
endif()
_nelson_check_gif_prefix("/opt/homebrew")
_nelson_check_gif_prefix("/opt/homebrew/opt/giflib")
_nelson_check_gif_prefix("/usr/local")
_nelson_check_gif_prefix("/usr/local/opt/giflib")
if(NOT GIF_INCLUDE_DIR OR NOT GIF_LIBRARIES)
execute_process(
COMMAND brew --prefix giflib
OUTPUT_VARIABLE BREW_GIFLIB_PREFIX
Expand All @@ -72,13 +142,43 @@ if(NOT WITHOUT_GIF)
if(NOT GIF_INCLUDE_DIR OR NOT GIF_LIBRARIES)
include(FindGIF)
find_package(GIF REQUIRED)
if(CMAKE_SYSTEM_NAME
MATCHES
"Darwin"
AND
GIF_INCLUDE_DIR
MATCHES
"/Library/Frameworks/Mono.framework/Headers"
)
foreach(_nelson_gif_library IN LISTS GIF_LIBRARIES GIF_LIBRARY)
_nelson_check_gif_include_from_library("${_nelson_gif_library}")
endforeach()
endif()
else()
set(GIF_FOUND TRUE CACHE BOOL "GIF library found" FORCE)
endif()
else()
set(GIF_FOUND FALSE CACHE BOOL "GIF library disabled" FORCE)
endif()
# ==============================================================================
if(NOT
WITHOUT_GIF
AND
GIF_FOUND
AND
CMAKE_SYSTEM_NAME
MATCHES
"Darwin"
AND
GIF_INCLUDE_DIR
MATCHES
"/Library/Frameworks/Mono.framework/Headers"
)
message(FATAL_ERROR
"Found Mono's incompatible gif_lib.h at ${GIF_INCLUDE_DIR}. Install giflib with Homebrew or set GIF_INCLUDE_DIR/GIF_LIBRARIES to a giflib 5+ installation."
)
endif()
# ==============================================================================
if(GIF_FOUND)
include_directories(BEFORE ${GIF_INCLUDE_DIR})
message(STATUS "libgif include directory: ${GIF_INCLUDE_DIR}")
Expand Down
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,26 @@ else()
find_package(OpenBLAS)
find_package(BLAS)
find_package(LAPACK)
if(NOT BLAS_FOUND)
find_library(
NELSON_BLAS_LIBRARY
NAMES blas
PATHS /lib /lib64 /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
if(NELSON_BLAS_LIBRARY)
set(BLAS_FOUND TRUE)
set(BLAS_LIBRARIES "${NELSON_BLAS_LIBRARY}")
endif()
endif()
if(NOT LAPACK_FOUND)
find_library(
NELSON_LAPACK_LIBRARY
NAMES lapack
PATHS /lib /lib64 /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)
if(NELSON_LAPACK_LIBRARY)
set(LAPACK_FOUND TRUE)
set(LAPACK_LIBRARIES "${NELSON_LAPACK_LIBRARY}")
endif()
endif()
find_package(LAPACKE)
if(OpenBLAS_FOUND)
if(CMAKE_SYSTEM_NAME
Expand Down