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

[email protected]_rc2_py312_qt6: scaffold out new formula #602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
338 changes: 338 additions & 0 deletions Formula/[email protected]_rc2_py312_qt6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
class FreecadAT100Rc2Py312Qt6 < Formula

Check warning on line 1 in Formula/[email protected]_rc2_py312_qt6.rb

View workflow job for this annotation

GitHub Actions / test-bot (macos-15)

No bottle built for [email protected]_rc2_py312_qt6!

[email protected]_rc2_py312_qt6 has unbottled dependencies, so a bottle will not be built.
desc "Parametric 3D modeler"
homepage "https://www.freecadweb.org"
license "GPL-2.0-only"

# NOTE: ipatch, ie. local patch `url "file:///#{HOMEBREW_PREFIX}/Library/Taps/freecad/homebrew-freecad/patches/`
# run `brew cleanup` when editing local patch files on each subsequent `brew install`
#---
stable do
url "https://github.com/FreeCAD/FreeCAD/archive/refs/tags/1.0rc2.tar.gz"
sha256 "4ed61d1a91039e5ad465bc19313bc95422d93b52b0135c63b628e59778d29512"
patch do
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/95e5aa838ae8b5e7d4fd6ddd710bc53c8caedddc/patches/freecad-0.20.2-cmake-find-hdf5.patch"
sha256 "99d115426cb3e8d7e5ab070e1d726e51eda181ac08768866c6e0fd68cda97f20"
end

# NOTE: ipatch, building the rc2 tag of freecad requires the resources due the new use of git submodules
resource "ondselsolver" do
url "https://github.com/Ondsel-Development/OndselSolver/archive/889196e3267597127b5889572b0c86f9316e16f0.tar.gz"
sha256 "83124c67971e7322b553599cf5883bb28cceffe0efde7e8524c090adc3d94b6e"
end

resource "googletest" do
url "https://github.com/google/googletest/releases/download/v1.15.2/googletest-1.15.2.tar.gz"
sha256 "7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926"
end

resource "msgsl" do
url "https://github.com/microsoft/GSL/archive/refs/tags/v4.1.0.tar.gz"
sha256 "0a227fc9c8e0bf25115f401b9a46c2a68cd28f299d24ab195284eb3f1d7794bd"
end
end

head do
url "https://github.com/freecad/FreeCAD.git", branch: "main", shallow: false

patch do
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/95e5aa838ae8b5e7d4fd6ddd710bc53c8caedddc/patches/freecad-0.20.2-cmake-find-hdf5.patch"
sha256 "99d115426cb3e8d7e5ab070e1d726e51eda181ac08768866c6e0fd68cda97f20"
end
end

keg_only :versioned_formula

depends_on "cmake" => :build
depends_on "freecad/freecad/[email protected]" => :build
depends_on "gcc" => :build
depends_on "hdf5" => :build
depends_on "llvm" => :build if OS.linux?
depends_on "mesa" => :build if OS.linux?
depends_on "ninja" => :build if OS.linux?
depends_on "pkg-config" => :build
depends_on "[email protected]" => :build
depends_on "tbb" => :build
depends_on "boost"
depends_on "cups"
depends_on "cython"
depends_on "doxygen"
depends_on "expat"
depends_on "fmt"
depends_on "freecad/freecad/[email protected]_py312_qt6"
depends_on "freecad/freecad/fc_bundle_py312"
depends_on "freecad/freecad/[email protected]_py312"
depends_on "freecad/freecad/[email protected]_py312"
depends_on "freecad/freecad/pybind11_py312"
depends_on "freecad/freecad/pyside6_py312"
depends_on "freetype"
depends_on "glew"
depends_on "icu4c"
depends_on macos: :high_sierra
depends_on "mesa-glu" if OS.linux?
depends_on "openblas"
depends_on "opencascade"
depends_on "orocos-kdl"
depends_on "pyqt"
depends_on "qt" # use version 6.x
depends_on "vtk"
depends_on "webp"
depends_on "xerces-c"
depends_on "yaml-cpp"
depends_on "zlib"

patch do
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/a979a1011bb1d911c2c26db9b663b04862b8b950/patches/freecad%401.0.0_rc2_py312-fix-pyside-path-issue.patch"
sha256 "c312676f490a9850691cc47ced760849bd440d20f0fdbefcac42b613f5873a2f"
end

