Skip to content

Instantly share code, notes, and snippets.

@marksteve
Last active April 17, 2024 03:51
Show Gist options
  • Save marksteve/cdd263862d5fcdcdb85c383e3d87cd2e to your computer and use it in GitHub Desktop.
Save marksteve/cdd263862d5fcdcdb85c383e3d87cd2e to your computer and use it in GitHub Desktop.

Building pgModeler in MacOS with Homebrew

The official installation instructions for pgModeler recommends installing Xcode and the Enterprise DB distribution of Postgres to fulfill its build requirements. Luckily, Homebrew's got us covered!

  1. Checkout the source

    git clone https://github.com/pgmodeler/pgmodeler.git
    git checkout main
    
  2. Install dependencies with brew

    brew install postgresql@13 qt@5 libxml2 libpq
    
  3. Tweak build script (pgmodeler.pri)

    macx {
      PGSQL_LIB = /usr/local/opt/libpq/lib/libpq.dylib
      PGSQL_INC = /usr/local/opt/libpq/include
      XML_INC = /usr/local/opt/libxml2/include/libxml2
      XML_LIB = /usr/local/opt/libxml2/lib/libxml2.dylib
      INCLUDEPATH += $$PGSQL_INC $$XML_INC
    }
    

    Brew installs to a different path by default for Apple Silicon devices:

    macx {
      PGSQL_LIB = /opt/homebrew/opt/libpq/lib/libpq.dylib
      PGSQL_INC = /opt/homebrew/opt/libpq/include
      XML_INC = /opt/homebrew/opt/libxml2/include/libxml2
      XML_LIB = /opt/homebrew/opt/libxml2/lib/libxml2.dylib
      INCLUDEPATH += $$PGSQL_INC $$XML_INC
    }
    
  4. Build

    <PATH_TO_QT5_BIN>/qmake -r pgmodeler.pro
    make
    make install
    
@knnth
Copy link

knnth commented Nov 26, 2021

I ran into issues when running make:

In file included from src/schemaparser.cpp:19:
src/schemaparser.h:49:16: error: unknown type name 'QRegExp'
                static const QRegExp AttribRegExp;
                             ^
src/schemaparser.cpp:62:7: error: unknown type name 'QRegExp'
const QRegExp SchemaParser::AttribRegExp=QRegExp("^([a-z])([a-z]*|(\\d)*|(\\-)*|(_)*)+", Qt::CaseInsensitive);
      ^
src/schemaparser.cpp:62:42: error: use of undeclared identifier 'QRegExp'
const QRegExp SchemaParser::AttribRegExp=QRegExp("^([a-z])([a-z]*|(\\d)*|(\\-)*|(_)*)+", Qt::CaseInsensitive);
                                         ^
3 errors generated.
make[1]: *** [obj/schemaparser.o] Error 1
make: *** [sub-libparsers-make_first-ordered] Error 2

To fix, I had to remove qt 6 and install qt 5, then invoke qmake directly from the qt5 install directory.

make clean
brew uninstall qt
brew install qt@5
/usr/local/opt/qt@5/bin/qmake -r pgmodeler.pro
make

Works like a charm in Big Sur 11.6!

macOS 11.6 (20G165)

Thank you!!!

@zyc
Copy link

zyc commented Dec 26, 2021

Working in macOS Monterey 21.1

By the way I think the postgresql dependency could by added to the first post too:

brew install postgresql@13

@zyc
Copy link

zyc commented Feb 5, 2022

The git checkout master should be changed to the git checkout main

@zyc
Copy link

zyc commented Feb 5, 2022

I changed the base path for Apple M1 build:

macx {
  PGSQL_LIB = /opt/homebrew/opt/libpq/lib/libpq.dylib
  PGSQL_INC = /opt/homebrew/opt/libpq/include
  XML_INC = /opt/homebrew/opt/libxml2/include/libxml2
  XML_LIB = /opt/homebrew/opt/libxml2/lib/libxml2.dylib
  INCLUDEPATH += $$PGSQL_INC $$XML_INC
}

