ElmerCSC / elmerfem

Official git repository of Elmer FEM software
http://www.elmerfem.org
Other
1.14k stars 311 forks source link

Compile on Mac OS Monterey12.1 (Mac Mini M1) #313

Open ouening opened 2 years ago

ouening commented 2 years ago

OS: Mac OS Monterey 12.1 Computer: Mac mini (M1, 2020) elmerfem version: 9.0 (devel 7665920e)

1. Prepare

Install gcc, g++, gfortran, cmake, Qt5 and qwt-qt5:

brew install gcc g++ gfortran cmake qt@5 qwt-qt5

The gcc and g++ installed from brew are located in /opt/homebrew/bin/gcc-11 and /opt/homebrew/bin/g++-11. gfortran is located in /opt/homebrew/bin/gfortran.

We can use command:

brew info qt@5
brew info qwt-qt5

to see where the qt5 and qwt-qt5 are installed (my computer is m1 mac mini, the installation dir is in /opt).

And command: find /opt -name Qt5Config.cmake to find Qt5_DIR

Same as qwt-qt5. Be aware we should install qt@5 instead of qt, so as qwt-qt5 instead of qwt. See https://formulae.brew.sh/formula/qt@5 and https://formulae.brew.sh/formula/qwt-qt5#default.

2. Modify elmerfem/CmakeLists.txt

Modify the Apple section configuration:

if(APPLE)
  # message("you need to have gcc-gfrotran installed using HomeBrew")
  # set(CMAKE_C_COMPILER "/usr/bin/gcc")
  # set(CMAKE_CXX_COMPILER "/usr/bin/g++")
  set(CMAKE_C_COMPILER "/opt/homebrew/bin/gcc-11")
  set(CMAKE_CXX_COMPILER "/opt/homebrew/bin/g++-11")
  set(CMAKE_Fortran_COMPILER "/opt/homebrew/bin/gfortran")
  # set(BLA_VENDOR "OpenBLAS")
  # option(HUNTER_ENABLED "Enable Hunter package manager support" OFF)
  # set (CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE)
  # set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
  set(Qt5_DIR "/opt/homebrew/Cellar/qt@5/5.15.2_1/lib/cmake/Qt5")
  set(QWT_INCLUDE_DIR "/opt/homebrew/opt/qwt-qt5/include")
  set(QWT_INCLUDE_DIR "/opt/homebrew/Cellar/qwt-qt5/6.2.0/lib/qwt.framework/Versions/6/Headers")
  set(QWT_LIBRARY "/opt/homebrew/opt/qwt-qt5/lib/qwt.framework/qwt")
endif()

and

IF(APPLE)
  SET(CMAKE_MACOSX_RPATH 1) 
    # on OSX FindOpenGL uses framework version of OpenGL, but we need X11 version
    # FIND_PATH(GLX_INCLUDE_DIR GL/glx.h
    #   PATHS /opt/X11/include /usr/X11/include /usr/X11R6/include)
    # find_library(X11_GL_LIB GL
    #   PATH /opt/X11/lib /usr/X11/lib /usr/X11R6/lib)
  FIND_LIBRARY(OPENGL_gl_LIBRARY GL
        PATHS /opt/X11/lib /usr/X11/lib /usr/X11R6/lib)
  FIND_LIBRARY(OPENGL_glu_LIBRARY GLU
        PATHS /opt/X11/lib /usr/X11/lib /usr/X11R6/lib)
  LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
# INCLUDE_DIRECTORIES(${GLX_INCLUDE_DIR})
ENDIF()

Compile and install

Just make -j6 && sudo make install

ShamoX commented 1 year ago

Hello, thanks for the work.

This solution may have worked before gcc 12 release, but we need now to precise gcc@11 when installing.

I also made more flexible the variable (to prevent incompatibility to old intel macs).

I made a PR: #393.

bdlabitt commented 7 months ago

Any ideas on how to update to Ventura on an M3? gcc is at 13 now. Are the opengl lib paths the same?

bdlabitt commented 7 months ago

There's no utility find_program as used in CmakeLists.txt. This documentation is very outdated.

nega0 commented 6 months ago

find_program is a CMake command. It's not an external utility.

bdlabitt commented 5 months ago

Any ideas on how to update to Ventura on an M3? gcc is at 13 now. Are the opengl lib paths the same?

That's my real question. There's no /opt/X11 in Ventura, but there is /opt/homebrew/opt/X11 which is a simlink which leads to some strange files. But in /opt/homebrew/opt the following files exist

Screenshot 2024-02-05 at 3 59 38 PM
tyVandeZande commented 1 month ago

MacBook Pro M1 Sonoma 14.3.1

I followed the original instructions outlined by @ouening and it sent me into an infinite install loop.