summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdoardo Pasca <edo.paskino@gmail.com>2017-10-19 17:01:55 +0100
committerEdoardo Pasca <edo.paskino@gmail.com>2017-10-20 16:55:24 +0100
commit8b427d82acfaeb4671484bc459343c5e2e412736 (patch)
treed61da32f885832f1bf8e2230541eec268c14e503
parent97f96692db91473b4bc9387994860baadab13e6a (diff)
downloadregularization-8b427d82acfaeb4671484bc459343c5e2e412736.tar.gz
regularization-8b427d82acfaeb4671484bc459343c5e2e412736.tar.bz2
regularization-8b427d82acfaeb4671484bc459343c5e2e412736.tar.xz
regularization-8b427d82acfaeb4671484bc459343c5e2e412736.zip
Initial revision of build environment made with CMake
Initial revision of build environment made with CMake First commit of CMakeLists.txt attempt to use CMake to create the build environment First commit of CMakeLists.txt attempting to locate conda python environment Added a few files for CMake Many changes for the CMake compilation. Tested CMake build Bugfixes
-rw-r--r--CMakeLists.txt30
-rw-r--r--src/CMakeLists.txt14
-rw-r--r--src/Python/CMakeLists.txt58
-rw-r--r--src/Python/FindAnacondaEnvironment.cmake166
-rw-r--r--src/Python/compile.bat.in4
-rw-r--r--src/Python/compile.sh.in6
-rw-r--r--src/Python/conda-recipe/bld.bat14
-rw-r--r--src/Python/conda-recipe/build.sh14
-rw-r--r--src/Python/conda-recipe/meta.yaml30
9 files changed, 336 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..c9e8cb7
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,30 @@
+# Copyright 2017 Edoardo Pasca
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required (VERSION 3.0)
+
+project(FISTA)
+#https://stackoverflow.com/questions/13298504/using-cmake-with-setup-py
+
+# The version number.
+set (FISTA_VERSION_MAJOR 1)
+set (FISTA_VERSION_MINOR 0)
+
+set (CIL_VERSION_MAJOR 0)
+set (CIL_VERSION_MINOR 9)
+set (CIL_VERSION_PATCH 1)
+
+set (CIL_VERSION '${CIL_VERSION_MAJOR}.${CIL_VERSION_MINOR}.${CIL_VERSION_PATCH}')
+
+add_subdirectory(src) \ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..cbe2fec
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Copyright 2017 Edoardo Pasca
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+add_subdirectory(Python) \ No newline at end of file
diff --git a/src/Python/CMakeLists.txt b/src/Python/CMakeLists.txt
new file mode 100644
index 0000000..fd377cc
--- /dev/null
+++ b/src/Python/CMakeLists.txt
@@ -0,0 +1,58 @@
+# Copyright 2017 Edoardo Pasca
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+message("CIL VERSION " ${CIL_VERSION})
+
+# variables that are set by conda
+#PREFIX=C:\Apps\Miniconda2\envs\cil\Library
+#LIBRARY_INC=C:\\Apps\\Miniconda2\\envs\\cil\\Library\\include
+
+set (NUMPY_VERSION 1.12)
+#set (PYTHON_VERSION 3.5)
+
+#https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/R9gWjl09UFs
+set (CONDA_ENVIRONMENT "cil")
+set (CONDA_ENVIRONMENT_PATH "C:\\Apps\\Miniconda2\\envs\\${CONDA_ENVIRONMENT}" CACHE PATH "env dir")
+
+message("CIL VERSION " ${CIL_VERSION})
+
+# set the Python variables for the Conda environment
+include(FindAnacondaEnvironment.cmake)
+findPythonForAnacondaEnvironment(${CONDA_ENVIRONMENT_PATH})
+message("Python found " ${PYTHON_VERSION_STRING})
+findPythonPackagesPath()
+message("PYTHON_PACKAGES_FOUND " ${PYTHON_PACKAGES_PATH})
+
+# copy the Pyhon files of the package
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ccpi/imaging/)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/__init__.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/imaging/__init__.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi/imaging)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/imaging/Regularizer.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi/imaging)
+
+
+# Copy and configure the relative conda build and recipes
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/conda-recipe)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/conda-recipe/meta.yaml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/conda-recipe)
+
+if (WIN32)
+ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/conda-recipe/bld.bat DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/conda-recipe/)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile.bat.in ${CMAKE_CURRENT_BINARY_DIR}/compile.bat)
+elseif(UNIX)
+ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/conda-recipe/build.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/conda-recipe/)
+ # assumes we will use bash
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile.sh.in ${CMAKE_CURRENT_BINARY_DIR}/compile.sh)
+endif()
+
+
diff --git a/src/Python/FindAnacondaEnvironment.cmake b/src/Python/FindAnacondaEnvironment.cmake
new file mode 100644
index 0000000..3abb5d1
--- /dev/null
+++ b/src/Python/FindAnacondaEnvironment.cmake
@@ -0,0 +1,166 @@
+# Copyright 2017 Edoardo Pasca
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# #.rst:
+# FindAnacondaEnvironment
+# --------------
+#
+# Find Python executable and library for a specific Anaconda environment
+#
+# This module finds the Python interpreter for a specific Anaconda enviroment,
+# if installed and determines where the include files and libraries are.
+# This code sets the following variables:
+#
+# ::
+# PYTHONINTERP_FOUND - if the Python interpret has been found
+# PYTHON_EXECUTABLE - the Python interpret found
+# PYTHON_LIBRARY - path to the python library
+# PYTHON_INCLUDE_PATH - path to where Python.h is found (deprecated)
+# PYTHON_INCLUDE_DIRS - path to where Python.h is found
+# PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8)
+# PYTHON_VERSION_MAJOR - major Python version
+# PYTHON_VERSION_MINOR - minor Python version
+# PYTHON_VERSION_PATCH - patch Python version
+
+
+
+function (findPythonForAnacondaEnvironment env)
+
+ file(TO_CMAKE_PATH ${env}/python.exe PYTHON_EXECUTABLE)
+
+ message("Found " ${PYTHON_EXECUTABLE})
+ ####### FROM FindPythonInterpr ########
+ # determine python version string
+ if(PYTHON_EXECUTABLE)
+ execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
+ "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))"
+ OUTPUT_VARIABLE _VERSION
+ RESULT_VARIABLE _PYTHON_VERSION_RESULT
+ ERROR_QUIET)
+ if(NOT _PYTHON_VERSION_RESULT)
+ string(REPLACE ";" "." _PYTHON_VERSION_STRING "${_VERSION}")
+ list(GET _VERSION 0 _PYTHON_VERSION_MAJOR)
+ list(GET _VERSION 1 _PYTHON_VERSION_MINOR)
+ list(GET _VERSION 2 _PYTHON_VERSION_PATCH)
+ if(PYTHON_VERSION_PATCH EQUAL 0)
+ # it's called "Python 2.7", not "2.7.0"
+ string(REGEX REPLACE "\\.0$" "" _PYTHON_VERSION_STRING "${PYTHON_VERSION_STRING}")
+ endif()
+ else()
+ # sys.version predates sys.version_info, so use that
+ execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)"
+ OUTPUT_VARIABLE _VERSION
+ RESULT_VARIABLE _PYTHON_VERSION_RESULT
+ ERROR_QUIET)
+ if(NOT _PYTHON_VERSION_RESULT)
+ string(REGEX REPLACE " .*" "" _PYTHON_VERSION_STRING "${_VERSION}")
+ string(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" _PYTHON_VERSION_MAJOR "${PYTHON_VERSION_STRING}")
+ string(REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" _PYTHON_VERSION_MINOR "${PYTHON_VERSION_STRING}")
+ if(PYTHON_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.([0-9]+)")
+ set(PYTHON_VERSION_PATCH "${CMAKE_MATCH_1}")
+ else()
+ set(PYTHON_VERSION_PATCH "0")
+ endif()
+ else()
+ # sys.version was first documented for Python 1.5, so assume
+ # this is older.
+ set(PYTHON_VERSION_STRING "1.4" PARENT_SCOPE)
+ set(PYTHON_VERSION_MAJOR "1" PARENT_SCOPE)
+ set(PYTHON_VERSION_MINOR "4" PARENT_SCOPE)
+ set(PYTHON_VERSION_PATCH "0" PARENT_SCOPE)
+ endif()
+ endif()
+ unset(_PYTHON_VERSION_RESULT)
+ unset(_VERSION)
+ endif()
+ ###############################################
+
+ set (PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} PARENT_SCOPE)
+ set (PYTHONINTERP_FOUND "ON" PARENT_SCOPE)
+ set (PYTHON_VERSION_STRING ${_PYTHON_VERSION_STRING} PARENT_SCOPE)
+ set (PYTHON_VERSION_MAJOR ${_PYTHON_VERSION_MAJOR} PARENT_SCOPE)
+ set (PYTHON_VERSION_MINOR ${_PYTHON_VERSION_MINOR} PARENT_SCOPE)
+ set (PYTHON_VERSION_PATCH ${_PYTHON_VERSION_PATCH} PARENT_SCOPE)
+ message("My version found " ${PYTHON_VERSION_STRING})
+
+endfunction()
+
+
+
+set(Python_ADDITIONAL_VERSIONS 3.5)
+
+find_package(PythonInterp)
+if (PYTHONINTERP_FOUND)
+
+ message("Found interpret " ${PYTHON_EXECUTABLE})
+ message("Python Library " ${PYTHON_LIBRARY})
+ message("Python Include Dir " ${PYTHON_INCLUDE_DIR})
+ message("Python Include Path " ${PYTHON_INCLUDE_PATH})
+
+ foreach(pv ${PYTHON_VERSION_STRING})
+ message("Found interpret " ${pv})
+ endforeach()
+endif()
+
+
+
+find_package(PythonLibs)
+if (PYTHONLIB_FOUND)
+ message("Found PythonLibs PYTHON_LIBRARIES " ${PYTHON_LIBRARIES})
+ message("Found PythonLibs PYTHON_INCLUDE_PATH " ${PYTHON_INCLUDE_PATH})
+ message("Found PythonLibs PYTHON_INCLUDE_DIRS " ${PYTHON_INCLUDE_DIRS})
+ message("Found PythonLibs PYTHONLIBS_VERSION_STRING " ${PYTHONLIBS_VERSION_STRING} )
+else()
+ message("No PythonLibs Found")
+endif()
+
+
+
+
+function(findPythonPackagesPath)
+### https://openlab.ncl.ac.uk/gitlab/john.shearer/clappertracker/raw/549885e5decd37f7b23e9c1fd39e86f207156795/src/3rdparty/opencv/cmake/OpenCVDetectPython.cmake
+###
+if(CMAKE_HOST_UNIX)
+ execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_lib()"
+ RESULT_VARIABLE PYTHON_CVPY_PROCESS
+ OUTPUT_VARIABLE PYTHON_STD_PACKAGES_PATH
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if("${PYTHON_STD_PACKAGES_PATH}" MATCHES "site-packages")
+ set(_PYTHON_PACKAGES_PATH "python${PYTHON_VERSION_MAJOR_MINOR}/site-packages")
+ else() #debian based assumed, install to the dist-packages.
+ set(_PYTHON_PACKAGES_PATH "python${PYTHON_VERSION_MAJOR_MINOR}/dist-packages")
+ endif()
+ if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${PYTHON_PACKAGES_PATH}")
+ set(_PYTHON_PACKAGES_PATH "lib${LIB_SUFFIX}/${_PYTHON_PACKAGES_PATH}")
+ else()
+ set(_PYTHON_PACKAGES_PATH "lib/${_PYTHON_PACKAGES_PATH}")
+ endif()
+ elseif(CMAKE_HOST_WIN32)
+ get_filename_component(PYTHON_PATH "${PYTHON_EXECUTABLE}" PATH)
+ file(TO_CMAKE_PATH "${PYTHON_PATH}" PYTHON_PATH)
+ if(NOT EXISTS "${PYTHON_PATH}/Lib/site-packages")
+ unset(PYTHON_PATH)
+ get_filename_component(PYTHON_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE)
+ if(NOT PYTHON_PATH)
+ get_filename_component(PYTHON_PATH "[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE)
+ endif()
+ file(TO_CMAKE_PATH "${PYTHON_PATH}" PYTHON_PATH)
+ endif()
+ set(_PYTHON_PACKAGES_PATH "${PYTHON_PATH}/Lib/site-packages")
+ endif()
+ SET(PYTHON_PACKAGES_PATH "${_PYTHON_PACKAGES_PATH}" PARENT_SCOPE)
+
+endfunction()
+
+
diff --git a/src/Python/compile.bat.in b/src/Python/compile.bat.in
new file mode 100644
index 0000000..d4ddc92
--- /dev/null
+++ b/src/Python/compile.bat.in
@@ -0,0 +1,4 @@
+set CIL_VERSION=@CIL_VERSION@
+
+activate @CONDA_ENVIRONMENT@
+conda build conda-recipe --python=@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@ --numpy=@NUMPY_VERSION@ -c ccpi \ No newline at end of file
diff --git a/src/Python/compile.sh.in b/src/Python/compile.sh.in
new file mode 100644
index 0000000..dd29973
--- /dev/null
+++ b/src/Python/compile.sh.in
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+export CIL_VERSION=@CIL_VERSION@
+module load python/anaconda
+source activate @CONDA_ENVIRONMENT@
+conda build conda-recipe --python=@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@ --numpy=@NUMPY_VERSION@ -c ccpi \ No newline at end of file
diff --git a/src/Python/conda-recipe/bld.bat b/src/Python/conda-recipe/bld.bat
new file mode 100644
index 0000000..69491de
--- /dev/null
+++ b/src/Python/conda-recipe/bld.bat
@@ -0,0 +1,14 @@
+IF NOT DEFINED CIL_VERSION (
+ECHO CIL_VERSION Not Defined.
+exit 1
+)
+
+mkdir "%SRC_DIR%\ccpi"
+xcopy /e "%RECIPE_DIR%\..\.." "%SRC_DIR%\ccpi"
+
+cd %SRC_DIR%\ccpi\Python
+
+%PYTHON% setup.py build_ext
+if errorlevel 1 exit 1
+%PYTHON% setup.py install
+if errorlevel 1 exit 1
diff --git a/src/Python/conda-recipe/build.sh b/src/Python/conda-recipe/build.sh
new file mode 100644
index 0000000..855047f
--- /dev/null
+++ b/src/Python/conda-recipe/build.sh
@@ -0,0 +1,14 @@
+
+if [ -z "$CIL_VERSION" ]; then
+ echo "Need to set CIL_VERSION"
+ exit 1
+fi
+mkdir "$SRC_DIR/ccpi"
+cp -r "$RECIPE_DIR/../.." "$SRC_DIR/ccpi"
+
+cd $SRC_DIR/ccpi/Python
+
+$PYTHON setup.py build_ext
+$PYTHON setup.py install
+
+
diff --git a/src/Python/conda-recipe/meta.yaml b/src/Python/conda-recipe/meta.yaml
new file mode 100644
index 0000000..c5b7a89
--- /dev/null
+++ b/src/Python/conda-recipe/meta.yaml
@@ -0,0 +1,30 @@
+package:
+ name: ccpi-fista
+ version: {{ environ['CIL_VERSION'] }}
+
+
+build:
+ preserve_egg_dir: False
+ script_env:
+ - CIL_VERSION
+# number: 0
+
+requirements:
+ build:
+ - python
+ - numpy
+ - setuptools
+ - boost ==1.64
+ - boost-cpp ==1.64
+ - cython
+
+ run:
+ - python
+ - numpy
+ - boost ==1.64
+
+
+about:
+ home: http://www.ccpi.ac.uk
+ license: BSD license
+ summary: 'CCPi Core Imaging Library Quantification Toolbox'