@marksteve
Copy link
Author

@zyc thanks! updated

@hrodrig
Copy link

hrodrig commented Mar 27, 2022

works fine on M1 with latest Xtools 12.3 and PostgreSQL 14.2 !!! thank you so much !!!

@lzambarda
Copy link

In case you get the following when running make:

/usr/local/opt/libxml2/include/libxml2/libxml/encoding.h:31:10: fatal error: 'unicode/ucnv.h' file not found
#include <unicode/ucnv.h>
         ^~~~~~~~~~~~~~~~
1 error generated.
make[1]: *** [obj/schemaparser.o] Error 1
make: *** [sub-libs-libparsers-make_first-ordered] Error 2

I solved this by using libxml2 coming from XCode:

  XML_INC = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2
  XML_LIB = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libxml2.tbd

After this make worked fine and make install too. However pgModeler could not start due to:

qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: cocoa.

And I had to export the following

export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/local/opt/qt@5/plugin
/Applications/pgmodeler.app/Contents/MacOS/pgmodeler

@vserge
Copy link

vserge commented Apr 8, 2023

last build based on QT6, PQ15 and last brew packages needs:
macx {
!defined(PGSQL_LIB, var): PGSQL_LIB = /usr/local/Cellar/libpq/15.2/lib/libpq.dylib
!defined(PGSQL_INC, var): PGSQL_INC = /usr/local/Cellar/libpq/15.2/include
!defined(XML_INC, var): XML_INC = /usr/local/Cellar/libxml2/2.10.3_2/include/libxml2
!defined(XML_LIB, var): XML_LIB = /usr/local/Cellar/libxml2/2.10.3_2/lib/libxml2.dylib
INCLUDEPATH += "$$PGSQL_INC" "$$XML_INC"
}

and then

qmake6 -r pgmodeler.pro

@leonardocdz
Copy link

I had to install qt@6 because it wasn't working with qt@5 due to an error I can't recall. But after that it worked for me on Ventura. Thanks!

@sbamin
Copy link

sbamin commented Feb 16, 2024

For macbook pro M2 Max running Sonomia 14.3.1:

prerequisites

brew install postgresql@14 qt@6 libxml2 libpq

Also update XCode from app store, open xcode and accept initial license agreement, and install xcode cli.

update build script, pgmodeler.pri

Add line starting PGSQL_LIB to INCLUDEPATH in a macx { ... } block, preferably second block towards the end of the file provide updated build paths.

macx {
  !defined(PGSQL_LIB, var): PGSQL_LIB = /Library/PostgreSQL/14/lib/libpq.dylib
  !defined(PGSQL_INC, var): PGSQL_INC = /Library/PostgreSQL/14/include
  !defined(XML_INC, var): XML_INC = /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2
  !defined(XML_LIB, var): XML_LIB = /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libxml2.tbd
  INCLUDEPATH += "$$PGSQL_INC" "$$XML_INC"

  PGSQL_LIB = /opt/homebrew/opt/libpq/lib/libpq.dylib
  PGSQL_INC = /opt/homebrew/opt/libpq/include
  XML_INC = /opt/homebrew/opt/libxml2/include/libxml2
  XML_LIB = /opt/homebrew/opt/libxml2/lib/libxml2.dylib
  INCLUDEPATH += $$PGSQL_INC $$XML_INC
}

build

git clone https://github.com/pgmodeler/pgmodeler.git
cd pgmodeler
git checkout main
git pull
git status # should be clean

# workaround for an error:
# Project ERROR: failed to parse default search paths from compiler output
# define xcode path
# https://stackoverflow.com/a/77631382/1243763
which qmake # should be from homebrew install
qmake -r pgmodeler.pro -early QMAKE_DEFAULT_LIBDIRS=$(xcrun -show-sdk-path)/usr/lib
make
make install
echo $?

With a successful install and exit code 0, pgModeler.app should be under /Applications/

@technorior
Copy link

Worked perfectly on m1 pro Sonoma 14.4.1 , thanks 👍👍👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment