Skip to content

Instantly share code, notes, and snippets.

@marksteve
Last active February 24, 2024 02:27
Show Gist options
  • Star 68 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • 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
    
Copy link

ghost commented Jan 11, 2019

Thank you, these instructions worked perfectly on High Sierra.

I didn't add QT to my path after installing, so invoked qmake directly: /usr/local/opt/qt/bin/qmake -r pgmodeler.pro

(Note the directions correctly explain that the *.pri file is edited, but the *.pro file is passed to qmake.)

The build process takes a while, better go for ☕.

@pabloalvzal
Copy link

Thank you as well, this is also working on macOS Mojave 10.14.4

I did add 'qmake' to my '.bash_profile' to follow the exact commands here like so:

# Qt paths
# -----------------
export PATH="/usr/local/opt/qt/bin:$PATH"

However, if you haven't updated Xcode in a while, do this first before running brew commands and trying the build. My Xcode version: 10.2)

@hugh-hoang
Copy link

Thanks and this works well for me on Mojave 10.14.3 too

@enragedginger
Copy link

+1 This is great. Worked for me on Mojave 10.14.6

@AdilHMCTS
Copy link

Worked perfectly on Mojave 10.14.6, thanks 👍

@sgeef
Copy link

sgeef commented Dec 19, 2019

Worked perfectly on Catalina 10.15.1, thanks 👍

@maikeruit
Copy link

brew link qt --force
and
echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.zshrc

@macdougall
Copy link

Followed instructions. Getting a crash after the app is open for 10-15 seconds.

Mohave 10.14.6
Qt 5.14 (installed with brew)
Postresql 11.6 (installed with Brew)
XCode 11.3.1

Crash Dump:

** pgModeler crashed after receive signal: 11 **

Date/Time: 2020-01-19 13:36:32
Version: 0.9.2
Build: 20200119
Compilation Qt version: 5.14.0
Running Qt version: 5.14.0

[29] 0 pgmodeler 0x000000010b923823 pgmodeler + 26659
[28] 1 libsystem_platform.dylib 0x00007fff665d1b5d _sigtramp + 29
[27] 2 ??? 0x00006000024d3660 0x0 + 105553154881120
[26] 3 QtNetwork 0x000000010ccfb0ba _ZNK13QNetworkReply7requestEv + 26
[25] 4 QtNetwork 0x000000010cce73a4 _ZN21QNetworkAccessManager20setAutoDeleteRepliesEb + 164
[24] 5 QtCore 0x000000010d05648c _ZN11QMetaObject8activateEP7QObjectPKS_iPPv + 3868
[23] 6 QtNetwork 0x000000010cd4a3e8 _ZN14QHttpMultiPart11setBoundaryERK10QByteArray + 105768
[22] 7 QtCore 0x000000010d04ea3d _ZN7QObject5eventEP6QEvent + 957
[21] 8 QtWidgets 0x000000010c14699d _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent + 269
[20] 9 QtWidgets 0x000000010c147dd5 _ZN12QApplication6notifyEP7QObjectP6QEvent + 581
[19] 10 pgmodeler 0x000000010b928213 _ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI15ObjectsDiffInfoLb1EE9ConstructEPvPKv + 11459
[18] 11 QtCore 0x000000010d0245f4 _ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent + 212
[17] 12 QtCore 0x000000010d0256a3 _ZN23QCoreApplicationPrivate16sendPostedEventsEP7QObjectiP11QThreadData + 691
[16] 13 libqcocoa.dylib 0x000000010f441142 qt_plugin_instance + 184914
[15] 14 libqcocoa.dylib 0x000000010f441848 qt_plugin_instance + 186712
[14] 15 CoreFoundation 0x00007fff3a47be33 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
[13] 16 CoreFoundation 0x00007fff3a47bdd9 __CFRunLoopDoSource0 + 108
[12] 17 CoreFoundation 0x00007fff3a45f79b __CFRunLoopDoSources0 + 195
[11] 18 CoreFoundation 0x00007fff3a45ed65 __CFRunLoopRun + 1189
[10] 19 CoreFoundation 0x00007fff3a45e66e CFRunLoopRunSpecific + 455
[9] 20 HIToolbox 0x00007fff396bd1ab RunCurrentEventLoopInMode + 292
[8] 21 HIToolbox 0x00007fff396bcee5 ReceiveNextEventCommon + 603
[7] 22 HIToolbox 0x00007fff396bcc76 _BlockUntilNextEventMatchingListInModeWithFilter + 64
[6] 23 AppKit 0x00007fff37a5477d _DPSNextEvent + 1135
[5] 24 AppKit 0x00007fff37a5346b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1361
[4] 25 AppKit 0x00007fff37a4d588 -[NSApplication run] + 699
[3] 26 libqcocoa.dylib 0x000000010f4406b8 qt_plugin_instance + 182216
[2] 27 QtCore 0x000000010d02076f _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE + 431
[1] 28 QtCore 0x000000010d024c42 _ZN16QCoreApplication4execEv + 130
[0] 29 pgmodeler 0x000000010b92495c pgmodeler + 31068

@Bizilizi
Copy link

Followed instructions. Getting a crash after the app is open for 10-15 seconds.

Mohave 10.14.6
Qt 5.14 (installed with brew)
Postresql 11.6 (installed with Brew)
XCode 11.3.1

Crash Dump:

** pgModeler crashed after receive signal: 11 **

Date/Time: 2020-01-19 13:36:32
Version: 0.9.2
Build: 20200119
Compilation Qt version: 5.14.0
Running Qt version: 5.14.0

[29] 0 pgmodeler 0x000000010b923823 pgmodeler + 26659
[28] 1 libsystem_platform.dylib 0x00007fff665d1b5d _sigtramp + 29
[27] 2 ??? 0x00006000024d3660 0x0 + 105553154881120
[26] 3 QtNetwork 0x000000010ccfb0ba _ZNK13QNetworkReply7requestEv + 26
[25] 4 QtNetwork 0x000000010cce73a4 _ZN21QNetworkAccessManager20setAutoDeleteRepliesEb + 164
[24] 5 QtCore 0x000000010d05648c _ZN11QMetaObject8activateEP7QObjectPKS_iPPv + 3868
[23] 6 QtNetwork 0x000000010cd4a3e8 _ZN14QHttpMultiPart11setBoundaryERK10QByteArray + 105768
[22] 7 QtCore 0x000000010d04ea3d _ZN7QObject5eventEP6QEvent + 957
[21] 8 QtWidgets 0x000000010c14699d _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent + 269
[20] 9 QtWidgets 0x000000010c147dd5 _ZN12QApplication6notifyEP7QObjectP6QEvent + 581
[19] 10 pgmodeler 0x000000010b928213 _ZN17QtMetaTypePrivate23QMetaTypeFunctionHelperI15ObjectsDiffInfoLb1EE9ConstructEPvPKv + 11459
[18] 11 QtCore 0x000000010d0245f4 _ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent + 212
[17] 12 QtCore 0x000000010d0256a3 _ZN23QCoreApplicationPrivate16sendPostedEventsEP7QObjectiP11QThreadData + 691
[16] 13 libqcocoa.dylib 0x000000010f441142 qt_plugin_instance + 184914
[15] 14 libqcocoa.dylib 0x000000010f441848 qt_plugin_instance + 186712
[14] 15 CoreFoundation 0x00007fff3a47be33 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
[13] 16 CoreFoundation 0x00007fff3a47bdd9 __CFRunLoopDoSource0 + 108
[12] 17 CoreFoundation 0x00007fff3a45f79b __CFRunLoopDoSources0 + 195
[11] 18 CoreFoundation 0x00007fff3a45ed65 __CFRunLoopRun + 1189
[10] 19 CoreFoundation 0x00007fff3a45e66e CFRunLoopRunSpecific + 455
[9] 20 HIToolbox 0x00007fff396bd1ab RunCurrentEventLoopInMode + 292
[8] 21 HIToolbox 0x00007fff396bcee5 ReceiveNextEventCommon + 603
[7] 22 HIToolbox 0x00007fff396bcc76 _BlockUntilNextEventMatchingListInModeWithFilter + 64
[6] 23 AppKit 0x00007fff37a5477d _DPSNextEvent + 1135
[5] 24 AppKit 0x00007fff37a5346b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1361
[4] 25 AppKit 0x00007fff37a4d588 -[NSApplication run] + 699
[3] 26 libqcocoa.dylib 0x000000010f4406b8 qt_plugin_instance + 182216
[2] 27 QtCore 0x000000010d02076f _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE + 431
[1] 28 QtCore 0x000000010d024c42 _ZN16QCoreApplication4execEv + 130
[0] 29 pgmodeler 0x000000010b92495c pgmodeler + 31068

Same for me

@zpl
Copy link

zpl commented Jan 20, 2020

I downgraded brew qt from 5.14.0 to 5.13.2 and it works.

brew uninstall qt
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/224d82c09d0bbeda99b4ee9b5ccdf56773e5d513/Formula/qt.rb

@macdougall
Copy link

I downgraded brew qt from 5.14.0 to 5.13.2 and it works.

brew uninstall qt
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/224d82c09d0bbeda99b4ee9b5ccdf56773e5d513/Formula/qt.rb

This worked for me as well. Clearly an issue with 5.14.*

@falmp
Copy link

falmp commented Jun 8, 2020

Works for me with Catalina and the newest qt.

Afterwards, besides the commands described, I had to run the following command to install it to my Applications folder:

/usr/local/opt/qt/bin/macdeployqt /Applications/pgmodeler.app /Applications/pgmodeler.app/Contents/MacOS/pgmodeler-ch /Applications/pgmodeler.app/Contents/MacOS/pgmodeler-cli

@yourssvk
Copy link

worked for me too @marksteve - Thank you :-)

Versions: qt: stable 5.15.0 (brew installed today)
MacOS Catalina 10.15.5
Postgres 12.3 (brew installed most likely on 2020-05-18)
XCode Version 11.5 beta 2

@m-thirumal
Copy link

m-thirumal commented Nov 24, 2020

It's working for me in Big Sur except display
Screenshot 2020-11-24 at 12 13 14 PM
]()

@cryptedx
Copy link

cryptedx commented Dec 21, 2020

I am on
10.15.7
qt 5.15.2 (brew)
pg 13.1 (brew)
Xcode 12.3

When I execute "make" command then I get this failure:

clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk' [-Wmissing-sysroot]
In file included from src/exception.cpp:18:
In file included from src/exception.h:29:
In file included from /usr/local/Cellar/qt/5.15.2/lib/QtCore.framework/Headers/QObject:1:
In file included from /usr/local/Cellar/qt/5.15.2/lib/QtCore.framework/Headers/qobject.h:46:
In file included from /usr/local/Cellar/qt/5.15.2/lib/QtCore.framework/Headers/qobjectdefs.h:48:
In file included from /usr/local/Cellar/qt/5.15.2/lib/QtCore.framework/Headers/qnamespace.h:43:
In file included from /usr/local/Cellar/qt/5.15.2/lib/QtCore.framework/Headers/qglobal.h:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/utility:203:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:60:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:60:15: fatal error:
      'string.h' file not found
#include_next <string.h>
              ^~~~~~~~~~
1 error generated.
make[1]: *** [obj/exception.o] Error 1
make: *** [sub-libutils-make_first-ordered] Error 2

I have installed a vanilla macos 11.1 virutal machine and build process in ongoing now. Let's see what I will get.

It's did work without a single problem.

@m-thirumal I also don't have any display bug. I am using the dev repo. Maybe you should give it a try.

@tjgeorgen
Copy link

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

@arjan-bal
Copy link

@tjgeorgen thank you, I faced the same problem on Big Sur and your solution helped

@heffcodex
Copy link

@tjgeorgen big thanks!

@Keating950
Copy link

Keating950 commented Oct 4, 2021

@tjgeorgen Thanks! For the benefit of future readers, I didn't have to uninstall qt6; specifying the path to qt5's qmake was enough for it to work. Building on Big Sur on an M1 Mac, for reference.

@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/

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