Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes to build using cmake on macOS/Qt5 #834

Merged
merged 8 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions App/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ if(WINDOWS)
list(APPEND Natron_SOURCES ../Natron.rc)
endif()
add_executable(Natron ${Natron_SOURCES})
set_target_properties(Natron PROPERTIES
devernay marked this conversation as resolved.
Show resolved Hide resolved
MACOSX_BUNDLE TRUE
)
target_link_libraries(Natron
PRIVATE
NatronGui
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ set(QTCORE_INCLUDE_DIRS ${Qt5_INCLUDE_DIR} ${Qt5Core_INCLUDE_DIRS})
set(QTGUI_INCLUDE_DIRS ${Qt5Gui_INCLUDE_DIRS})
set(QTWIDGETS_INCLUDE_DIRS ${Qt5Widgets_INCLUDE_DIRS})

find_package(expat REQUIRED)
YakoYakoYokuYoku marked this conversation as resolved.
Show resolved Hide resolved

if(NATRON_SYSTEM_LIBS)
find_package(glog)
find_package(Ceres)
Expand Down
1 change: 1 addition & 0 deletions Engine/AppInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// ***** BEGIN PYTHON BLOCK *****
// from <https://docs.python.org/3/c-api/intro.html#include-files>:
// "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
#undef Py_LIMITED_API // Needed for PyRun_SimpleString
#include <Python.h>
// ***** END PYTHON BLOCK *****

Expand Down
1 change: 1 addition & 0 deletions Engine/AppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// ***** BEGIN PYTHON BLOCK *****
// from <https://docs.python.org/3/c-api/intro.html#include-files>:
// "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
#undef Py_LIMITED_API // Needed for PyRun_SimpleString, PyRun_String, Py_NoUserSiteDirectory
#include <Python.h>
// ***** END PYTHON BLOCK *****

Expand Down
14 changes: 8 additions & 6 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

include(FindPkgConfig)

pkg_check_modules(Cairo REQUIRED cairo fontconfig)
pkg_check_modules(Cairo REQUIRED IMPORTED_TARGET cairo fontconfig)

file(GLOB NatronEngine_HEADERS *.h)
file(GLOB NatronEngine_SOURCES *.cpp)

set(PYENGINE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Qt${QT_VERSION_MAJOR})
set(PYENGINE_INCLUDE_DIRS ${PYSIDE_INCLUDE_DIRS} ${PYSIDE_INCLUDE_DIRS}/QtCore)
list(APPEND PYENGINE_INCLUDE_DIRS ${QTCORE_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS})
list(APPEND PYENGINE_INCLUDE_DIRS ${QTCORE_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
list(JOIN PYENGINE_INCLUDE_DIRS ":" PYENGINE_INCS)
set(PYENGINE_HEADER PySide2_Engine_Python.h)
set(POST_SHIBOKEN ../tools/utils/runPostShiboken2.sh)
Expand All @@ -37,7 +37,10 @@ set(shiboken_args
"-I.:..:../Global:../libs/OpenFX/include:${PYENGINE_INCS}"
"-T${PYSIDE_TYPESYSTEMS}" "--output-directory=${PYENGINE_OUT}"
"${PYENGINE_HEADER}" "typesystem_engine.xml")

if(APPLE)
list(PREPEND shiboken_args -I${Qt5_DIR}/../../../include)
YakoYakoYokuYoku marked this conversation as resolved.
Show resolved Hide resolved
endif()

execute_process(COMMAND ${Python3_EXECUTABLE} ../tools/utils/sourceList.py typesystem_engine.xml ${PYENGINE_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PyEngine_SOURCES)
Expand All @@ -57,7 +60,7 @@ if(UNIX AND NOT APPLE)
endif()

if(APPLE)
list(APPEND NatronEngine_SOURCES QtUrlFix.mm)
list(APPEND NatronEngine_SOURCES QUrlFix.mm)
endif()

list(APPEND NatronEngine_SOURCES
Expand All @@ -76,7 +79,7 @@ target_link_libraries(NatronEngine
HostSupport
Boost::headers
Boost::serialization
${Cairo_LIBRARIES}
PkgConfig::Cairo
PRIVATE
Shiboken2::libshiboken
PySide2::pyside2
Expand All @@ -100,7 +103,6 @@ target_include_directories(NatronEngine
..
../Global
../libs/SequenceParsing
${Cairo_INCLUDE_DIRS}
${X11_INCLUDE_DIR}
)
target_compile_definitions(NatronEngine
Expand Down
2 changes: 2 additions & 0 deletions Engine/GenericSchedulerThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <QThread>

#include <boost/shared_ptr.hpp>

#include "Engine/EngineFwd.h"
#include "Engine/ThreadPool.h"

Expand Down
1 change: 1 addition & 0 deletions Global/PythonUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// ***** BEGIN PYTHON BLOCK *****
// from <https://docs.python.org/3/c-api/intro.html#include-files>:
// "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
#undef Py_LIMITED_API // Needed for Py_NoUserSiteDirectory, PyBytes_AS_STRING
#include <Python.h>
// ***** END PYTHON BLOCK *****

Expand Down
7 changes: 5 additions & 2 deletions Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set(PYGUI_OUT ${CMAKE_CURRENT_BINARY_DIR}/Qt${QT_VERSION_MAJOR})
set(PYGUI_INCLUDE_DIRS ${PYSIDE_INCLUDE_DIRS} ${PYSIDE_INCLUDE_DIRS}/QtCore
${PYSIDE_INCLUDE_DIRS}/QtGui ${PYSIDE_INCLUDE_DIRS}/QtWidgets)
list(APPEND PYGUI_INCLUDE_DIRS ${QTCORE_INCLUDE_DIRS} ${QTGUI_INCLUDE_DIRS}
${QTWIDGETS_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS})
${QTWIDGETS_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
list(JOIN PYGUI_INCLUDE_DIRS ":" PYGUI_INCS)
set(PYGUI_HEADER PySide2_Gui_Python.h)
set(POST_SHIBOKEN ../tools/utils/runPostShiboken2.sh)
Expand All @@ -36,6 +36,9 @@ set(shiboken_args
"-I.:..:../Engine:../Global:../libs/OpenFX/include:${PYGUI_INCS}"
"-T../Engine:${PYSIDE_TYPESYSTEMS}" "--output-directory=${PYGUI_OUT}"
"${PYGUI_HEADER}" "typesystem_natronGui.xml")
if(APPLE)
list(APPEND shiboken_args -I${Qt5_DIR}/../../../include)
devernay marked this conversation as resolved.
Show resolved Hide resolved
endif()

execute_process(COMMAND ${Python3_EXECUTABLE} ../tools/utils/sourceList.py typesystem_natronGui.xml ${PYGUI_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand All @@ -48,7 +51,7 @@ add_custom_command(OUTPUT ${PyGui_SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

if(APPLE)
list(APPEND NatronGui_SOURCES QtMac.mm TaskBar.mm)
list(APPEND NatronGui_SOURCES QtMac.mm TaskBarMac.mm)
endif()

list(APPEND NatronGui_SOURCES
Expand Down
5 changes: 4 additions & 1 deletion HostSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# along with Natron. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
# ***** END LICENSE BLOCK *****

# see https://cmake.org/cmake/help/latest/module/FindEXPAT.html
FIND_PACKAGE( EXPAT REQUIRED )
devernay marked this conversation as resolved.
Show resolved Hide resolved

file(GLOB HostSupport_HEADERS
../libs/OpenFX/HostSupport/include/*.h
../libs/OpenFX/include/*.h
Expand All @@ -43,7 +46,7 @@ set(HostSupport_SOURCES
add_library(HostSupport STATIC ${HostSupport_SOURCES})
target_link_libraries(HostSupport
PRIVATE
expat::expat
EXPAT::EXPAT
)
target_include_directories(HostSupport
PUBLIC
Expand Down
33 changes: 25 additions & 8 deletions INSTALL_MACOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,15 @@ brew install cairo expat
brew install gnu-sed gawk coreutils findutils
brew install cmake keychain sphinx-doc
/usr/local/opt/sphinx-doc/libexec/bin/pip3 install sphinx_rtd_theme
brew install qt@5
brew install pyside@1.2 pyside-tools@1.2
```

If compiling with Qt5:

```Shell
brew install pyside@2
```


To install the [openfx-io](https://github.com/NatronGitHub/openfx-io) and [openfx-misc](https://github.com/NatronGitHub/openfx-misc) sets of plugin, you also need the following:

Expand Down Expand Up @@ -330,8 +335,9 @@ curl -k -L https://github.com/NatronGitHub/OpenColorIO-Configs/archive/Natron-v2
mv OpenColorIO-Configs-Natron-v2.5 OpenColorIO-Configs
```

## Building with qmake (for Qt4 and Qt5)
YakoYakoYokuYoku marked this conversation as resolved.
Show resolved Hide resolved

## Add the config.pri file
### Add the config.pri file

You have to define the locations of the required libraries.
This is done by creating a .pri file that will tell the .pro where to find those libraries.
Expand Down Expand Up @@ -365,7 +371,7 @@ cp config-homebrew.pri config.pri

Then check at the top of the `config.pri` file that the `HOMEBREW` variable is set to the homebrew installation prefix (usually `/opt/homebrew`).

## Build with Makefile
### Build with Makefile

You can generate a makefile by opening a Terminal, setting the current
directory to the toplevel source directory, and typing
Expand All @@ -392,7 +398,7 @@ qmake -r CONFIG+=debug

* You can also enable clang sanitizer by adding CONFIG+=sanitizer

### Building with OpenMP support using clang
#### Building with OpenMP support using clang

It is possible to build Natron using clang (version 3.8 is required,
version 9.0 is recommended) with OpenMP support on
Expand Down Expand Up @@ -451,7 +457,7 @@ LLVM_PATH=/opt/llvm
make CXX='clang++-mp-9.0 -stdlib=libc++' OPENMP=1 CXXFLAGS_MESA="-DHAVE_OSMESA" LDFLAGS_MESA="-L${OSMESA_PATH}/lib -lMangledOSMesa32 `${LLVM_PATH}/bin/llvm-config --ldflags --libs engine mcjit mcdisassembler | tr '\n' ' '`" OSMESA_PATH="${OSMESA_PATH}"
```

## Build on Xcode
### Build on Xcode

Follow the instruction of build but
add -spec macx-xcode to the qmake call command:
Expand All @@ -462,7 +468,7 @@ qmake -r -spec macx-xcode

Then open the already provided Project-xcode.xcodeproj and compile the target "all"

### Compiling plugins with Xcode
#### Compiling plugins with Xcode

The source distributions of the plugin sets `openfx-io` and
`openfx-misc` contain Xcode projects, but these require setting a few
Expand All @@ -486,7 +492,7 @@ It is also recommended in Xcode Preferences, select "Locations", then
the advanced settings to set the build location to Legacy (if not,
build files are somewhere under `~/Library/Developer/Xcode`.

### Build on Xcode with openmp clang
#### Build on Xcode with openmp clang

See instructions under "Using clang-omp with Xcode" at the following page https://clang-omp.github.io

Expand Down Expand Up @@ -524,7 +530,7 @@ qmake -r -spec macx-xcode CONFIG+=debug CONFIG+=enable-osmesa LLVM_PATH=/opt/llv

Then you can just build and run using Xcode

### Xcode caveats
#### Xcode caveats

Whenever the .pro files change, Xcode will try to launch qmake and
probably fail because it doesn't find the necessary binaries (qmake,
Expand All @@ -541,6 +547,17 @@ On MacPorts, this would look like:
launchctl setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
```

## Building with cmake (Qt5 only)

### On homebrew

```Shell
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH="/opt/homebrew/opt/expat;/opt/homebrew/opt/qt@5;/opt/homebrew/opt/pyside@2" -DPYTHON_FRAMEWORK_LIBRARIES=/opt/homebrew/Frameworks/Python.framework/Versions/3.9/lib
make -j
```

## Testing

```Shell
Expand Down
5 changes: 4 additions & 1 deletion PythonBin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ target_include_directories(NatronPython
..
../Global
)

if(APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
target_link_libraries(NatronPython PRIVATE ${COREFOUNDATION_LIBRARY})
endif()
install(TARGETS NatronPython DESTINATION "${CMAKE_INSTALL_BINDIR}")
2 changes: 1 addition & 1 deletion libs/ceres/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ set(ceres_SOURCES
internal/ceres/wall_time.cc
)
add_library(ceres STATIC ${ceres_HEADERS} ${ceres_SOURCES})
target_include_directories(ceres PUBLIC ../Eigen3 config include internal)
target_include_directories(ceres PUBLIC ../Eigen3 ../glog/src config include internal)
target_compile_definitions(ceres
PUBLIC
CERES_HAVE_PTHREAD
Expand Down
11 changes: 11 additions & 0 deletions libs/ceres/ceres-Natron.patch
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,14 @@
namespace ceres {
namespace internal {

--- CMakeLists.txt.orig 2022-08-08 12:49:31.000000000 -0400
YakoYakoYokuYoku marked this conversation as resolved.
Show resolved Hide resolved
+++ CMakeLists.txt 2022-08-08 12:49:23.000000000 -0400
@@ -246,7 +246,7 @@
internal/ceres/wall_time.cc
)
add_library(ceres STATIC ${ceres_HEADERS} ${ceres_SOURCES})
-target_include_directories(ceres PUBLIC ../Eigen3 config include internal)
+target_include_directories(ceres PUBLIC ../Eigen3 ../glog/src config include internal)
target_compile_definitions(ceres
PUBLIC
CERES_HAVE_PTHREAD
4 changes: 2 additions & 2 deletions libs/glog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ else()
)
endif()
add_library(glog STATIC ${glog_HEADERS} ${glog_SOURCES})
target_include_directories(glog src)
target_compile_definitions(glog GOOGLE_GLOG_DLL_DECL=)
target_include_directories(glog PRIVATE src)
target_compile_definitions(glog PRIVATE GOOGLE_GLOG_DLL_DECL=)
if(WINDOWS)
target_include_directories(APPEND glog src/windows)
target_compile_definitions(APPEND glog GLOG_NO_ABBREVIATED_SEVERITIES)
Expand Down
13 changes: 13 additions & 0 deletions libs/glog/glog-Natron.patch
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,16 @@ diff -ur /Users/devernay/Development/blender/extern/glog/src/windows/port.h ./sr

inline char* strerror_r(int errnum, char* buf, size_t buflen) {
#ifdef FREE_WINDOWS
--- CMakeLists.txt.orig 2022-08-08 10:34:58.000000000 -0400
YakoYakoYokuYoku marked this conversation as resolved.
Show resolved Hide resolved
+++ CMakeLists.txt 2022-08-08 10:34:54.000000000 -0400
@@ -72,8 +72,8 @@
)
endif()
add_library(glog STATIC ${glog_HEADERS} ${glog_SOURCES})
-target_include_directories(glog src)
-target_compile_definitions(glog GOOGLE_GLOG_DLL_DECL=)
+target_include_directories(glog PRIVATE src)
+target_compile_definitions(glog PRIVATE GOOGLE_GLOG_DLL_DECL=)
if(WINDOWS)
target_include_directories(APPEND glog src/windows)
target_compile_definitions(APPEND glog GLOG_NO_ABBREVIATED_SEVERITIES)
1 change: 1 addition & 0 deletions libs/qhttpserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ file(GLOB qhttpserver_SOURCES src/*.cpp)
set(qhttpserver_SOURCES ${qhttpserver_SOURCES} http-parser/http_parser.c)
add_library(qhttpserver STATIC ${qhttpserver_HEADERS} ${qhttpserver_SOURCES})
target_link_libraries(qhttpserver PRIVATE Qt5::Core Qt5::Network)
target_include_directories(qhttpserver PRIVATE http-parser)
devernay marked this conversation as resolved.
Show resolved Hide resolved
set_target_properties(qhttpserver PROPERTIES POSITION_INDEPENDENT_CODE ON)