# NOTE: https://docs.brew.sh/Formula-Cookbook#handling-different-system-configurations
# patch for mojave with 10.15 SDK
# patch :p1 do
# url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/a4b71def99b5fe907550729038752aaf6fa1b9bf/patches/freecad-0.20.1-macos-10.15-sdk.patch"
# sha256 "ce9f4b2afb2c621274e74208a563616eeeee54369f295b6c5f6f4f3112923135"
# end

def install

Check failure on line 95 in Formula/[email protected]_rc2_py312_qt6.rb

View workflow job for this annotation

GitHub Actions / test-bot (macos-14)

`brew install --verbose --formula --build-bottle freecad/freecad/[email protected]_rc2_py312_qt6` failed on macOS Sonoma (14) on Apple Silicon!

In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/qstring.h:16: In file included from /opt/homebrew/opt/qt/include/QtCore/qbytearrayview.h:6: /opt/homebrew/opt/qt/include/QtCore/qbytearrayalgorithms.h:98:15: error: functions that differ only in their return type cannot be overloaded inline size_t qstrlen(const char *str) ~~~~~~ ^ /opt/homebrew/opt/qt@5/include/QtCore/qbytearray.h:73:13: note: previous definition is here inline uint qstrlen(const char *str) ~~~~ ^ In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/qstring.h:16: In file included from /opt/homebrew/opt/qt/include/QtCore/qbytearrayview.h:6: /opt/homebrew/opt/qt/include/QtCore/qbytearrayalgorithms.h:131:78: error: redefinition of default argument Q_CORE_EXPORT int qstrnicmp(const char *, qsizetype, const char *, qsizetype = -1); ^ ~~ /opt/homebrew/opt/qt@5/include/QtCore/qbytearray.h:102:78: note: previous definition is here Q_CORE_EXPORT int qstrnicmp(const char *, qsizetype, const char *, qsizetype = -1); ^ ~~ In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/qstring.h:16: /opt/homebrew/opt/qt/include/QtCore/qbytearrayview.h:305:29: error: unknown type name 'Q_IMPLICIT' [[nodiscard]] constexpr Q_IMPLICIT operator std::string_view() const noexcept ^ /opt/homebrew/opt/qt/include/QtCore/qbytearrayview.h:209:57: error: cannot initialize a parameter of type 'int *' with an rvalue of type 'qsizetype *' (aka 'long long *') auto result = QContainerImplHelper::mid(size(), &pos, &n); ^~~~ /opt/homebrew/opt/qt@5/include/QtCore/qarraydata.h:351:51: note: passing argument to parameter 'position' here static CutResult mid(int originalLength, int *position, int *length); ^ In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/qstring.h:18: In file included from /opt/homebrew/opt/qt/include/QtCore/qlatin1stringview.h:12: /opt/homebrew/opt/qt/include/QtCore/qtversionchecks.h:38:4: error: Qt major version not 6 or 7 # error Qt major version not 6 or 7 ^ In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-20409-3lo0du/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /opt/homebrew/opt/qt/lib/QtCore.framework/Headers/qstring.h:18: /opt/homebrew/opt/qt/include/QtCore/qlatin1stringv

Check failure on line 95 in Formula/[email protected]_rc2_py312_qt6.rb

View workflow job for this annotation

GitHub Actions / test-bot (macos-13)

`brew install --verbose --formula --build-bottle freecad/freecad/[email protected]_rc2_py312_qt6` failed on macOS Ventura (13)!

