The code.ill.fr has been recreated and upgraded with the latest version this weekend, If you encounter any problem please inform the Helpdesk.

Commit d89f5fa3 authored by Shervin Nourbakhsh's avatar Shervin Nourbakhsh
Browse files

Improved cmake build and install, fixed packaging with cpack for debian:

 - auto download of pybind11 (needed on ubuntu bionic)
 - cameo-api-python embedding the c++ api in the .so
 - debian package created by cpack
 - Virtual deb package cameo-server now provided by cameo-server-jzmq package
 - Other packages now requiring cameo-server as dependency
 - README documentation about how to compile and install
parent dc089610
cmake_minimum_required(VERSION 3.11.3)
cmake_minimum_required(VERSION 3.12.0)
# Project name and version
project(cameopy VERSION 1.0.0 LANGUAGES CXX)
project(cameo-api-python
VERSION 1.0.0
LANGUAGES CXX
HOMEPAGE_URL "https://code.ill.fr/cameo/cameo"
)
#--------------- Helpers
include(GNUInstallDirs)
# Want to compile dynamic or static libraries
set(BUILD_SHARED_LIBS True)
include(CMakePackageConfigHelpers)
include(FetchContent)
include(ExternalProject)
# in order to find FindZeroMQ.cmake
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cameo-api-cpp/)
option(TESTING "Enable testing" OFF)
#------------------------------------------------------------ Dependencies
# 2.4.3 is the version that has been used for development and tests
find_package(pybind11 2.4.3 QUIET)
find_package(cameo 1.1 QUIET)
#------------------------------------------------------------
# Dependencies
#------------------------------------------------------------
#list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cameo-api-cpp/build/)
#message(STATUS ${CMAKE_MODULE_PATH})
find_package(cameo-api-cpp-static 1.1.0 REQUIRED) # provided by the C++ API
find_package(pybind11 2.4.3 QUIET)
if(NOT pybind11_FOUND)
message(WARNING "Using PYBIND11 from GIT repository")
ExternalProject_Add(pybind11
message(WARNING "Using pybind11 from GIT repository")
FetchContent_Declare(pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.5.0
GIT_TAG v2.4.3
GIT_SHALLOW True
#INSTALL_COMMAND ""
UPDATE_COMMAND ""
UPDATE_DISCONNECTED FALSE
CMAKE_ARGS -DPYBIND11_TEST=OFF -DPYBIND11_INSTALL=ON -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/pybind11_install/
#I am obliged to perform the install step otherwise some files from pybind are not put together and I don't manage to set it.
)
ExternalProject_Get_Property(pybind11 install_dir BINARY_DIR)
list(APPEND DEPENDENT_PACKAGES pybind11)
#set(pybind11_DIR ${install_dir})
set(pybind11_DIR ${CMAKE_CURRENT_BINARY_DIR}/pybind11_install/share/cmake/pybind11)
FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
FetchContent_Populate(pybind11)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
mark_as_advanced(PYBIND11_TEST)
mark_as_advanced(PYBIND11_INSTALL)
endif()
#else()
# find_package(pybind11 2.4.3 REQUIRED)
endif()
#------------------------------------------------------------
if(NOT cameo_FOUND)
ExternalProject_Add(cameo
GIT_REPOSITORY https://code.ill.fr/cameo/cameo-api-cpp.git
# GIT_TAG master_new
GIT_TAG master
GIT_REMOTE_NAME cameocpp
GIT_SHALLOW True
#SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cameo-api-cpp/
INSTALL_DIR ${CMAKE_INSTALL_PREFIX} # this does not work...
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
#INSTALL_COMMAND "" # this disables the install step for the external project
)
ExternalProject_Get_Property(cameo install_dir BINARY_DIR)
set(cameo_DIR ${BINARY_DIR})
list(APPEND DEPENDENT_PACKAGES cameo)
#set(cameo_DIR ${install_dir})
endif(NOT cameo_FOUND)
ExternalProject_Add(cameopython
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/
DEPENDS ${DEPENDENT_PACKAGES}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -Dpybind11_DIR=${pybind11_DIR} #pybind is fake-installed in the build
#INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
pybind11_add_module(cameopy src/Application.cpp)
#file(GENERATE OUTPUT /tmp/message.log CONTENT $<TARGET_PROPERTY:cameo,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(cameopy PRIVATE Cameo::cameo-api-cpp-static)
#target_compile_features(cameopy PUBLIC cxx_std_17)
#target_include_directories(cameopy
# PRIVATE $<TARGET_PROPERTY:Cameo::cameo-api-cpp,INTERFACE_INCLUDE_DIRECTORIES>
# )
#target_include_directories(${MODULE_NAME} ${cameo_INCLUDE_DIR})
set_target_properties(cameopy PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
)
if(TESTING)
enable_testing()
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
ExternalProject_Add(testing
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test/
DEPENDS ${DEPENDENT_PACKAGES}
CMAKE_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
INSTALL_COMMAND ""
#####------------------------------------------- copied from CMakeLists.txt of openPMD-api
if(WIN32)
set(CMAKE_INSTALL_PYTHONDIR_DEFAULT
"${CMAKE_INSTALL_LIBDIR}/site-packages"
)
else()
set(CMAKE_INSTALL_PYTHONDIR_DEFAULT
"${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages"
)
endif()
set(CMAKE_INSTALL_PYTHONDIR "${CMAKE_INSTALL_PYTHONDIR_DEFAULT}"
CACHE STRING "Location for installed python package"
)
endif(TESTING)
#set(CMAKE_PYTHON_OUTPUT_DIRECTORY
# "${openPMD_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}"
# CACHE PATH "Build directory for python modules"
# )
# set_target_properties(raytracing.py PROPERTIES
# # ARCHIVE_OUTPUT_NAME openpmd_api_cxx
# # LIBRARY_OUTPUT_NAME openpmd_api_cxx
# ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# LIBRARY_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api_api
# COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# )
# add_custom_command(TARGET raytracing.py POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# ${openPMD_SOURCE_DIR}/python/src/raytracing_api
# ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# )
##### End of ------------------------------------ copied from CMakeLists.txt of openPMD-api
#---------------
# Library version
write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY SameMajorVersion
VERSION ${PROJECT_VERSION}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
#if(CAMEOPYTHON_TESTS)
# message("TESTS have been enabled")
# enable_testing()
#
# add_subdirectory(test)
#endif(CAMEOPYTHON_TESTS)
#unset(CAMEOPYTHON_TESTS CACHE) # this removes the value from the CACHE, this is a trick to get the test compiled when running cmake --build . the second time
#------------------------------------------------------------
# Install
#------------------------------------------------------------
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/__init__.py
DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/${PROJECT_NAME}
)
install(TARGETS cameopy
EXPORT cameopyexport
LIBRARY DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/${PROJECT_NAME}
)
#ExternalProject_Add_StepDependencies(cameopython build cameocpp)
#------------------------------------------------------------
# CPack
#------------------------------------------------------------
include(${CMAKE_CURRENT_SOURCE_DIR}/packaging/CPackConfig.cmake)
include(CPack)
# cameo-python
# cameo-api-python
This library provides the Python API for Cameo.
## Compilation dependencies
- cmake
The API is obtained using pybind11 and the C++ Cameo API.
- [pybind11](https://github.com/pybind/pybind11)
- cmake 3.12.0
- [pybind11](https://github.com/pybind/pybind11)
The API is obtained using pybind11 and the C++ Cameo API. If the required version is not available on the system, it is automatically downloaded from source and compiled in place.
- [doctest](https://github.com/onqtam/doctest)
Testing is performed using the doctest framework.
- cameo-api-cpp-static: the static library need to be compiled first. See [here](../cameo-api-cpp/REDME.md) for compilation instructions of cameo-cpp-api.
Testing is performed using the doctest framework:
- [doctest](https://github.com/onqtam/doctest)
These packages can either be installed on the system (see exact name of the packages below), or be downloaded from GitHub and compiled from source if not found on the system.
For convenience, the packages for some major distributions are listed in the following:
### CENTOS 8
```yum install -y cmake pybind11-devel```
- CENTOS 8: `yum install -y cmake pybind11-devel`
- Ubuntu bionic: `sudo apt install libzmq3-dev`
*N.B.* `pybind11-dev` has version 2.0.1 while 2.4.3 is needed -> most recent version automatically downloaded and compiled from source
For testing:
```yum install -y doctest-devel```
## How to compile and install
### Ubuntu 18
```sudo apt install python3-pybind11 libzmq3-dev```
```
cmake -S . -B <build directory> -DCMAKE_PREFIX_PATH="<cpp api build directory> -D<OPTION>"
cmake --build <build directory>
```
Possible options are:
- CMAKE_INSTALL_PREFIX=<your_chosen_install_basepath>: to install in a non-standard directory
For testing:
```sudo apt install doctest-dev```
Debian packages can also be created by:
```
cpack --config <build directory>/CPackConfig.cmake -B <build directory>/packaging
```
and be found in `<build directory>/packaging`
## How to compile and install
You can run the `build.sh` script.
Don't forget to set your LD_LIBRARY_PATH to `/usr/local/lib64/`
......
#!/bin/bash
usage(){
echo "`basename $0` [INSTALL_PREFIX] [CMAKE_PREFIX_PATH]"
}
case $1 in
dev|DEV|devel|DEVEL)
DEV=true
INSTALL_PREFIX=${2:-/tmp/devel}
echo "[INFO] Development mode: installation directory is $INSTALL_PREFIX"
ARGS="-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DCMAKE_PREFIX_PATH=$3"
;;
"")
;;
*)
INSTALL_PREFIX=$1
ARGS="-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DCMAKE_PREFIX_PATH=$2"
;;
esac
# to force recompilation:
# cmake --build . --target cameo-api-cpp --clean-first
mkdir -p build/
cd build/
cmake .. $ARGS
# compile without the tests, because they need the rest to be compiled first
cmake --build . || {
echo "[ERROR]" >> /dev/stderr
exit 1
}
# if [ -n "$DEV" ];then
# echo "Enabling testing"
# # now enable the tests
# cmake -DCAMEOPYTHON_TESTS=ON $ARGS ..
# cmake --build . || exit 1
# fi
You can build the project with the aid of the build.sh script.
## Dependencies for testing:
Ubuntu bionic: `sudo apt install doctest-dev`
If you want to install it in a non-standard path (MY_INSTALL_PATH) and enable the testing:
## How to compile and install
```
./build.sh dev MY_INSTALL_PATH
cmake -S . -B <build_directory> -DCMAKE_PREFIX_PATH=<cpp_api_build_directory>
cmake --build <build_directory>
```
otherwise:
```./build.sh```
By default MY_INSTALL_PATH is `/tmp/devel/`
in order to install in a non-standard directory add the `-DCMAKE_INSTALL_PREFIX=<your_base_path>` to the first cmake invocation.
If you are using a non-standard path, the following environmental variables should then be set.
```
......@@ -21,7 +23,7 @@ Example for the fish shell:
#!/bin/fish
set -lx CMAKE_INSTALL_PREFIX /tmp/devel/
set -lx PYTHONPATH $PYTHONPATH $CMAKE_INSTALL_PREFIX/lib64/python3.6/site-packages/
set -lx LD_LIBRARY_PATH ${CMAKE_INSTALL_PREFIX}/lib64/
set -lx LD_LIBRARY_PATH $CMAKE_INSTALL_PREFIX/lib64/
```
# Testing
......
set(CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION ON)
set(CPACK_PACKAGE_CHECKSUM MD5)
set(CPACK_PACKAGE_CONTACT "Yannick Le Goc <legoc@ill.fr>")
set(CPACK_PACKAGE_VENDOR "ILL")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Cameo Python API")
set(CPACK_GENERATOR "DEB")
# #set(CPACK_PACKAGE_DESCRIPTION_FILE "/home/andy/vtk/CMake/Copyright.txt")
set(CPACK_PACKAGE_DESCRIPTION "Long description")
set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
set(CPACK_RPM_BUILDREQUIRES "cmake >= ${CMAKE_MINIMUM_REQUIRED_VERSION}")
set(CPACK_DEBIAN_PACKAGE_SECTION python)
# set(CPACK_RPM_PACKAGE_RELOCATABLE ON)
# set(CPACK_RPM_PACKAGE_LICENSE "EUPL v1.1")
set(CPACK_COMPONENTS_IGNORE_GROUPS ON)
set(CPACK_DEB_COMPONENT_INSTALL TRUE)
set(CPACK_RPM_COMPONENT_INSTALL TRUE)
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "python3:any, cameo-server (>=1.0.2)")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE all)
#set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
#set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON )
#set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY ">=")
# #if((${CMAKE_BUILD_TYPE} EQUAL "Debug") OR (${CMAKE_BUILD_TYPE} EQUAL "RelWithDebInfo"))
# # set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON)
# # set(CPACK_RPM_DEBUGINFO_PACKAGE ON)
# #endif()
# ####### CPACK RPM
# #message("CPACK SYSTEM NAME: ${CMAKE_SYSTEM_NAME}")
# cpack_add_component(lib
# DISPLAY_NAME "LIBB"
# DESCRIPTION "runtime library"
# REQUIRED #[HIDDEN | REQUIRED | DISABLED ]
# GROUP LIBBB
# #DEPENDS
# #[INSTALL_TYPES type1 type2 ... ]
# #[DOWNLOADED]
# #[ARCHIVE_FILE filename]
# #[PLIST filename]
# )
# cpack_add_component(dev
# DISPLAY_NAME "DEVV"
# DESCRIPTION "library development"
# #REQUIRED #[HIDDEN | REQUIRED | DISABLED ]
# GROUP DEVVV
# DEPENDS lib
# #[INSTALL_TYPES type1 type2 ... ]
# #[DOWNLOADED]
# #[ARCHIVE_FILE filename]
# #[PLIST filename]
# )
......@@ -18,7 +18,7 @@
#include <pybind11/stl.h>
namespace py = pybind11;
#include <cameo/cameo.h>
#include <cameo/api/cameo.h>
using namespace cameo::application;
#include <iostream>
......
if(NOT DEFINED PROJECT_NAME)
cmake_minimum_required(VERSION 3.7.2)
# Project name and version
project(cameopy VERSION 1.0.0 LANGUAGES CXX)
endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(BUILD_SHARED_LIBS True)
# this works only on linux....
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
#list(APPEND CMAKE_MODULE_PATH ${pybind11_DIR}/../pybind11/tools/)
#list(APPEND CMAKE_MODULE_PATH ${pybind11_DIR})
#list(APPEND CMAKE_PREFIX_PATH ${pybind11_DIR}/../)
#message(WARNING "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
#message(WARNING "CMAKE_ARGS: ${CMAKE_PREFIX_PATH}")
#message(WARNING "PYBIND11_DIR: ${pybind11_DIR}/../")
#------------------------------------------------------------
# Dependencies
#------------------------------------------------------------
message(STATUS ${CMAKE_PREFIX_PATH})
#list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(cameo 1.1.0 REQUIRED) # provided by the C++ API
#find_package(pybind11 CONFIG)
find_package(pybind11 2.4.3 REQUIRED)
pybind11_add_module(cameopy Application.cpp)
#file(GENERATE OUTPUT /tmp/message.log CONTENT $<TARGET_PROPERTY:cameo,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(cameopy PRIVATE cameo)
#target_compile_features(cameopy PUBLIC cxx_std_17)
#target_include_directories(cameopy
# PRIVATE $<TARGET_PROPERTY:cameo,INTERFACE_INCLUDE_DIRECTORIES>
# )
#target_include_directories(${MODULE_NAME} ${cameo_INCLUDE_DIR})
set_target_properties(cameopy PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
)
#####------------------------------------------- copied from CMakeLists.txt of openPMD-api
if(WIN32)
set(CMAKE_INSTALL_PYTHONDIR_DEFAULT
"${CMAKE_INSTALL_LIBDIR}/site-packages"
)
else()
set(CMAKE_INSTALL_PYTHONDIR_DEFAULT
"${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages"
)
endif()
set(CMAKE_INSTALL_PYTHONDIR "${CMAKE_INSTALL_PYTHONDIR_DEFAULT}"
CACHE STRING "Location for installed python package"
)
#set(CMAKE_PYTHON_OUTPUT_DIRECTORY
# "${openPMD_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}"
# CACHE PATH "Build directory for python modules"
# )
# set_target_properties(raytracing.py PROPERTIES
# # ARCHIVE_OUTPUT_NAME openpmd_api_cxx
# # LIBRARY_OUTPUT_NAME openpmd_api_cxx
# ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# LIBRARY_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api_api
# COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# )
# add_custom_command(TARGET raytracing.py POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# ${openPMD_SOURCE_DIR}/python/src/raytracing_api
# ${CMAKE_PYTHON_OUTPUT_DIRECTORY}/raytracing_api
# )
##### End of ------------------------------------ copied from CMakeLists.txt of openPMD-api
#---------------
# Library version
write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY SameMajorVersion
VERSION ${PROJECT_VERSION}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
#------------------------------------------------------------
# Install
#------------------------------------------------------------
#------------------------------------------------------------
# Install
#------------------------------------------------------------
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py
DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/${PROJECT_NAME}
)
install(TARGETS cameopy
EXPORT cameopyexport
DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/${PROJECT_NAME}
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment