[Beginner] Compiling parmetis MacOS with homebrew

Big picture: Attempting to compile elmerfem on an M3 silicon Mac with parallel computing abilities
Litle steps: Get some of the prerequisite libraries compiled with homebrew installed open-mpi or gcc.

Step one: get parMETIS compiled. Obtaining ParMETIS | Karypis Lab CMake wants to use AppleCLang for the compilers, I want to use the homebrew installed gcc and tools for my platform. Simply setting the prefix to /opt/homebrew has not proven sufficient, as Cmake is pulling in Apple compiler stuff, not the homebrew installed libraries and helpers. Sort of fixed that by creating a hombrew.cmake file that sets the tool chain. Unfortunately, this results in Cmake not being able to find source files. So I am asking for some help.

% rm -r build
(base)parmetis % cmake . -B build -DCMAKE_TOOLCHAIN_FILE=$PWD/homebrew.cmake 
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/homebrew/bin/aarch64-apple-darwin23-gcc-13 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/homebrew/bin/aarch64-apple-darwin23-g++-13 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
failed to create symbolic link 'metis' because existing path cannot be removed: Operation not permitted
-- Looking for execinfo.h
-- Looking for execinfo.h - found
-- Looking for getline
-- Looking for getline - found
CMake Error at /Users/me/myApps/parmetis/build/CMakeFiles/CMakeTmp/CMakeLists.txt:18 (target_sources):
  Cannot find source file:

    METIS/GKlib/conf/check_thread_storage.c


CMake Error at /Users/me/myApps/parmetis/build/CMakeFiles/CMakeTmp/CMakeLists.txt:17 (add_executable):
  No SOURCES given to target: cmTC_53873


CMake Error at METIS/GKlib/GKlibSystem.cmake:110 (try_compile):
  Failed to generate test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:26 (include)


-- Configuring incomplete, errors occurred!

Seems I cannot upload a small attachment (1K). Contents of homebrew.cmake

set(HOMEBREW_PREFIX "/opt/homebrew"
    CACHE PATH "Path to Homebrew installation")

set(CMAKE_C_COMPILER "${HOMEBREW_PREFIX}/bin/aarch64-apple-darwin23-gcc-13")
set(CMAKE_CXX_COMPILER "${HOMEBREW_PREFIX}/bin/aarch64-apple-darwin23-g++-13")
set(CMAKE_RANLIB "${HOMEBREW_PREFIX}/bin/aarch64-apple-darwin23-gcc-ranlib-13")
set(CMAKE_AR "${HOMEBREW_PREFIX}/bin/aarch64-apple-darwin23-gcc-ar-13")
set(CMAKE_Fortran_COMPILER "${HOMEBREW_PREFIX}/bin/aarch64-apple-darwin23-gfortran-13")


set(CMAKE_PREFIX_PATH
    "${HOMEBREW_PREFIX}"
    # These libraries are keg-only and not loaded into
    # the root prefix by default (to avoid clashes).
    "${HOMEBREW_PREFIX}/opt/lapack"
    "${HOMEBREW_PREFIX}/opt/openblas"
    "${HOMEBREW_PREFIX}/opt/gcc"
    "${HOMEBREW_PREFIX}/opt/scalapack"
    "${HOMEBREW_PREFIX}/opt/open-mpi"
    "${HOMEBREW_PREFIX}/opt/openmpi"
)

list(TRANSFORM CMAKE_PREFIX_PATH APPEND "/include"
     OUTPUT_VARIABLE CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES)
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES "${CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES}")

set(CMAKE_FIND_FRAMEWORK NEVER)
set(CMAKE_FIND_APPBUNDLE NEVER)

set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)

Thanks for any and all help.

I see some case confusion here. Is there a metis path that is not a directory around?

There might be some case confusion, but not of my making. It’s interesting that the error message refers to …/CMakeTmp/something, but there is nothing in CMakeTmp now, it has been erased.
Here’s a picture of the whole directory.

/metis has GKlib under it. In /build/CMakeFiles/CMakeCache.txt it states:

//path to GKlib
GKLIB_PATH:PATH=METIS/GKlib

Should that be edited to metis/GKlib ?

But in CMakeLists.txt there is:

cmake_minimum_required(VERSION 2.8)
project(ParMETIS)

set(GKLIB_PATH METIS/GKlib CACHE PATH "path to GKlib")
set(METIS_PATH METIS CACHE PATH "path to METIS")

# Symlink ./metis to wherever metis is. This allows files to be
# included from metis/libmetis/.
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${METIS_PATH} metis)

Thanks for any and all assistance, it is greatly appreciated.
Edit: As a new user I cannot upload files, that’s what this site told me. It was 5.8MB zipped.

Pass --debug-trycompile to keep things around.

Hope I am doing this correctly

% cmake . -B build --debug-trycompile -DCMAKE_TOOLCHAIN_FILE=$PWD/homebrew.cmake
debug trycompile on
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


failed to create symbolic link 'metis' because existing path cannot be removed: Operation not permitted
CMake Debug Log at metis/GKlib/GKlibSystem.cmake:110 (try_compile):
  Executing try_compile (HAVE_THREADLOCALSTORAGE) in:

    /Users/me/myApps/parmetis/build/CMakeFiles/CMakeTmp
Call Stack (most recent call first):
  CMakeLists.txt:26 (include)


CMake Error at /Users/me/myApps/parmetis/build/CMakeFiles/CMakeTmp/CMakeLists.txt:18 (target_sources):
  Cannot find source file:

    metis/GKlib/conf/check_thread_storage.c


CMake Error at /Users/me/myApps/parmetis/build/CMakeFiles/CMakeTmp/CMakeLists.txt:17 (add_executable):
  No SOURCES given to target: cmTC_a9c36


CMake Error at metis/GKlib/GKlibSystem.cmake:110 (try_compile):
  Failed to generate test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:26 (include)


-- Configuring incomplete, errors occurred!

Contents of CMakeTmp/CMakeList.txt

cmake_minimum_required(VERSION 3.28.1.0)
cmake_policy(SET CMP0126 OLD)
cmake_policy(SET CMP0128 OLD)
project(CMAKE_TRY_COMPILE C)
set(CMAKE_VERBOSE_MAKEFILE 1)
set(CMAKE_C_FLAGS "")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILE_DEFINITIONS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXE_LINKER_FLAGS}")
include_directories(${INCLUDE_DIRECTORIES})
set(CMAKE_SUPPRESS_REGENERATION 1)
link_directories(${LINK_DIRECTORIES})
cmake_policy(SET CMP0065 OLD)
cmake_policy(SET CMP0083 OLD)
cmake_policy(SET CMP0155 OLD)
include("${CMAKE_ROOT}/Modules/Internal/HeaderpadWorkaround.cmake")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "/Users/me/myApps/parmetis/build/CMakeFiles/CMakeTmp")
add_executable(cmTC_daf15)
target_sources(cmTC_daf15 PRIVATE
  "metis/GKlib/conf/check_thread_storage.c"
)
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/cmTC_daf15_loc"
     CONTENT $<TARGET_FILE:cmTC_daf15>)
target_link_libraries(cmTC_daf15 ${LINK_LIBRARIES})

CMakeTmp/CMakeCache.txt is too large to cut and paste. 11K. Forum won’t allow me to attach.

I really feel like this is highly relevant; can you track down what this is trying to do and what it’s supposed to do?