# \[Beginner\] Compiling parmetis MacOS with homebrew

**URL:** https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006
**Category:** Code
**Created:** [February 5, 2024, 6:34pm UTC](https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006 "2024-02-05T18:34:13Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bdl42](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bdl42/32/4273_2.png) [@bdl42](https://discourse.cmake.org/u/bdl42)
#### Post date: [February 5, 2024, 6:34pm UTC](https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006/1 "2024-02-05T18:34:13Z")

</div>

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](http://glaros.dtc.umn.edu/gkhome/metis/parmetis/download) 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.

```auto
% 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

```auto
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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 7, 2024, 8:39pm UTC](https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006/2 "2024-02-07T20:39:37Z")

</div>

> [@bdl42](#):
>
> ```auto
> 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
> 
> ```

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

---

<div class="post-metadata">

### Author: ![bdl42](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bdl42/32/4273_2.png) [@bdl42](https://discourse.cmake.org/u/bdl42)
#### Post date: [February 7, 2024, 9:02pm UTC](https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006/3 "2024-02-07T21:02:58Z")

</div>

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.

 ![Screenshot 2024-02-07 at 3.50.08 PM](https://discourse.cmake.org/uploads/default/original/2X/0/0ca5fe29fc53144278f3aa263381f525d35818fb.jpeg)

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

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

```

Should that be edited to metis/GKlib ?

But in CMakeLists.txt there is:

```auto
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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 8, 2024, 5:04am UTC](https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006/4 "2024-02-08T05:04:00Z")

</div>

> [@bdl42](#):
>
> It’s interesting that the error message refers to …/CMakeTmp/something, but there is nothing in CMakeTmp now, it has been erased.

Pass `--debug-trycompile` to keep things around.

---

<div class="post-metadata">

### Author: ![bdl42](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bdl42/32/4273_2.png) [@bdl42](https://discourse.cmake.org/u/bdl42)
#### Post date: [February 8, 2024, 1:56pm UTC](https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006/5 "2024-02-08T13:56:21Z")

</div>

> [@bdl42](#):
>
> `cmake . -B build -DCMAKE_TOOLCHAIN_FILE=$PWD/homebrew.cmake `

Hope I am doing this correctly

```auto
% 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

```auto
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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 16, 2024, 2:16pm UTC](https://discourse.cmake.org/t/beginner-compiling-parmetis-macos-with-homebrew/10006/6 "2024-02-16T14:16:20Z")

</div>

> [@bdl42](#):
>
> `failed to create symbolic link 'metis' because existing path cannot be removed: Operation not permitted`

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?