In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/qstring.h:16: In file included from /usr/local/opt/qt/include/QtCore/qbytearrayview.h:6: /usr/local/opt/qt/include/QtCore/qbytearrayalgorithms.h:98:15: error: functions that differ only in their return type cannot be overloaded inline size_t qstrlen(const char *str) ~~~~~~ ^ /usr/local/opt/qt@5/include/QtCore/qbytearray.h:73:13: note: previous definition is here inline uint qstrlen(const char *str) ~~~~ ^ In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/qstring.h:16: In file included from /usr/local/opt/qt/include/QtCore/qbytearrayview.h:6: /usr/local/opt/qt/include/QtCore/qbytearrayalgorithms.h:131:78: error: redefinition of default argument Q_CORE_EXPORT int qstrnicmp(const char *, qsizetype, const char *, qsizetype = -1); ^ ~~ /usr/local/opt/qt@5/include/QtCore/qbytearray.h:102:78: note: previous definition is here Q_CORE_EXPORT int qstrnicmp(const char *, qsizetype, const char *, qsizetype = -1); ^ ~~ In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/qstring.h:16: /usr/local/opt/qt/include/QtCore/qbytearrayview.h:305:29: error: unknown type name 'Q_IMPLICIT' [[nodiscard]] constexpr Q_IMPLICIT operator std::string_view() const noexcept ^ /usr/local/opt/qt/include/QtCore/qbytearrayview.h:209:57: error: cannot initialize a parameter of type 'int *' with an rvalue of type 'qsizetype *' (aka 'long long *') auto result = QContainerImplHelper::mid(size(), &pos, &n); ^~~~ /usr/local/opt/qt@5/include/QtCore/qarraydata.h:351:51: note: passing argument to parameter 'position' here static CutResult mid(int originalLength, int *position, int *length); ^ In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/qstring.h:18: In file included from /usr/local/opt/qt/include/QtCore/qlatin1stringview.h:12: /usr/local/opt/qt/include/QtCore/qtversionchecks.h:38:4: error: Qt major version not 6 or 7 # error Qt major version not 6 or 7 ^ In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Builder3D.cpp:45: In file included from /tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24991-uv1a0s/FreeCAD-1.0rc2/src/Base/Tools.h:37: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/QString:1: In file included from /usr/local/opt/qt/lib/QtCore.framework/Headers/qstring.h:18: /usr/local/opt/qt/include/QtCore/qlatin1stringview.h:147:14: error: too many arguments to function call, expected

Check failure on line 95 in Formula/[email protected]_rc2_py312_qt6.rb

View workflow job for this annotation

GitHub Actions / test-bot (ubuntu-22.04)

`brew install --verbose --formula --build-bottle freecad/freecad/[email protected]_rc2_py312_qt6` failed on Linux!

| ^ 8 warnings generated. [793/6261] /home/linuxbrew/.linuxbrew/opt/llvm/bin/clang++ -DBOOST_ATOMIC_DYN_LINK -DBOOST_ATOMIC_NO_LIB -DBOOST_DATE_TIME_DYN_LINK -DBOOST_DATE_TIME_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_FILESYSTEM_NO_LIB -DBOOST_PP_VARIADICS=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_NO_LIB -DBOOST_REGEX_DYN_LINK -DBOOST_REGEX_NO_LIB -DBOOST_SYSTEM_DYN_LINK -DBOOST_SYSTEM_NO_LIB -DBOOST_THREAD_DYN_LINK -DBOOST_THREAD_NO_LIB -DBUILD_ADDONMGR -DCMAKE_BUILD_TYPE=\"RelWithDebInfo\" -DFMT_SHARED -DFreeCADGui_EXPORTS -DHAVE_CONFIG_H -DHAVE_PYSIDE6 -DHAVE_SHIBOKEN6 -DNDEBUG -DPYCXX_6_2_COMPATIBILITY -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_NO_KEYWORDS -DQT_OPENGLWIDGETS_LIB -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_SVGWIDGETS_LIB -DQT_SVG_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB -DQT_XML_LIB -D_OCC64 -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build/src/Gui/FreeCADGui_autogen/include -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build/src -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/FreeCAD-1.0rc2/src -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/FreeCAD-1.0rc2/src/Gui -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/FreeCAD-1.0rc2/src/Gui/Quarter -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build/src/Gui -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/FreeCAD-1.0rc2/src/Gui/.. -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build/src/Gui/.. -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build/src/Gui/Language -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build/src/Gui/propertyeditor -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build/src/Gui/TaskView -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build/src/Gui/Quarter -I/tmp/freecadA1.0.0_rc2_py312_qt6-20241027-24056-v2kfu8/build/src/Gui/DAGView -I/home/linuxbrew/.linuxbrew/opt/eigen/include/eigen3 -I/home/linuxbrew/.linuxbrew/opt/[email protected]_py312_qt6/include -I/home/linuxbrew/.linuxbrew/opt/xerces-c/include -I/home/linuxbrew/.linuxbrew/opt/zlib/include -I/home/linuxbrew/.linuxbrew/opt/qt/include/QtDBus -I/home/linuxbrew/.linuxbrew/opt/qt/include/QtUiPlugin -I/home/linuxbrew/.linuxbrew/opt/pyside6_py312/include/PySide6/QtCore -I/home/linuxbrew/.linuxbrew/opt/pyside6_py312/include/PySide6/QtGui -I/home/linuxbrew/.linuxbrew/opt/pyside6_py312/include/PySide6/QtWidgets -isystem /home/linuxbrew/.linuxbrew/Cellar/boost/1.86.0_1/include -isystem /home/linuxbrew/.linuxbrew/opt/[email protected]/include/python3.12 -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtCore -isystem /home/linuxbrew/.linuxbrew/opt/qt/include -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtWidgets -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtGui -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtOpenGL -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtPrintSupport -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtSvg -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtSvgWidgets -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtNetwork -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtUiTools -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtOpenGLWidgets -isystem /home/linuxbrew/.linuxbrew/opt/qt/include/QtXml -isystem /home/linuxbrew/.linuxbrew/opt/pyside6_py312/include/shiboken6 -isystem /home/linuxbrew/.linuxbrew/opt/pyside6_py312/include/PySide6 -isystem /home/linuxbrew/.linuxbrew/opt/qt/share/qt/mkspecs/linux-g++ -isystem /home/linuxbrew/.linuxbrew/opt/fmt/include -isystem /home/linuxbrew/.linuxbrew/opt/mesa/include -Wall -Wextra -Wpedantic -Wno-write-strings -Wno-undefined-var-template -O2 -g -DNDEBUG -std=gnu++17 -fPIC -I/home/linuxbrew/.linuxbrew/opt/open-mpi/include -fPIC -MD -MT src/Gui/CMakeFiles/FreeCADGui.dir/SoFCOffscreenRenderer.cpp.o -MF src/Gui/CMakeFiles/FreeCADGui.dir/SoFCOffscreenRenderer.cpp.o.d -o src/Gui/CMakeFiles/FreeCADGui.dir/SoFCOffscreenRenderer.cpp.o -c /tmp/freecadA1.0.0_rc2_
hbp = HOMEBREW_PREFIX

