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

Feature/fix macos build #31

Merged
merged 10 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
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
24 changes: 23 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +37,6 @@ build-scons_qt5
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
Expand All @@ -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.
Expand Down Expand Up @@ -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/

Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 64 additions & 1 deletion doc/user/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
========================
Expand Down
54 changes: 54 additions & 0 deletions macos_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/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
echo "cleaning build directory"
rm -rf build
fi

if ! [[ -d build ]]; then
echo "creating build directory"
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


cd build
cmake \
-DPLANTGL_ROOT=../plantgl/build-cmake/ \
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
-DCMAKE_PREFIX_PATH=${PREFIX} \
-DCMAKE_BUILD_TYPE=Debug \
-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
4 changes: 4 additions & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,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")
Expand Down
11 changes: 11 additions & 0 deletions src/openalea/lpy/gui/lpymainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@
<addaction name="actionSave"/>
<addaction name="actionSaveAs"/>
<addaction name="actionSaveAll"/>
<addaction name="actionSaveSession"/>
<addaction name="actionClose"/>
<addaction name="menuSVN"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -1197,6 +1198,7 @@
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSaveAll"/>
<addaction name="actionSaveSession"/>
<addaction name="actionClose"/>
</widget>
<widget class="QToolBar" name="LsytemBar">
Expand Down Expand Up @@ -1384,6 +1386,15 @@
<string>Save As</string>
</property>
</action>
<action name="actionSaveSession">
<property name="icon">
<iconset resource="lpyresources.qrc">
<normaloff>:/images/icons/filesave.png</normaloff>:/images/icons/filesave.png</iconset>
</property>
<property name="text">
<string>Save Session</string>
</property>
</action>
<action name="actionExit">
<property name="icon">
<iconset resource="lpyresources.qrc">
Expand Down
58 changes: 58 additions & 0 deletions windows_build_dev.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@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

:: Initialize build tools
IF "%VSINSTALLDIR%" == "" CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"

:: Initialize conda environment
IF "%CONDA_PREFIX%" == "" 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
if "%1"=="clean" echo "CLEANING BEFORE BUILD."
if "%1"=="clean" rmdir /s /q %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

if not exist %BUILDDIR% mkdir %BUILDDIR%

cd %BUILDDIR%
cmake --version
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

:: You can run the IDE directly by de-commenting this line below.
:: %PYTHON% %CONDA_PREFIX%\Scripts\lpy-script.pyw