diff --git a/CMakeLists.txt b/CMakeLists.txt index e29c88e7..4a18a4d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # --- CMake Modules -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.20) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include("Anaconda") include("pywrapper") @@ -11,8 +11,7 @@ project(lpy_project CXX) # --- Build setup -set(CMAKE_INCLUDE_PATH "$ENV{CONDA_PREFIX}/include" ${CMAKE_INCLUDE_PATH}) -set(CMAKE_LIBRARY_PATH "$ENV{CONDA_PREFIX}/lib" ${CMAKE_LIBRARY_PATH}) + set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") @@ -56,13 +55,15 @@ endif() # --- Python -set(Python3_FIND_VIRTUALENV FIRST) +set(Python_FIND_VIRTUALENV FIRST) if (WIN32) # needed when we run cmake in a conda environment - set(Python3_FIND_REGISTRY LAST) + set(Python_FIND_REGISTRY LAST) endif() -find_package (Python3 COMPONENTS Interpreter Development NumPy REQUIRED) +set(Python_ROOT_DIR "$ENV{CONDA_PREFIX}") +find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + include_directories(${Python3_INCLUDE_DIRS}) # --- Libraries @@ -72,6 +73,10 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Concurrent) find_package(PlantGL REQUIRED) +if(POLICY CMP0167) # Removes find boost warning + cmake_policy(SET CMP0167 NEW) +endif() + set(Boost_NO_SYSTEM_PATHS ON) set(Boost_USE_MULTITHREAD ON) set(Boost_USE_STATIC_LIBS OFF) @@ -79,12 +84,6 @@ set(BUILD_SHARED_LIBS ON) set(boost_python python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}) -find_package(Boost 1.69 COMPONENTS system ${boost_python} REQUIRED) -if (NOT Boost_FOUND) - message("Boost not found, trying again") - set(boost_python python) - find_package(Boost 1.69 COMPONENTS system ${boost_python} REQUIRED) -endif() find_package(Boost COMPONENTS system ${boost_python} REQUIRED) @@ -105,4 +104,4 @@ endif() add_subdirectory("src/cpp") add_subdirectory("src/wrapper") -install_share("share" "lpy") \ No newline at end of file +install_share("share" "lpy") diff --git a/setup.py b/bckup_setup.py similarity index 100% rename from setup.py rename to bckup_setup.py diff --git a/cmake/Anaconda.cmake b/cmake/Anaconda.cmake index 8932283d..f6b6036a 100644 --- a/cmake/Anaconda.cmake +++ b/cmake/Anaconda.cmake @@ -2,14 +2,16 @@ if (DEFINED ENV{CONDA_PREFIX}) # Anaconda Environment message(STATUS "Anaconda environment detected: " $ENV{CONDA_PREFIX}) - - + + set(CMAKE_INCLUDE_PATH "$ENV{CONDA_PREFIX}/include" ${CMAKE_INCLUDE_PATH}) + set(CMAKE_LIBRARY_PATH "$ENV{CONDA_PREFIX}/lib" ${CMAKE_LIBRARY_PATH}) + if (DEFINED ENV{PREFIX}) file(TO_CMAKE_PATH $ENV{PREFIX} TMP_CONDA_ENV) else() file(TO_CMAKE_PATH $ENV{CONDA_PREFIX} TMP_CONDA_ENV) endif() - + if (WIN32) set(CONDA_ENV "${TMP_CONDA_ENV}/Library/") else() @@ -45,15 +47,36 @@ if (DEFINED ENV{CONDA_BUILD}) if (APPLE) set(CMAKE_OSX_ARCHITECTURES $ENV{OSX_ARCH}) endif() - + set(CMAKE_CXX_COMPILER $ENV{CXX}) set(CMAKE_CXX_COMPILER_RANLIB $ENV{RANLIB}) set(CMAKE_CXX_COMPILER_AR $ENV{AR}) # where is the target environment - set(CMAKE_FIND_ROOT_PATH $ENV{PREFIX} $ENV{BUILD_PREFIX} $ENV{BUILD_PREFIX}/$ENV{HOST}/sysroot $ENV{CONDA_BUILD_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH $ENV{PREFIX} $ENV{BUILD_PREFIX}) + if (APPLE) + list(APPEND CMAKE_FIND_ROOT_PATH $ENV{CONDA_BUILD_SYSROOT} ) + endif() + if (WIN32) + list(APPEND CMAKE_FIND_ROOT_PATH $ENV{BUILD_PREFIX}/Library/usr $ENV{PREFIX}/Library/usr) + set(CMAKE_INCLUDE_PATH "$ENV{BUILD_PREFIX}/Library/usr/include" ${CMAKE_INCLUDE_PATH}) + set(CMAKE_LIBRARY_PATH "$ENV{BUILD_PREFIX}/Library/usr/lib" ${CMAKE_LIBRARY_PATH}) + endif() + if (UNIX) + # I add both old stype and new style cdts : https://github.com/conda-forge/cdt-builds#old-stylelegacy-vs-new-style-cdts + list(APPEND CMAKE_FIND_ROOT_PATH $ENV{BUILD_PREFIX}/x86_64-conda-linux-gnu/sysroot $ENV{BUILD_PREFIX}/$ENV{HOST}/sysroot ) + list(APPEND CMAKE_FIND_ROOT_PATH $ENV{PREFIX}/x86_64-conda-linux-gnu/sysroot $ENV{PREFIX}/$ENV{HOST}/sysroot ) + + link_directories($ENV{BUILD_PREFIX}/x86_64-conda-linux-gnu/sysroot/lib64 $ENV{BUILD_PREFIX}/$ENV{HOST}/sysroot/lib64) + link_directories($ENV{BUILD_PREFIX}/x86_64-conda-linux-gnu/sysroot/lib $ENV{BUILD_PREFIX}/$ENV{HOST}/sysroot/lib) + link_directories($ENV{BUILD_PREFIX}/x86_64-conda-linux-gnu/sysroot/usr/lib64 $ENV{BUILD_PREFIX}/$ENV{HOST}/sysroot/usr/lib64) + link_directories($ENV{BUILD_PREFIX}/x86_64-conda-linux-gnu/sysroot/usr/lib $ENV{BUILD_PREFIX}/$ENV{HOST}/sysroot/usr/lib) + endif() - message("CMAKE_FIND_ROOT_PATH :" ${CMAKE_FIND_ROOT_PATH}) + message(STATUS "CMAKE_FIND_ROOT_PATH :") + foreach(dir ${CMAKE_FIND_ROOT_PATH}) + message(STATUS " - " ${dir}) + endforeach() # search for programs in the build host directories set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) @@ -86,4 +109,12 @@ else() message(STATUS "Install Prefix: " ${CMAKE_INSTALL_PREFIX}) endif() +function(install_pgllib libname) + message("Installing ${libname} in ${CONDA_ENV}lib/") + install(TARGETS ${libname} + RUNTIME DESTINATION "${CONDA_ENV}bin/" + LIBRARY DESTINATION "${CONDA_ENV}lib/" + ARCHIVE DESTINATION "${CONDA_ENV}lib/" + ) +endfunction() diff --git a/cmake/pywrapper.cmake b/cmake/pywrapper.cmake index 3d1b9d9b..31506dbe 100644 --- a/cmake/pywrapper.cmake +++ b/cmake/pywrapper.cmake @@ -1,15 +1,11 @@ function(pgllib_link_python libwrapname) - if(NOT APPLE OR NOT USE_CONDA) - if (Python3_FOUND) - target_link_libraries(${libwrapname} Python3::Python) - elseif (Python2_FOUND) - target_link_libraries(${libwrapname} Python2::Python) + if (APPLE) + target_link_libraries(${libwrapname} "-undefined dynamic_lookup") + else() + target_link_libraries(${libwrapname} Python3::Python) endif() - else() - message(STATUS "Do not link with Python directly : " ${libwrapname}) - endif() endfunction() function(pgllib_link_boost libwrapname) @@ -35,5 +31,5 @@ function(pglwrapper_install libwrapname) endfunction() function(install_share sharedirectory project) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${sharedirectory}/ DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${project}") + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${sharedirectory}/ DESTINATION "${CONDA_ENV}/share/${project}") endfunction() diff --git a/conda/bld.bat b/conda/bckup_bld.bat similarity index 100% rename from conda/bld.bat rename to conda/bckup_bld.bat diff --git a/conda/build.sh b/conda/bckup_build.sh similarity index 100% rename from conda/build.sh rename to conda/bckup_build.sh diff --git a/conda/environment.yml b/conda/environment.yml new file mode 100644 index 00000000..53cd7212 --- /dev/null +++ b/conda/environment.yml @@ -0,0 +1,11 @@ +name: lpy_dev +channels: + - openalea3/label/dev + - openalea3/label/rc + - conda-forge +dependencies: + - openalea.plantgl + - qtconsole + - pip + - pip: + - -e .."[doc, test]" diff --git a/conda/meta.yaml b/conda/meta.yaml index 006368a4..a917bad4 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -8,20 +8,26 @@ source: path: .. about: - home: https://github.com/openalea/plantgl + home: https://github.com/openalea/lpy license: Cecill-C - summary: An open-source graphic toolkit for the creation, simulation and analysis of 3D virtual plants. + summary: Lindenmayer Systems in Python package for OpenAlea. build: string: py{{ PY_VER }} number: 0 preserve_egg_dir: True + script: + - {{ PYTHON }} -m pip install --prefix={{ PREFIX }} . --no-deps --no-build-isolation -vv + entry_points: + - lpy = openalea.lpy.gui.lpystudio:main + - cpfg2lpy = openalea.lpy.cpfg_compat.cpfg2lpy:main requirements: host: - python - setuptools - setuptools_scm + - scikit-build-core - openalea.plantgl - boost - pyqt @@ -38,7 +44,6 @@ requirements: - setuptools - openalea.plantgl - boost - - pyqt - ipython - qtconsole - jupyter_client # <6 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..b3f15f99 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,96 @@ +[build-system] +requires = ["scikit-build-core", "setuptools-scm"] +build-backend = "scikit_build_core.build" + +[project] +name = "openalea.lpy" +authors = [ + {name = "Frederic Boudon"} +] +description = "Lindenmayer Systems in Python package for OpenAlea." +requires-python = ">=3.9" +classifiers = [ + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Topic :: Scientific/Engineering", +] +license-files = ["LICEN[CS]E*"] +# version = "1.0.2" +readme = "README.rst" +dynamic = ["version"] +dependencies = [ + "pandas", + "scipy", +] + +[project.optional-dependencies] +doc = [ + "sphinx", + "sphinx-autoapi", + "sphinx-copybutton", + "nbsphinx", + "pydata-sphinx-theme", + "myst-parser", + "sphinx-favicon" +] +notebook = [ + "jupyter", + "ipywidgets" +] +test = [ + "pytest", + "pytest-cov", +] + +[tool.conda.environment] +channels = [ + "openalea3", + "conda-forge" +] +dependencies = [ + "openalea.plantgl", + "qtconsole", +] + +[tool.setuptools_scm] +# Format version to ease alignment with conda/meta.yaml tag-based versioning +fallback_version = "3.14.1.dev0" +version_scheme = "guess-next-dev" +local_scheme = "no-local-version" + +[tool.scikit-build] +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +build-dir="./build/" +sdist.include = ["*.so", "*.dylib", "*.dll", "*.pyd", '*.lpy','*.ui','*.qrc','*.json','*.png'] +sdist.exclude = ["*.pyc", "*.pyo"] +logging.level = "WARNING" +build.verbose = true +experimental = true + +[tool.scikit-build.cmake] +build-type="Release" +source-dir="." + +[tool.scikit-build.wheel] +packages = ["src/openalea/"] + +[project.urls] +Homepage = "https://github.com/openalea/lpy" +"Bug Tracker" = "https://github.com/openalea/lpy/issues" +Discussions = "https://github.com/openalea/lpy/discussions" +Changelog = "https://github.com/openalea/lpy/releases" + +[project.entry-points."wralea"] +"lpy" = "openalea.lpy_wralea" + +[project.scripts] +"lpy" = "openalea.lpy.gui.lpystudio:main" +"cpfg2lpy" = "openalea.lpy.cpfg_compat.cpfg2lpy:main" diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 5801c2f9..6c649ad3 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -25,8 +25,8 @@ endif() # --- Output Library -install(TARGETS lpy LIBRARY DESTINATION "lib") +install_pgllib(lpy) # --- Install Headers -install(DIRECTORY "." DESTINATION "include/lpy" FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") +install(DIRECTORY "." DESTINATION "${CONDA_ENV}include/lpy" FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") diff --git a/src/openalea/lpy/gui/lpystudio.py b/src/openalea/lpy/gui/lpystudio.py index 412feb4e..e13836cd 100644 --- a/src/openalea/lpy/gui/lpystudio.py +++ b/src/openalea/lpy/gui/lpystudio.py @@ -1120,7 +1120,7 @@ def main(): splash.finish(w) w.splash = splash - qapp.exec_() + return qapp.exec_() if __name__ == '__main__': main()