diff --git a/CMakeLists.txt b/CMakeLists.txt index e92c23e..4a3cd20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,150 +1,146 @@ cmake_minimum_required(VERSION 3.1..3.19) # Basic settings # ============== project(GooseFEM) option(BUILD_TESTS "${PROJECT_NAME}: Build tests" OFF) option(BUILD_EXAMPLES "${PROJECT_NAME}: Build examples" OFF) option(BUILD_DOCS "${PROJECT_NAME}: Build docs" OFF) option(CHECK_DOCS "${PROJECT_NAME}: Check docs (throw error for every warning)" OFF) # Version # ======= -IF(DEFINED ENV{PKG_VERSION}) - set(GOOSEFEM_VERSION $ENV{PKG_VERSION}) -else() - execute_process( - COMMAND python -c "from setuptools_scm import get_version; print(get_version())" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GOOSEFEM_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() +execute_process( + COMMAND python -c "from setuptools_scm import get_version; print(get_version())" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GOOSEFEM_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) message(STATUS "Building ${PROJECT_NAME} ${GOOSEFEM_VERSION}") # Set target # ========== find_package(xtensor REQUIRED) add_library(GooseFEM INTERFACE) target_include_directories(GooseFEM INTERFACE $ $) target_link_libraries(GooseFEM INTERFACE xtensor) # Installation # ============ include(CMakePackageConfigHelpers) include(GNUInstallDirs) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION include) configure_file("include/${PROJECT_NAME}/version.h" "${CMAKE_CURRENT_BINARY_DIR}/version.h" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/version.h" DESTINATION "include/${PROJECT_NAME}/") install(TARGETS GooseFEM EXPORT GooseFEM-targets) install( EXPORT GooseFEM-targets FILE "${PROJECT_NAME}Targets.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") set(_GOOSEFEM ${CMAKE_SIZEOF_VOID_P}) unset(CMAKE_SIZEOF_VOID_P) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" VERSION ${GOOSEFEM_VERSION} COMPATIBILITY AnyNewerVersion) set(CMAKE_SIZEOF_VOID_P ${_GOOSEFEM}) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/") # Add builds # ========== include("${PROJECT_NAME}Config.cmake") include(CTest) # Tests if(BUILD_TESTS) enable_testing() add_subdirectory(test/basic) enable_testing() add_subdirectory(test/gmat) endif() # Examples if(BUILD_EXAMPLES) enable_testing() add_subdirectory(docs/examples) endif() # Check docs: only this library, throw error for every warning if(CHECK_DOCS) find_package(Doxygen REQUIRED) set(DOXYGEN_EXCLUDE_SYMBOLS detail) set(DOXYGEN_CASE_SENSE_NAMES YES) set(DOXYGEN_USE_MATHJAX YES) set(DOXYGEN_QUIET YES) set(DOXYGEN_WARN_IF_UNDOCUMENTED YES) set(DOXYGEN_WARN_AS_ERROR YES) set(DOXYGEN_ALIASES "rst=\\verbatim embed:rst:leading-asterisk" "endrst=\\endverbatim" "license=@par License:") doxygen_add_docs(check_docs "${CMAKE_CURRENT_SOURCE_DIR}/include") endif() # Build docs: include dependencies if(BUILD_DOCS) find_package(Doxygen REQUIRED) set(DOXYGEN_EXCLUDE_SYMBOLS detail) set(DOXYGEN_CASE_SENSE_NAMES YES) set(DOXYGEN_USE_MATHJAX YES) set(DOXYGEN_GENERATE_TREEVIEW YES) set(DOXYGEN_JAVADOC_AUTOBRIEF YES) set(DOXYGEN_MACRO_EXPANSION YES) set(DOXYGEN_SOURCE_BROWSER YES) set(DOXYGEN_GENERATE_XML YES) set(DOXYGEN_QUIET YES) set(DOXYGEN_WARN_IF_UNDOCUMENTED YES) set(DOXYGEN_ALIASES "rst=\\verbatim embed:rst:leading-asterisk" "endrst=\\endverbatim" "license=@par License:") set(DOXYGEN_STRIP_FROM_INC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include") set(DOXYGEN_STRIP_FROM_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include") doxygen_add_docs(docs "${CMAKE_CURRENT_SOURCE_DIR}/include") endif() diff --git a/docs/install.rst b/docs/install.rst index b28131e..18010c2 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -1,101 +1,126 @@ **************** Getting GooseFEM **************** Using conda =========== The easiest is to use *conda* to install *GooseFEM*:: conda install -c conda-forge goosefem This will install all the necessary runtime dependencies as well. .. tip:: - The runtime dependencies (for both the C++ and the Python APIs) are also listed in - ``environment.yaml``. + The runtime dependencies (for both the C++ and the Python APIs) + are also listed in ``environment.yaml``. One could install those dependencies in an activated environment by: .. code-block:: cpp conda env update --file environment.yaml - In addition, one could further extend one's environment - to also run the tests and the examples using: - - .. code-block:: cpp - - conda env update --file environment_test.yaml - conda env update --file environment_examples.yaml - - Note that ``environment_test.yaml`` and ``environment_examples.yaml`` extend the environment. - In each case one **also** has to install the dependencies in ``environment.yaml``. + This will install the dependencies to run tests and examples. From source =========== Download the package:: git checkout https://github.com/tdegeus/GooseFEM.git cd GooseFEM -Install headers, *CMake* and *pkg-config* support:: +Install headers, *CMake* and *pkg-config* support: + +.. code-block:: none + + cmake -Bbuild + cd build + cmake --install . + +.. note:: + + The version is determined from the latest git tag, and possible commits since that tag. + Internally Python's ``setuptools_scm`` is used to this end. + In case that you are not working from a clone of the repository you have to set + the version manually, **before** configuring with CMake: + + .. code-block:: none + + export SETUPTOOLS_SCM_PRETEND_VERSION="1.2.3" + cmake -Bbuild + cd build + cmake --install . + + In Windows replace the first line with + + .. code-block:: none + + set SETUPTOOLS_SCM_PRETEND_VERSION="1.2.3" + +.. tip:: + + To install in a loaded conda environment use + + .. code-block:: none + + cmake -Bbuild -DCMAKE_INSTALL_PREFIX:PATH="${CONDA_PREFIX}" + cd build + cmake --install . - cmake . - make install .. _install_python: Python interface ================ Using conda ^^^^^^^^^^^ The quickest (but not the most efficient!) is to use *conda* to install *GooseFEM*:: conda install -c conda-forge python-goosefem .. warning:: This package does not benefit from *xsimd* optimisation, as it is not compiled on your hardware. You'll have to compile by hand to benefit from *xsimd* optimisation. .. _install_python_source: From source ^^^^^^^^^^^ Start by installing the dependencies, for example using *conda*:: conda install -c conda-forge pyxtensor eigen xsimd Note that *xsimd* is optional, but recommended. .. note:: You can also use:: python -m pip install pyxtensor pybind11 for use without *conda*. Note that you install *Eigen* and *xsimd* yourself in such a way that Python can find it in order to use it. Then, download the package:: git checkout https://github.com/tdegeus/GooseFEM.git cd GooseFEM Install the package using:: python -m pip install . .. note:: The following will give more readable output:: python setup.py build python setup.py install diff --git a/setup.py b/setup.py index c906452..e138466 100644 --- a/setup.py +++ b/setup.py @@ -1,55 +1,52 @@ from setuptools import setup, Extension import re import os import pybind11 import pyxtensor from os import environ +from setuptools_scm import get_version -version = environ.get('PKG_VERSION') - -if version is None: - from setuptools_scm import get_version - version = get_version() +version = get_version() include_dirs = [ os.path.abspath('include/'), pyxtensor.find_pyxtensor(), pyxtensor.find_pybind11(), pyxtensor.find_xtensor(), pyxtensor.find_xtl(), pyxtensor.find_eigen()] build = pyxtensor.BuildExt xsimd = pyxtensor.find_xsimd() if xsimd: if len(xsimd) > 0: include_dirs += [xsimd] build.c_opts['unix'] += ['-march=native', '-DXTENSOR_USE_XSIMD'] build.c_opts['msvc'] += ['/DXTENSOR_USE_XSIMD'] build.c_opts['unix'] += ['-DGOOSEFEM_VERSION="{0:s}"'.format(version)] build.c_opts['msvc'] += ['/DGOOSEFEM_VERSION="{0:s}"'.format(version)] ext_modules = [Extension( 'GooseFEM', ['python/main.cpp'], include_dirs = include_dirs, language = 'c++')] setup( name = 'GooseFEM', description = 'Finite element meshes, quadrature, and assembly tools', long_description = 'Finite element meshes, quadrature, and assembly tools', version = version, license = 'GPLv3', author = 'Tom de Geus', author_email = 'tom@geus.me', url = 'https://github.com/tdegeus/GooseFEM', ext_modules = ext_modules, install_requires = ['pybind11', 'pyxtensor'], cmdclass = {'build_ext': build}, zip_safe = False)