# NOTE: `which` cmd is not installed by default on every OS
# ENV["PYTHON"] = which("python3.10")
#------------
ENV["PYTHON"] = Formula["[email protected]"].opt_bin/"python3.12"

# Get the Python includes directory without duplicates
py_inc_output = `python3.12-config --includes`
py_inc_dirs = py_inc_output.scan(/-I([^\s]+)/).flatten.uniq
py_inc_dir = py_inc_dirs.join(" ")

py_lib_path = if OS.mac?
`python3.12-config --configdir`.strip + "/libpython3.12.dylib"
else
`python3.12-config --configdir`.strip + "/libpython3.12.a"
end

py_root_dir = Formula["[email protected]"].opt_prefix

puts "----------------------------------------------------"
puts "PYTHON=#{ENV["PYTHON"]}"
puts "PYTHON_INCLUDE_DIR=#{py_inc_dir}"
puts "PYTHON_LIBRARY=#{py_lib_path}"

# NOTE: apple's clang & clang++ don not provide batteries for open-mpi
# NOTE: when setting the compilers to brews' llvm, set the cmake_ar linker as well
# ENV["CC"] = Formula["llvm"].opt_bin/"clang"
# ENV["CXX"] = Formula["llvm"].opt_bin/"clang++"

# NOTE: ipatch, nuke default cmake_prefix_path to prevent qt6 from sneaking in
ENV.delete("CMAKE_PREFIX_PATH") # Clear existing paths
puts "----------------------------------------------------"
puts "CMAKE_PREFIX_PATH=#{ENV["CMAKE_PREFIX_PATH"]}"
puts "CMAKE_PREFIX_PATH Datatype: #{ENV["CMAKE_PREFIX_PATH"].class}"
puts "----------------------------------------------------"
puts "homebrew prefix: #{hbp}"
puts "prefix: #{prefix}"
puts "rpath: #{rpath}"

puts "PATH=#{ENV["PATH"]}"

