From 1b7517ad9ff3360c85e54f206ae18ccd970c2aa5 Mon Sep 17 00:00:00 2001
From: Jonathan LEVY <23365238+j-levy@users.noreply.github.com>
Date: Mon, 31 May 2021 12:58:39 +0200
Subject: [PATCH 1/9] add actionSaveSession (crashed). add build script
---
.gitignore | 24 ++++++++++++-
bld.bat | 49 +++++++++++++++++++++++++++
src/openalea/lpy/gui/lpymainwindow.ui | 11 ++++++
3 files changed, 83 insertions(+), 1 deletion(-)
create mode 100644 bld.bat
diff --git a/.gitignore b/.gitignore
index 62518145..84f43d8b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@ src/openalea/lpy/gui/logdialog.py
src/openalea/lpy/gui/logindialog.py
src/openalea/lpy/gui/lpymainwindow.py
src/openalea/lpy/gui/lpyprefwidget.py
+src/openalea/lpy/gui/py2exe_release.py
#src/openalea/lpy/gui/lpyresources_rc.py
src/openalea/lpy/gui/scalarfloatmetaedit.py
src/openalea/lpy/gui/scalarmetaedit.py
@@ -36,7 +37,6 @@ build-scons_qt5
# Distribution / packaging
.Python
env/
-build/
develop-eggs/
dist/
downloads/
@@ -51,6 +51,9 @@ var/
.installed.cfg
*.egg
+# build/
+
+
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
@@ -84,6 +87,25 @@ doc/_build/doctrees
.idea/
cmake-build-debug/
+# Windows config folders
+.vscode
+.vs
+
+# build folders
+build*
+
+# C extensions
+*.so
+*.dll
+*.dblite
+*.lib
+
+
+# build-scons
+# build-scons_noqt
+# build-scons_qt4
+# build-scons_qt5
+
# PyBuilder
target/
diff --git a/bld.bat b/bld.bat
new file mode 100644
index 00000000..701328b6
--- /dev/null
+++ b/bld.bat
@@ -0,0 +1,49 @@
+@echo off
+
+:: You must install Visual Studio 2019 (Community is fine) with Desktop Development C++
+:: You must run this script in the Developer Command Prompt for Visual Studio (find the shortcut in your start menu)
+:: You should have installed your dependencies with
+:: ==> conda install -c conda-forge -c fredboudon --only-deps openalea.lpy
+:: CHECK THE VERSION IT PULLS. Sometimes Conda decides to pull an older version. In that case, specify openalea.lpy=3.8.0
+:: You should adjust the path to your conda environment in the variable CONDA_PREFIX
+
+set CONDA_PREFIX=%USERPROFILE%\miniconda3\envs\lpydev
+set BUILDDIR=build
+
+:: using "clean" as an argument will delete the build directory
+if "%1"=="clean" echo "CLEANING BEFORE BUILD."
+if "%1"=="clean" rmdir /s /q %BUILDDIR%
+if "%1"=="clean" mkdir %BUILDDIR%
+
+set PYTHON=%CONDA_PREFIX%\python.exe
+:: BUILD_CONFIG must be Release because conda does not provide debug symbols for Windows.
+set BUILD_CONFIG=Release
+set LIBRARY_LIB=%CONDA_PREFIX%\Library\lib
+set LIBRARY_PREFIX=%CONDA_PREFIX%\Library
+
+cd %BUILDDIR%
+
+cmake .. -G "Visual Studio 16 2019" ^
+-Wno-dev ^
+-DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
+-DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX% ^
+-DCMAKE_INSTALL_RPATH:STRING=%LIBRARY_LIB% ^
+-DCMAKE_INSTALL_NAME_DIR=%LIBRARY_LIB% ^
+-DPython3_EXECUTABLE=%PYTHON%
+
+
+if errorlevel 1 exit /b
+::echo "Can't generate CMake config"
+
+cd ..
+
+cd %BUILDDIR%
+cmake --build . --parallel %NUMBER_OF_PROCESSORS% --config %BUILD_CONFIG% --target install
+
+if errorlevel 1 exit /b
+:: echo "Can't build generated CMake config"
+
+cd ..
+%PYTHON% setup.py install
+
+%PYTHON% %CONDA_PREFIX%\Scripts\lpy-script.pyw
\ No newline at end of file
diff --git a/src/openalea/lpy/gui/lpymainwindow.ui b/src/openalea/lpy/gui/lpymainwindow.ui
index fc870528..94b0d23c 100644
--- a/src/openalea/lpy/gui/lpymainwindow.ui
+++ b/src/openalea/lpy/gui/lpymainwindow.ui
@@ -1093,6 +1093,7 @@
+
@@ -1197,6 +1198,7 @@
+
@@ -1384,6 +1386,15 @@
Save As
+
+
+
+ :/images/icons/filesave.png:/images/icons/filesave.png
+
+
+ Save Session
+
+
From bd1206a7331b3c09be6018fa9242b0273b7a2891 Mon Sep 17 00:00:00 2001
From: Jonathan LEVY <23365238+j-levy@users.noreply.github.com>
Date: Mon, 31 May 2021 14:37:19 +0200
Subject: [PATCH 2/9] build script for macos (LDFLAGS missing)
---
macos_build.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100755 macos_build.sh
diff --git a/macos_build.sh b/macos_build.sh
new file mode 100755
index 00000000..3011b420
--- /dev/null
+++ b/macos_build.sh
@@ -0,0 +1,42 @@
+#!/usr/local/bin/bash
+echo $1
+if [ -d build ] && [ "$1" == "clean" ]; then
+ echo "cleaning build directory"
+ rm -rf build
+fi
+
+if ! [[ -d build ]]; then
+ echo "creating build directory"
+ mkdir build
+fi
+exit
+
+# ld crashes when it sees a symbol it cannot resolve.
+# In this case, we must either mark all incriminated symbols as Undefined (WHICH IS DANGEROUS),
+# or tell ld to shut up about this. I chose the 2nd option here out of laz
+# More on this: https://stackoverflow.com/questions/36662920/xcode-clang-link-build-dynamic-framework-or-dylib-not-embed-dependencies
+# More on this: https://stackoverflow.com/questions/17281901/ignoring-an-undefined-symbol-in-a-dynamic-library-from-xcode
+# More on this: https://developer.apple.com/forums/thread/17630
+export LDFLAGS="-undefined dynamic_lookup ${LDFLAGS}"
+
+export PREFIX=${CONDA_PREFIX}
+export PYTHON=${CONDA_PREFIX}/bin/python
+
+
+cd build
+cmake \
+ -DPLANTGL_ROOT=../plantgl/build-cmake/ \
+ -DCMAKE_INSTALL_PREFIX=${PREFIX} \
+ -DCMAKE_PREFIX_PATH=${PREFIX} \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DPython3_EXECUTABLE=${PYTHON} \
+ ..
+
+# depending on the version of Boost, it might not be detected (I don't know why) in that case add:
+# -DBoost_INCLUDE_DIR=${CONDA_PREFIX}/include \
+
+NBPROC=$(sysctl -a | grep machdep.cpu.thread_count | sed s/"machdep.cpu.thread_count: "//g)
+make -j $NBPROC
+make install
+cd ..
+python setup.py install
\ No newline at end of file
From 6eb9e3a37c015b77f11f439c514ddbd1efa5e073 Mon Sep 17 00:00:00 2001
From: Jonathan LEVY <23365238+j-levy@users.noreply.github.com>
Date: Fri, 4 Jun 2021 11:09:09 +0200
Subject: [PATCH 3/9] renamed file
---
bld.bat => windows_build_dev.bat | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
rename bld.bat => windows_build_dev.bat (87%)
diff --git a/bld.bat b/windows_build_dev.bat
similarity index 87%
rename from bld.bat
rename to windows_build_dev.bat
index 701328b6..220e6b99 100644
--- a/bld.bat
+++ b/windows_build_dev.bat
@@ -46,4 +46,7 @@ if errorlevel 1 exit /b
cd ..
%PYTHON% setup.py install
-%PYTHON% %CONDA_PREFIX%\Scripts\lpy-script.pyw
\ No newline at end of file
+:: if you want to run the program, you must have your conda environment activated
+:: it won't not be the case if you're running this script in a simple Developer Command Prompt.
+
+:: %PYTHON% %CONDA_PREFIX%\Scripts\lpy-script.pyw
\ No newline at end of file
From ed33fae36aa63272e89048c7f1d31750649e1efb Mon Sep 17 00:00:00 2001
From: Jonathan LEVY <23365238+j-levy@users.noreply.github.com>
Date: Fri, 4 Jun 2021 11:59:55 +0200
Subject: [PATCH 4/9] improved script, wrote doc
---
doc/user/installing.rst | 65 ++++++++++++++++++++++++++++++++++++++++-
windows_build_dev.bat | 15 +++++++---
2 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/doc/user/installing.rst b/doc/user/installing.rst
index 0fd1e02d..34ea5b6c 100644
--- a/doc/user/installing.rst
+++ b/doc/user/installing.rst
@@ -49,7 +49,13 @@ You should clone the lpy project into your computer
git clone https://github.com/fredboudon/lpy.git
-You need then to compile lpy with the following command
+
+Compiling on macOS and Linux
+=================
+
+This assumes you installed the usual build tools on Linux, or the Xcode Build Tools on macOS.
+
+You need then to compile lpy with the following command, on macOS and Linux:
.. code-block:: bash
@@ -83,6 +89,63 @@ To launch the visual editor, you can type in your shell
lpy
+Compiling on Windows
+=======
+
+On Windows you must install **Visual Studio 2019** with Desktop C++ tools.
+
+For your convenience a build script called `windows_build_dev.bat` has been written. If you installed **Visual Studio 2019** with Desktop C++ tools and **miniconda3** at the default location, with your environment called **lpydev**, running the script from the Windows Command Prompt should compile lpy.
+
+If you want to compile manually, open the **Developer Command Prompt for VS 2019** (search for the shortcut in the Start Menu).
+
+Then you should activate **conda** manually in that prompt. If you installed **miniconda3** in the default directory `C:\\Users\\YourName\\miniconda3` and if your environment is named `lpydev`, you can use the command:
+
+.. code-block:: command
+
+ %USERPROFILE%\miniconda3\Scripts\activate.bat %USERPROFILE%\miniconda3\envs\lpydev
+
+Otherwise, adapt the command to the path where you installed miniconda3.
+
+Then you can compile with the following commands:
+
+.. code-block:: command
+
+ mkdir build
+ cd build
+ cmake .. -G "Visual Studio 16 2019" ^
+ -Wno-dev ^
+ -DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX%\Library ^
+ -DCMAKE_PREFIX_PATH=%CONDA_PREFIX%\Library ^
+ -DCMAKE_INSTALL_RPATH:STRING=%CONDA_PREFIX%\Library\lib ^
+ -DCMAKE_INSTALL_NAME_DIR=%CONDA_PREFIX%\Library\lib ^
+ -DPython3_EXECUTABLE=%CONDA_PREFIX%\python.exe
+
+ cmake --build . --parallel %NUMBER_OF_PROCESSORS% --config Release --target install
+ cd ..
+
+Note: you can only compile using the config **Release** and the target **install** on Windows.
+
+To install L-Py on your environment
+
+.. code-block:: command
+
+ python setup.py install
+
+to install it into you python system.
+
+To run test,
+
+.. code-block:: command
+
+ cd test/
+ nosetests
+
+To launch the visual editor, you can type in your shell
+
+.. code-block:: command
+
+ lpy
+
Notes on dependencies
========================
diff --git a/windows_build_dev.bat b/windows_build_dev.bat
index 220e6b99..f002afb2 100644
--- a/windows_build_dev.bat
+++ b/windows_build_dev.bat
@@ -7,7 +7,14 @@
:: CHECK THE VERSION IT PULLS. Sometimes Conda decides to pull an older version. In that case, specify openalea.lpy=3.8.0
:: You should adjust the path to your conda environment in the variable CONDA_PREFIX
-set CONDA_PREFIX=%USERPROFILE%\miniconda3\envs\lpydev
+:: Initialize build tools
+CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"
+
+:: Initialize conda environment
+CALL "%USERPROFILE%\miniconda3\Scripts\activate.bat" "%USERPROFILE%\miniconda3\envs\lpydev"
+
+echo %CONDA_PREFIX%
+
set BUILDDIR=build
:: using "clean" as an argument will delete the build directory
@@ -21,6 +28,8 @@ set BUILD_CONFIG=Release
set LIBRARY_LIB=%CONDA_PREFIX%\Library\lib
set LIBRARY_PREFIX=%CONDA_PREFIX%\Library
+if not exist %BUILDDIR% mkdir %BUILDDIR%
+
cd %BUILDDIR%
cmake .. -G "Visual Studio 16 2019" ^
@@ -46,7 +55,5 @@ if errorlevel 1 exit /b
cd ..
%PYTHON% setup.py install
-:: if you want to run the program, you must have your conda environment activated
-:: it won't not be the case if you're running this script in a simple Developer Command Prompt.
-
+:: You can run the IDE directly by de-commenting this line below.
:: %PYTHON% %CONDA_PREFIX%\Scripts\lpy-script.pyw
\ No newline at end of file
From 86586e4ef24ccd7813740441171d9b2d9eebf64a Mon Sep 17 00:00:00 2001
From: Jonathan LEVY <23365238+j-levy@users.noreply.github.com>
Date: Fri, 4 Jun 2021 12:55:59 +0200
Subject: [PATCH 5/9] don't re-activate is it's already set
---
windows_build_dev.bat | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/windows_build_dev.bat b/windows_build_dev.bat
index f002afb2..26b85c54 100644
--- a/windows_build_dev.bat
+++ b/windows_build_dev.bat
@@ -8,10 +8,10 @@
:: You should adjust the path to your conda environment in the variable CONDA_PREFIX
:: Initialize build tools
-CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"
+IF "%VSINSTALLDIR%" == "" CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"
:: Initialize conda environment
-CALL "%USERPROFILE%\miniconda3\Scripts\activate.bat" "%USERPROFILE%\miniconda3\envs\lpydev"
+IF "%CONDA_PREFIX%" == "" CALL "%USERPROFILE%\miniconda3\Scripts\activate.bat" "%USERPROFILE%\miniconda3\envs\lpydev"
echo %CONDA_PREFIX%
@@ -20,7 +20,6 @@ set BUILDDIR=build
:: using "clean" as an argument will delete the build directory
if "%1"=="clean" echo "CLEANING BEFORE BUILD."
if "%1"=="clean" rmdir /s /q %BUILDDIR%
-if "%1"=="clean" mkdir %BUILDDIR%
set PYTHON=%CONDA_PREFIX%\python.exe
:: BUILD_CONFIG must be Release because conda does not provide debug symbols for Windows.
@@ -31,7 +30,7 @@ set LIBRARY_PREFIX=%CONDA_PREFIX%\Library
if not exist %BUILDDIR% mkdir %BUILDDIR%
cd %BUILDDIR%
-
+cmake --version
cmake .. -G "Visual Studio 16 2019" ^
-Wno-dev ^
-DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
From bdb6e3bcc70059697799b0990b9c6df406287176 Mon Sep 17 00:00:00 2001
From: Jonathan LEVY <23365238+j-levy@users.noreply.github.com>
Date: Mon, 7 Jun 2021 15:44:02 +0200
Subject: [PATCH 6/9] removed unwanted exit
---
macos_build.sh | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/macos_build.sh b/macos_build.sh
index 3011b420..2b563427 100755
--- a/macos_build.sh
+++ b/macos_build.sh
@@ -9,7 +9,6 @@ if ! [[ -d build ]]; then
echo "creating build directory"
mkdir build
fi
-exit
# ld crashes when it sees a symbol it cannot resolve.
# In this case, we must either mark all incriminated symbols as Undefined (WHICH IS DANGEROUS),
@@ -39,4 +38,4 @@ NBPROC=$(sysctl -a | grep machdep.cpu.thread_count | sed s/"machdep.cpu.thread_c
make -j $NBPROC
make install
cd ..
-python setup.py install
\ No newline at end of file
+python setup.py install
From 173efab597fb34c7f7a326d5c2c17a7f9b52e27e Mon Sep 17 00:00:00 2001
From: Jonathan LEVY <23365238+j-levy@users.noreply.github.com>
Date: Fri, 11 Jun 2021 14:48:16 +0200
Subject: [PATCH 7/9] add Python3_LIBRARIES to link, CRASH on macOS?WTF
---
src/cpp/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt
index 24d981ac..502ca52a 100644
--- a/src/cpp/CMakeLists.txt
+++ b/src/cpp/CMakeLists.txt
@@ -8,6 +8,7 @@ add_library(lpy SHARED ${SRC_FILES})
target_link_libraries(lpy ${PLANTGL_LIBRARIES})
target_link_libraries(lpy Qt5::Core Qt5::Concurrent)
+target_link_libraries(lpy ${Python3_LIBRARIES})
pgllib_link_python(lpy)
pgllib_link_boost(lpy)
From 97e777128841615b799dcdcff445bfc34f74c6ca Mon Sep 17 00:00:00 2001
From: Jonathan LEVY <23365238+j-levy@users.noreply.github.com>
Date: Mon, 14 Jun 2021 11:50:39 +0200
Subject: [PATCH 8/9] added undefined dynamic_lookup flag for macos
---
CMakeLists.txt | 7 +++++++
macos_build.sh | 8 --------
src/cpp/CMakeLists.txt | 5 ++++-
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e1ae0a8a..56543388 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,6 +37,13 @@ if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
+## When linking, Python libs are required, so I advised I could use: "target_library_link(targetname ${Python3_LIBRARIES})"
+## But AppleClang has difficulties linking with Python3_LIBRARIES, I don't know why.
+## It DOES link with it, but when running it crashes mysteriously on a Python Malloc (what???)
+## instead, I use this undefined dynamic_lookup flag to let the dynamic libraries be found when run.
+if (APPLE)
+ SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
+endif()
## ###################################################################
## Dependencies
diff --git a/macos_build.sh b/macos_build.sh
index 2b563427..f6c4c26a 100755
--- a/macos_build.sh
+++ b/macos_build.sh
@@ -10,14 +10,6 @@ if ! [[ -d build ]]; then
mkdir build
fi
-# ld crashes when it sees a symbol it cannot resolve.
-# In this case, we must either mark all incriminated symbols as Undefined (WHICH IS DANGEROUS),
-# or tell ld to shut up about this. I chose the 2nd option here out of laz
-# More on this: https://stackoverflow.com/questions/36662920/xcode-clang-link-build-dynamic-framework-or-dylib-not-embed-dependencies
-# More on this: https://stackoverflow.com/questions/17281901/ignoring-an-undefined-symbol-in-a-dynamic-library-from-xcode
-# More on this: https://developer.apple.com/forums/thread/17630
-export LDFLAGS="-undefined dynamic_lookup ${LDFLAGS}"
-
export PREFIX=${CONDA_PREFIX}
export PYTHON=${CONDA_PREFIX}/bin/python
diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt
index 502ca52a..0a284f5c 100644
--- a/src/cpp/CMakeLists.txt
+++ b/src/cpp/CMakeLists.txt
@@ -8,7 +8,6 @@ add_library(lpy SHARED ${SRC_FILES})
target_link_libraries(lpy ${PLANTGL_LIBRARIES})
target_link_libraries(lpy Qt5::Core Qt5::Concurrent)
-target_link_libraries(lpy ${Python3_LIBRARIES})
pgllib_link_python(lpy)
pgllib_link_boost(lpy)
@@ -20,6 +19,10 @@ if (WIN32)
target_compile_definitions(lpy PRIVATE LPY_MAKEDLL)
endif()
+if (APPLE)
+ SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
+endif()
+
# --- Output Library
install(TARGETS lpy LIBRARY DESTINATION "lib")
From d7573dde1af6fa3efc2fe302fa53da4a9f6ceb99 Mon Sep 17 00:00:00 2001
From: Jonathan LEVY <23365238+j-levy@users.noreply.github.com>
Date: Mon, 14 Jun 2021 12:17:13 +0200
Subject: [PATCH 9/9] activate conda env is not activated
---
macos_build.sh | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/macos_build.sh b/macos_build.sh
index f6c4c26a..601dd121 100755
--- a/macos_build.sh
+++ b/macos_build.sh
@@ -1,6 +1,9 @@
#!/usr/local/bin/bash
+## Note: this script can also be run in ZSH if, for whatever reason, you want to run it in ZSH (the default shell for macOS 10.15+)
+#!/bin/zsh
+
echo $1
-if [ -d build ] && [ "$1" == "clean" ]; then
+if [[ -d build ]] && [[ "$1" == "clean" ]]; then
echo "cleaning build directory"
rm -rf build
fi
@@ -10,6 +13,24 @@ if ! [[ -d build ]]; then
mkdir build
fi
+export ENV_NAME=lpydev
+if [[ ${CONDA_PREFIX} != ${ENV_NAME} ]] ; then
+ echo "initialize CONDA"
+ if [[ -d $HOME/miniconda3/ ]] ; then
+ source ~/miniconda3/etc/profile.d/conda.sh
+ fi
+ if [[ -d $HOME/anaconda3/ ]] ; then
+ source ~/anaconda3/etc/profile.d/conda.sh
+ fi
+ if [[ ${CONDA_EXE} == "" ]] ; then
+ echo "error activating conda. Did you install it in the default directory? Exit."
+ exit
+ fi
+ conda activate ${ENV_NAME}
+fi
+echo "Conda prefix: ${CONDA_PREFIX}"
+
+
export PREFIX=${CONDA_PREFIX}
export PYTHON=${CONDA_PREFIX}/bin/python
@@ -19,7 +40,7 @@ cmake \
-DPLANTGL_ROOT=../plantgl/build-cmake/ \
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
-DCMAKE_PREFIX_PATH=${PREFIX} \
- -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_BUILD_TYPE=Debug \
-DPython3_EXECUTABLE=${PYTHON} \
..