Skip to content

Commit

Permalink
Python and pyFLTK fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Feb 14, 2024
1 parent bfc7e5a commit 09d8019
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 12 deletions.
19 changes: 13 additions & 6 deletions cmake/Modules/BuildPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ else()
set( platform Win32 )
endif()

# @bug: This creates another .bat file and makes the original .bat file fail
# set( Python_ENV ${CMAKE_COMMAND} -E env "PATH=${Python_PATH}" -- )
string(CONCAT Python_ENV "cmd /c \"set PATH=\"${Python_PATH}\"")
string(CONCAT Python_BUILD ${Python_ENV} && PCbuild/build.bat -e -q -p ${platform} )

# @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 ${Python_ENV} && python.bat PC/layout --precompile --preset-default --copy "${CMAKE_INSTALL_PREFIX}/bin/" )
set(Python_INSTALL ${CMAKE_COMMAND} -D Python_COMMAND=install)
set(Python_INSTALL ${Python_INSTALL} ${Python_SCRIPT})
endif()

ExternalProject_Add(
Expand Down
23 changes: 18 additions & 5 deletions cmake/Modules/BuildpyFLTK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ 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)
string(REPLACE ";" "|" pyFLTK_PATH "$ENV{PATH}")
endif()

#
# Handle macOS min version.
Expand Down Expand Up @@ -68,16 +71,20 @@ 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} --)
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} -- )
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} -- )
set(pyFLTK_ENV ${pyFLTK_ENV} "PATH=${pyFLTK_PATH}" LD_LIBRARY_PATH=${pyFLTK_LD_LIBRARY_PATH} -- )
endif()


Expand All @@ -86,7 +93,12 @@ set(pyFLTK_CONFIGURE ${pyFLTK_ENV} ${PYTHON_EXECUTABLE} setup.py swig --enable-s
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 @@ -101,6 +113,7 @@ ExternalProject_Add(
CONFIGURE_COMMAND "${pyFLTK_CONFIGURE}"
BUILD_COMMAND "${pyFLTK_BUILD}"
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)

2 changes: 1 addition & 1 deletion tlRender

0 comments on commit 09d8019

Please sign in to comment.