From fc9802cab58796a5d451e7b521811c7d374a2c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Garramu=C3=B1o?= Date: Wed, 14 Feb 2024 05:52:14 -0300 Subject: [PATCH] =?UTF-8?q?commit=2009d80194d49b3307db240883dcdea171f5419e?= =?UTF-8?q?5b=20Author:=20Gonzalo=20Garramu=C3=B1o=20?= =?UTF-8?q?=20Date:=20=20=20Wed=20Feb=2014=2005:22:04=202024=20-0300?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python and pyFLTK build fixes. --- .github/workflows/full.yml | 10 ++- .github/workflows/python.yml | 6 ++ cmake/Modules/BuildPython.cmake | 52 ++++++++------ cmake/Modules/BuildpyFLTK.cmake | 68 +++++++++++++++---- cmake/build_python_windows.cmake | 30 ++++++++ .../pyFLTK-patch/fltk14/test/exceptions.py | 67 ++++++++++++++++++ cmake/patches/pyFLTK-patch/setup.py | 15 ++-- mrv2/docs/HISTORY.md | 2 + tlRender | 2 +- 9 files changed, 210 insertions(+), 42 deletions(-) create mode 100644 cmake/build_python_windows.cmake create mode 100644 cmake/patches/pyFLTK-patch/fltk14/test/exceptions.py diff --git a/.github/workflows/full.yml b/.github/workflows/full.yml index 4984ee637..a750532e1 100644 --- a/.github/workflows/full.yml +++ b/.github/workflows/full.yml @@ -153,8 +153,11 @@ jobs: run: brew install gnu-sed - name: Install Python dependencies - run: brew install swig subversion libffi openssl readline sqlite3 xz zlib + run: brew install libffi openssl readline sqlite3 xz zlib + - name: Install pyFLTK dependencies + run: brew install subversion swig + - name: Setup environment run: mkdir -p ssh @@ -203,8 +206,11 @@ jobs: run: brew install gnu-sed - name: Install Python dependencies - run: brew install swig subversion libffi openssl readline sqlite3 xz zlib + run: brew install libffi openssl readline sqlite3 xz zlib + - name: Install pyFLTK dependencies + run: brew install subversion swig + - name: Setup environment run: mkdir -p ssh diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index a6160d9bf..db084a764 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -132,6 +132,9 @@ jobs: - name: Install Python dependencies run: brew install libffi openssl readline sqlite3 xz zlib + - name: Install pyFLTK dependencies + run: brew install subversion swig + - name: Setup environment run: mkdir -p ssh @@ -177,6 +180,9 @@ jobs: - name: Install Python dependencies run: brew install libffi openssl readline sqlite3 xz zlib + - name: Install pyFLTK dependencies + run: brew install subversion swig + - name: Setup environment run: mkdir -p ssh diff --git a/cmake/Modules/BuildPython.cmake b/cmake/Modules/BuildPython.cmake index a58a585fa..795303c4c 100644 --- a/cmake/Modules/BuildPython.cmake +++ b/cmake/Modules/BuildPython.cmake @@ -14,46 +14,58 @@ set( Python_TINY 9 ) set( Python_URL https://www.python.org/ftp/python/${Python_VERSION}.${Python_TINY}/Python-${Python_VERSION}.${Python_TINY}.tar.xz ) set( Python_PATCH ) +set( Python_ENV ) +set( Python_PATH $ENV{PATH} ) if(APPLE) - set( Python_PATCH cmake -E copy ${PROJECT_SOURCE_DIR}/etc/configure-macos-python.sh ${CMAKE_CURRENT_BINARY_DIR}/ ) + set( Python_PATCH ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/etc/configure-macos-python.sh ${CMAKE_CURRENT_BINARY_DIR}/ ) - set(Python_C_FLAGS ${CMAKE_C_FLAGS} ) - set(Python_LD_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} ) + set(Python_C_FLAGS "${CMAKE_C_FLAGS}" ) + set(Python_CXX_FLAGS "${CMAKE_CXX_FLAGS}" ) + set(Python_LD_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" ) + if(CMAKE_OSX_DEPLOYMENT_TARGET) set( Python_C_FLAGS "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET} ${CMAKE_C_FLAGS}") endif() - set( Python_CONFIGURE ${CMAKE_CURRENT_BINARY_DIR}/configure-macos-python.sh --prefix=${CMAKE_INSTALL_PREFIX} - "CFLAGS=${Python_C_FLAGS}" - "CPPFLAGS=${Python_C_FLAGS}" - "CXXFLAGS=${Python_CXX_FLAGS}" - "LDFLAGS=${Python_LD_FLAGS}" + set( Python_CONFIGURE ${CMAKE_COMMAND} -E env "CFLAGS=${Python_C_FLAGS}" "CPPFLAGS=${Python_C_FLAGS}" "CXXFLAGS=${Python_CXX_FLAGS}" "LDFLAGS=${Python_LD_FLAGS}" -- ${CMAKE_CURRENT_BINARY_DIR}/configure-macos-python.sh --prefix=${CMAKE_INSTALL_PREFIX} ) set( Python_BUILD ) set( Python_INSTALL make -j ${NPROCS} altinstall ) + elseif(UNIX) - set(Python_C_FLAGS ${CMAKE_C_FLAGS} ) - set(Python_CXX_FLAGS ${CMAKE_CXX_FLAGS} ) - set(Python_LD_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} ) - set( Python_CONFIGURE ./configure + + set(Python_C_FLAGS "${CMAKE_C_FLAGS}" ) + set(Python_CXX_FLAGS "${CMAKE_CXX_FLAGS}" ) + set(Python_LD_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" ) + + set( Python_CONFIGURE ${CMAKE_COMMAND} -E env "CFLAGS=${Python_C_FLAGS}" "CPPFLAGS=${Python_C_FLAGS}" "CXXFLAGS=${Python_CXX_FLAGS}" "LDFLAGS=${Python_LD_FLAGS}" -- ./configure --enable-optimizations --enable-shared --prefix=${CMAKE_INSTALL_PREFIX} - "CFLAGS=${Python_C_FLAGS}" - "CPPFLAGS=${Python_CXX_FLAGS}" - "CXXFLAGS=${Python_CXX_FLAGS}" - "LDFLAGS=${Python_LD_FLAGS}" ) set( Python_BUILD ) set( Python_INSTALL make -j ${NPROCS} altinstall ) else() + set( platform x64 ) if( "$ENV{ARCH}" STREQUAL "i386" ) set( platform Win32 ) endif() - set( Python_CONFIGURE ) - set( Python_BUILD PCbuild/build.bat -e -q -p ${platform} ) - set( Python_INSTALL python.bat PC/layout --precompile --preset-default --copy "${CMAKE_INSTALL_PREFIX}/bin/" ) + + # @bug: + # This creates another .bat file and makes the original .bat file fail + # set( Python_ENV ${CMAKE_COMMAND} -E env "PATH=${Python_PATH}" --) + + list(JOIN Python_PATH "|" Python_PATH_STR) + set(Python_SCRIPT "-DPATH=${Python_PATH_STR}" -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -P ${PROJECT_SOURCE_DIR}/cmake/build_python_windows.cmake + ) + + set(Python_BUILD ${CMAKE_COMMAND} -D Python_COMMAND=build + -D Python_PLATFORM=${platform}) + set(Python_BUILD ${Python_BUILD} ${Python_SCRIPT}) + + set(Python_INSTALL ${CMAKE_COMMAND} -D Python_COMMAND=install) + set(Python_INSTALL ${Python_INSTALL} ${Python_SCRIPT}) endif() ExternalProject_Add( @@ -61,7 +73,7 @@ ExternalProject_Add( URL ${Python_URL} PATCH_COMMAND "${Python_PATCH}" CONFIGURE_COMMAND "${Python_CONFIGURE}" - BUILD_COMMAND ${Python_BUILD} + BUILD_COMMAND "${Python_BUILD}" INSTALL_COMMAND "${Python_INSTALL}" BUILD_IN_SOURCE 1 ) diff --git a/cmake/Modules/BuildpyFLTK.cmake b/cmake/Modules/BuildpyFLTK.cmake index 8d72486ec..92fbb5f5b 100644 --- a/cmake/Modules/BuildpyFLTK.cmake +++ b/cmake/Modules/BuildpyFLTK.cmake @@ -22,21 +22,40 @@ endif() # Environment setup # set(pyFLTK_CXX_FLAGS ${CMAKE_CXX_FLAGS} ) -set(pyFLTK_LD_LIBRARY_PATH $ENV{OLD_LD_LIBRARY_PATH}) +set(pyFLTK_OLD_LD_LIBRARY_PATH $ENV{OLD_LD_LIBRARY_PATH}) +set(pyFLTK_OLD_DYLD_LIBRARY_PATH $ENV{OLD_DYLD_LIBRARY_PATH}) -set(pyFLTK_ENV ${CMAKE_COMMAND} -E env FLTK_HOME=${CMAKE_INSTALL_PREFIX} CXXFLAGS=${pyFLTK_CXX_FLAGS} -- ) +set(pyFLTK_LD_LIBRARY_PATH $ENV{LD_LIBRARY_PATH}) +set(pyFLTK_DYLD_LIBRARY_PATH $ENV{DYLD_LIBRARY_PATH}) +set(pyFLTK_PATH $ENV{PATH}) if(WIN32) - set(pyFLTK_CHECKOUT_CMD ${CMAKE_COMMAND} -E env -- svn checkout ${pyFLTK_SVN_REVISION_ARG} ${pyFLTK_SVN_REPOSITORY} pyFLTK) -elseif(APPLE) - set(pyFLTK_DYLD_LIBRARY_PATH $ENV{OLD_DYLD_LIBRARY_PATH}) - set(pyFLTK_CHECKOUT_CMD ${CMAKE_COMMAND} -E env DYLD_LIBRARY_PATH=${pyFLTK_DYLD_LIBRARY_PATH} -- svn checkout ${pyFLTK_SVN_REVISION_ARG} ${pyFLTK_SVN_REPOSITORY} pyFLTK) + string(REPLACE ";" "|" pyFLTK_PATH "$ENV{PATH}") +endif() + +# +# Handle macOS min version. +# +if(APPLE) if(CMAKE_OSX_DEPLOYMENT_TARGET) - list(APPEND pyFLTK_CXX_FLAGS "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") + set(pyFLTK_CXX_FLAGS "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET} ${pyFLTK_CXX_FLAGS}") endif() +endif() + + +# +# Old environment and checkout command +# +if(WIN32) + set(pyFLTK_OLD_ENV ${CMAKE_COMMAND} -E env -- ) + set(pyFLTK_CHECKOUT_CMD ${pyFLTK_OLD_ENV} svn checkout ${pyFLTK_SVN_REVISION_ARG} ${pyFLTK_SVN_REPOSITORY} pyFLTK) +elseif(APPLE) + set(pyFLTK_OLD_ENV ${CMAKE_COMMAND} -E env DYLD_LIBRARY_PATH="${pyFLTK_OLD_DYLD_LIBRARY_PATH}" -- ) + set(pyFLTK_CHECKOUT_CMD ${pyFLTK_OLD_ENV} svn checkout ${pyFLTK_SVN_REVISION_ARG} ${pyFLTK_SVN_REPOSITORY} pyFLTK) else() - set(pyFLTK_CHECKOUT_CMD ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${pyFLTK_LD_LIBRARY_PATH} svn checkout ${pyFLTK_SVN_REVISION_ARG} ${pyFLTK_SVN_REPOSITORY} pyFLTK) + set(pyFLTK_OLD_ENV ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH="${pyFLTK_OLD_LD_LIBRARY_PATH}" -- ) + set(pyFLTK_CHECKOUT_CMD ${pyFLTK_OLD_ENV} svn checkout ${pyFLTK_SVN_REVISION_ARG} ${pyFLTK_SVN_REPOSITORY} pyFLTK) endif() @@ -52,12 +71,34 @@ set(pyFLTK_PATCH COMMAND ${CMAKE_COMMAND} -E copy_if_different "${PROJECT_SOURCE_DIR}/cmake/patches/pyFLTK-patch/swig/WindowShowTypemap.i" - "${CMAKE_BINARY_DIR}/pyFLTK-prefix/src/pyFLTK/swig/") + "${CMAKE_BINARY_DIR}/pyFLTK-prefix/src/pyFLTK/swig/" + COMMAND + ${CMAKE_COMMAND} -E copy_if_different + "${PROJECT_SOURCE_DIR}/cmake/patches/pyFLTK-patch/fltk14/test/exceptions.py" + "${CMAKE_BINARY_DIR}/pyFLTK-prefix/src/pyFLTK/fltk14/test") + +# Environment setup for configure, building and installing +set(pyFLTK_ENV ${CMAKE_COMMAND} -E env CXXFLAGS=${pyFLTK_CXX_FLAGS} ) +if(WIN32) + set(pyFLTK_ENV ${pyFLTK_ENV} "PATH=${pyFLTK_PATH}" FLTK_HOME=${CMAKE_INSTALL_PREFIX} --) +elseif(APPLE) + set(pyFLTK_ENV ${pyFLTK_ENV} "PATH=${pyFLTK_PATH}" DYLD_LIBRARY_PATH=${pyFLTK_DYLD_LIBRARY_PATH} -- ) +else() + set(pyFLTK_ENV ${pyFLTK_ENV} "PATH=${pyFLTK_PATH}" LD_LIBRARY_PATH=${pyFLTK_LD_LIBRARY_PATH} -- ) +endif() + + +# Commands for configure, build and install set(pyFLTK_CONFIGURE ${pyFLTK_ENV} ${PYTHON_EXECUTABLE} setup.py swig --enable-shared) set(pyFLTK_BUILD ${pyFLTK_ENV} ${PYTHON_EXECUTABLE} setup.py build --enable-shared) set(pyFLTK_INSTALL ${pyFLTK_ENV} ${PYTHON_EXECUTABLE} setup.py install --enable-shared) - +# +# Output the commands +# +message(STATUS "pyFLTK_CONFIGURE=${pyFLTK_CONFIGURE}") +message(STATUS "pyFLTK_BUIILD=${pyFLTK_BUILD}") +message(STATUS "pyFLTK_INSTALL=${pyFLTK_INSTALL}") ExternalProject_Add( @@ -66,12 +107,13 @@ ExternalProject_Add( # so we need to DOWNLOAD_COMMAND for checking out the repository. # SVN_REPOSITORY ${pyFLTK_SVN_REPOSITORY} # SVN_REVISION ${pyFLTK_SVN_REVISION} - DEPENDS ${PYTHON_DEP} ${FLTK_DEP} ${SVN_DEP} - DOWNLOAD_COMMAND ${pyFLTK_CHECKOUT_CMD} + DEPENDS ${PYTHON_DEP} ${FLTK_DEP} + DOWNLOAD_COMMAND "${pyFLTK_CHECKOUT_CMD}" PATCH_COMMAND ${pyFLTK_PATCH} CONFIGURE_COMMAND "${pyFLTK_CONFIGURE}" BUILD_COMMAND "${pyFLTK_BUILD}" - INSTALL_COMMAND ${pyFLTK_INSTALL} + INSTALL_COMMAND "${pyFLTK_INSTALL}" + LIST_SEPARATOR | BUILD_IN_SOURCE 1 ) diff --git a/cmake/build_python_windows.cmake b/cmake/build_python_windows.cmake new file mode 100644 index 000000000..25cf0a452 --- /dev/null +++ b/cmake/build_python_windows.cmake @@ -0,0 +1,30 @@ + + +message(STATUS "Python_COMMAND=${Python_COMMAND}") +message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") +message(STATUS "PATH ENV 1=$ENV{PATH}") +message(STATUS "PATH 1=${PATH}") +string(REPLACE "|" ";" $ENV{PATH} "${PATH}") +message(STATUS "PATH ENV 2=$ENV{PATH}") + +set(ROOT_DIR ${CMAKE_INSTALL_PREFIX}/../Python-prefix/src/Python) + +if (Python_COMMAND STREQUAL "build") + set(CMD cmd /C PCbuild\\build.bat -e -q -p ${Python_PLATFORM}) +elseif(Python_COMMAND STREQUAL "install") + set(CMD cmd /C python.bat PC\\layout --precompile --preset-default --copy "${CMAKE_INSTALL_PREFIX}/bin/") +else() + message(FATAL_ERROR "Unknown Python_COMMAND ${Python_COMMAND}!") +endif() + +message(STATUS "Running: ${CMD} in ${ROOT_DIR}...") + +execute_process( + COMMAND ${CMD} + WORKING_DIRECTORY ${ROOT_DIR} + ERROR_VARIABLE BAT_CMD_ERROR + OUTPUT_VARIABLE BAT_CMD_OUTPUT + ECHO_ERROR_VARIABLE + ECHO_OUTPUT_VARIABLE + COMMAND_ERROR_IS_FATAL ANY +) diff --git a/cmake/patches/pyFLTK-patch/fltk14/test/exceptions.py b/cmake/patches/pyFLTK-patch/fltk14/test/exceptions.py new file mode 100644 index 000000000..b48b7cdd8 --- /dev/null +++ b/cmake/patches/pyFLTK-patch/fltk14/test/exceptions.py @@ -0,0 +1,67 @@ +# "$Id: demos.py 531 2019-12-27 12:15:45Z andreasheld $" +# +# Test program for pyFLTK the Python bindings +# for the Fast Light Tool Kit (FLTK). +# +# FLTK copyright 1998-1999 by Bill Spitzak and others. +# pyFLTK copyright 2003 by Andreas Held and others. +# +# This library is free software you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License, version 2.0 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# Please report all bugs and problems to "pyfltk-user@lists.sourceforge.net". +# + + +from fltk14 import * + +class subwindow(Fl_Gl_Window): + + def __init__(self, x,y,w,h): + super().__init__(x,y,w,h, "") + + def handle(self, event): + if event == FL_PUSH: + raise Exception("exception in handle") + return super().handle(event) + + def draw(self): + pass + + + +class MyButton(Fl_Button): + def __init__(self, x,y,w,h, l): + super().__init__(x,y,w,h, l) + self.callback(self.b_cb) + + def b_cb(self, wid): + raise Exception("exception in callback") + +if __name__=='__main__': + window = Fl_Double_Window(0, 0, 500, 500, "tst") + + widget = subwindow(0,0,500,400) + window.resizable(widget) + + mb = MyButton(200,420,100,60, "Exit") + + + try: + window.end() + window.show() + Fl.run() + except Exception as e: + print("Exception: ", e) + diff --git a/cmake/patches/pyFLTK-patch/setup.py b/cmake/patches/pyFLTK-patch/setup.py index 1642ddf25..9d1311be6 100644 --- a/cmake/patches/pyFLTK-patch/setup.py +++ b/cmake/patches/pyFLTK-patch/setup.py @@ -148,14 +148,14 @@ def fltk_config(dir): fltk_dir = os.environ['FLTK_HOME'] if isVerbose: print(f"FLTK_HOME={fltk_dir}") - ver_cmd = f"sh {fltk_dir}/bin/fltk-config --version" - inc_cmd = f"sh {fltk_dir}/bin/fltk-config --cxxflags {var_string}" - #lib_cmd = f"sh {fltk_dir}/bin/fltk-config --use-gl --use-glut --use-images --use-forms --ldflags" - lib_cmd = f"sh {fltk_dir}/bin/fltk-config --ldflags {var_string}" + ver_cmd = f"sh {fltk_dir}/fltk-config --version" + inc_cmd = f"sh {fltk_dir}/fltk-config --cxxflags {var_string}" + #lib_cmd = f"sh {fltk_dir}/fltk-config --use-gl --use-glut --use-images --use-forms --ldflags" + lib_cmd = f"sh {fltk_dir}/fltk-config --ldflags {var_string}" except: if isVerbose: print("Checking fltk-config using default installation") - + ver_cmd = "fltk-config --version" inc_cmd = f"fltk-config --cxxflags {var_string}" lib_cmd = f"fltk-config --ldflags {var_string}" @@ -289,7 +289,10 @@ def finalize_options(self): add_incl = ['-I/usr/include'] try: fltk_dir = os.environ['FLTK_HOME'] - add_incl.insert(0, f"-I{fltk_dir}/include") + if (sys.platform == 'win32'): + add_incl.insert(0, f"-I{fltk_dir}/include") + else: + add_incl.insert(0, f"-I{fltk_dir}") except: print("Using default location for FLTK!") result = os.popen('fltk-config --cxxflags').readlines() diff --git a/mrv2/docs/HISTORY.md b/mrv2/docs/HISTORY.md index ea584ac62..80ba2e63f 100644 --- a/mrv2/docs/HISTORY.md +++ b/mrv2/docs/HISTORY.md @@ -2,6 +2,8 @@ v1.0.5 ====== - Code clean up. +- Fixed Windows' Python compilation screwing up if some other Python version + was installed. v1.0.4 diff --git a/tlRender b/tlRender index 072c0012c..7a076e6af 160000 --- a/tlRender +++ b/tlRender @@ -1 +1 @@ -Subproject commit 072c0012c73f50377508d0ce81624a8edbf6494a +Subproject commit 7a076e6af6910e15ee76228c07bd40aa9ff10dd1