cmake_prefix_paths = []
# cmake_prefix_paths << Formula["llvm"].prefix
# cmake_prefix_paths << Formula["open-mpi"].prefix
cmake_prefix_paths << Formula["boost"].prefix
cmake_prefix_paths << Formula["[email protected]_py312_qt6"].prefix
cmake_prefix_paths << Formula["cups"].prefix
cmake_prefix_paths << Formula["double-conversion"].prefix
cmake_prefix_paths << Formula["doxygen"].prefix
cmake_prefix_paths << Formula["eigen"].prefix
cmake_prefix_paths << Formula["expat"].prefix
cmake_prefix_paths << Formula["fmt"].prefix
cmake_prefix_paths << Formula["freetype"].prefix
cmake_prefix_paths << Formula["glew"].prefix
cmake_prefix_paths << Formula["hdf5"].prefix
cmake_prefix_paths << Formula["icu4c"].prefix
cmake_prefix_paths << Formula["libjpeg-turbo"].prefix
cmake_prefix_paths << Formula["libpng"].prefix
cmake_prefix_paths << Formula["libtiff"].prefix
cmake_prefix_paths << Formula["lz4"].prefix
cmake_prefix_paths << Formula["[email protected]_py312"].prefix
cmake_prefix_paths << Formula["opencascade"].prefix
cmake_prefix_paths << Formula["pkg-config"].prefix
cmake_prefix_paths << Formula["pugixml"].prefix
cmake_prefix_paths << Formula["[email protected]"].prefix
cmake_prefix_paths << Formula["pybind11_py312"].prefix
cmake_prefix_paths << Formula["pyside6_py312"].prefix
cmake_prefix_paths << Formula["pyqt"].prefix
cmake_prefix_paths << Formula["qt"].prefix
cmake_prefix_paths << Formula["[email protected]"].prefix
cmake_prefix_paths << Formula["tbb"].prefix
cmake_prefix_paths << Formula["utf8cpp"].prefix
cmake_prefix_paths << Formula["vtk"].prefix
cmake_prefix_paths << Formula["xerces-c"].prefix
cmake_prefix_paths << Formula["xz"].prefix
cmake_prefix_paths << Formula["yaml-cpp"].prefix
cmake_prefix_paths << Formula["zlib"].prefix

if OS.linux?
cmake_prefix_paths << Formula["mesa-glu"].prefix
cmake_prefix_paths << Formula["mesa"].prefix
cmake_prefix_paths << Formula["libx11"].prefix
cmake_prefix_paths << Formula["libxcb"].prefix
end

cmake_prefix_path_string = cmake_prefix_paths.join(";")

# Check if Xcode.app exists
if File.directory?("/Applications/Xcode.app")
apl_sdk = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
apl_frmwks ="#{apl_sdk}/System/Library/Frameworks"
cmake_ar = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar"
cmake_ld = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"

else
apl_sdk = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
apl_frmwks = "#{apl_sdk}/System/Library/Frameworks"
cmake_ar = "/Library/Developer/CommandLineTools/usr/bin/ar"
cmake_ld = "/Library/Developer/CommandLineTools/usr/bin/ld"
end

# TODO: stub out the below cmake vars
# -DCMAKE_OSX_SYSROOT=#{cmake_osx_sysroot}
# -DCMAKE_CXX_FLAGS="-fuse-ld=lld"
# -DBUILD_ENABLE_CXX_STD=C++17
# -DCMAKE_INSTALL_RPATH=#{prefix}/lib
# -DCMAKE_INSTALL_RPATH=#{rpath}
# -DBUILD_DRAWING=1
# -DBUILD_SMESH=1
# -DFREECAD_USE_EXTERNAL_KDL=1
# -DBUILD_FEM_NETGEN=0
# -DFREECAD_USE_QTWEBMODULE=#{qtwebmodule}
# -DCMAKE_EXE_LINKER_FLAGS="-v"

if OS.mac?
arch = Hardware::CPU.arch.to_s
fver = OS::Mac.full_version.to_s

args_macos_only = %W[
-DCMAKE_OSX_ARCHITECTURES=#{arch}
-DCMAKE_OSX_DEPLOYMENT_TARGET=#{fver}
-DCMAKE_AR=#{cmake_ar}
-DCMAKE_LINKER=#{cmake_ld}
-DCMAKE_INSTALL_NAME_TOOL:FILEPATH=/usr/bin/install_name_tool
-DOPENGL_INCLUDE_DIR=#{apl_frmwks}/OpenGL.framework
-DOPENGL_gl_LIBRARY=#{apl_frmwks}/OpenGL.framework
-DOPENGL_GLU_INCLUDE_DIR=#{apl_frmwks}/OpenGL.framework
]
# -DOPENGL_glu_LIBRARY=#{apl_frmwks}/OpenGL.framework
end

