Skip to content

Commit

Permalink
commit 09d8019
Browse files Browse the repository at this point in the history
Author: Gonzalo Garramuño <[email protected]>
Date:   Wed Feb 14 05:22:04 2024 -0300

    Python and pyFLTK build fixes.
  • Loading branch information
ggarra13 committed Feb 14, 2024
1 parent fcfb5f0 commit fc9802c
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 42 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
52 changes: 32 additions & 20 deletions cmake/Modules/BuildPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,66 @@ 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(
Python
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
)
Expand Down
68 changes: 55 additions & 13 deletions cmake/Modules/BuildpyFLTK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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(
Expand All @@ -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
)

Expand Down
30 changes: 30 additions & 0 deletions cmake/build_python_windows.cmake
Original file line number Diff line number Diff line change
@@ -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
)
67 changes: 67 additions & 0 deletions cmake/patches/pyFLTK-patch/fltk14/test/exceptions.py
Original file line number Diff line number Diff line change
@@ -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 "[email protected]".
#


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)

15 changes: 9 additions & 6 deletions cmake/patches/pyFLTK-patch/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions mrv2/docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tlRender

0 comments on commit fc9802c

Please sign in to comment.