if OS.linux?
ninja_bin = Formula["ninja"].opt_bin/"ninja"
clang_cc = Formula["llvm"].opt_bin/"clang"
clang_cxx = Formula["llvm"].opt_bin/"clang++"
clang_ld = Formula["llvm"].opt_bin/"lld"
clang_ar = Formula["llvm"].opt_bin/"llvm-ar"
openglu_inc_dir = Formula["mesa-glu"].opt_include

puts "----------------------------------------------------"
puts openglu_inc_dir
puts "----------------------------------------------------"

args_linux_only = %W[
-GNinja
-DCMAKE_MAKE_PROGRAM=#{ninja_bin}
-DX11_X11_INCLUDE_PATH=#{hbp}/opt/libx11/include/X11
-DCMAKE_C_COMPILER=#{clang_cc}
-DCMAKE_CXX_COMPILER=#{clang_cxx}
-DCMAKE_LINKER=#{clang_ld}
-DCMAKE_AR=#{clang_ar}
-DOPENGL_GLU_INCLUDE_DIR=#{openglu_inc_dir}
]
end

args = %W[
-DHOMEBREW_PREFIX=#{hbp}
-DCMAKE_PREFIX_PATH=#{cmake_prefix_path_string}
-DCMAKE_INSTALL_PREFIX=#{prefix}
-DCMAKE_VERBOSE_MAKEFILE=1
-DPython_ROOT_DIR=#{py_root_dir}
-DPython3_EXECUTABLE=#{ENV["PYTHON"]}
-DPython3_INCLUDE_DIRS=#{py_inc_dir}
-DPython3_LIBRARIES=#{py_lib_path}
-DFREECAD_USE_PYBIND11=1
-DFREECAD_QT_VERSION=6

-DCMAKE_BUILD_TYPE=RelWithDebInfo
-L
]

# TODO: probably require a seperate formula to post_install the freecad py module
args << "-DINSTALL_TO_SITEPACKAGES=OFF"

# NOTE: useful cmake debugging args
# --trace
# -L

ENV.remove "PATH", Formula["pyside@2"].opt_prefix/"bin"

ENV.remove "PKG_CONFIG_PATH", Formula["pyside@2"].opt_prefix/"lib/pkgconfig"

# NOTE: ipatch, do not make build dir a sub dir of the src dir
puts "current working directory: #{Dir.pwd}"
src_dir = Dir.pwd.to_s
parent_dir = File.expand_path("..", src_dir)
# make the build dir a peer of the src dir
build_dir = "#{parent_dir}/build"
# Create the build directory if it doesn't exist
mkdir_p(build_dir)
# Change the working directory to the build directory
# false positive: `warning: conflicting chdir during another chdir block`
Dir.chdir(build_dir)
puts "----------------------------------------------------"
puts Dir.pwd
puts "Buildpath is: #{buildpath}"
puts "----------------------------------------------------"

unless build.head?
# NOTE: resources have to be in the correct buildpath
resource("googletest").stage(buildpath/"tests/lib")
resource("msgsl").stage(buildpath/"src/3rdParty/GSL")
resource("ondselsolver").stage(buildpath/"src/3rdParty/OndselSolver")
end

args.concat(args_macos_only) if OS.mac?
args.concat(args_linux_only) if OS.linux?

system "cmake", *args, src_dir.to_s
system "cmake", "--build", build_dir.to_s
system "cmake", "--install", build_dir.to_s
end

def post_install
ohai "the value of prefix = #{prefix}"
if OS.mac?
ln_s "#{prefix}/MacOS/FreeCAD", "#{HOMEBREW_PREFIX}/bin/freecad", force: true
ln_s "#{prefix}/MacOS/FreeCADCmd", "#{HOMEBREW_PREFIX}/bin/freecadcmd", force: true
elsif OS.linux?
ln_s "#{bin}/FreeCAD", "#{HOMEBREW_PREFIX}/bin/freecad", force: true
ln_s "#{bin}/FreeCADCmd", "#{HOMEBREW_PREFIX}/bin/freecadcmd", force: true
end
end

def caveats
<<-EOS
After installing FreeCAD you may want to do the following:

1. Due to recent code signing updates with Catalina and newer
building a FreeCAD.app bundle using the existing python
script no longer works due to updating the rpaths of the
copied executables and libraries into a FreeCAD.app
bundle. Until a fix or work around is made freecad
is built for CLI by default now.
EOS
end

test do
# NOTE: make test more robust and accurate
system "true"
end
end
Loading