diff --git a/CMake/FindNumpy.cmake b/CMake/FindNumpy.cmake index 4170adb613..8e798cc8f8 100644 --- a/CMake/FindNumpy.cmake +++ b/CMake/FindNumpy.cmake @@ -1,29 +1,35 @@ # Variables set by this script # NUMPY_FOUND # NUMPY_INCLUDE_DIR find_package(PackageHandleStandardArgs) # numpy dir defined, own numpy deployed in python runtime if(DEFINED Numpy_DIR AND EXISTS ${Numpy_DIR}) if(EXISTS ${Numpy_DIR}/core/include) set(NUMPY_INCLUDE_DIR ${Numpy_DIR}/core/include) endif() else() #numpy dir not defined + + set(_python ${PYTHON_EXECUTABLE}) + if(UNIX) + STRING(REPLACE " " "\ " _python ${PYTHON_EXECUTABLE}) + endif() + execute_process ( - COMMAND ${PYTHON_EXECUTABLE} -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]" + COMMAND ${_python} -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]" OUTPUT_VARIABLE output OUTPUT_STRIP_TRAILING_WHITESPACE ) if(DEFINED output AND EXISTS ${output} ) set (NUMPY_INCLUDE_DIR ${output}) endif() endif() FIND_PACKAGE_HANDLE_STANDARD_ARGS(Numpy DEFAULT_MSG NUMPY_INCLUDE_DIR) MARK_AS_ADVANCED ( NUMPY_INCLUDE_DIR ) diff --git a/CMake/mitkFunctionExternalPythonBuildStep.cmake b/CMake/mitkFunctionExternalPythonBuildStep.cmake index 0a6f55570d..ad1e3b219f 100644 --- a/CMake/mitkFunctionExternalPythonBuildStep.cmake +++ b/CMake/mitkFunctionExternalPythonBuildStep.cmake @@ -1,39 +1,49 @@ #! CMake function that runs a python build step from a setup.py script, #! e.g. python setup.py build. This is used to build external python #! libraries like numpy. The function takes the necessary build steps, #! python executable etc. as arguments. The specific build command executed #! by the runtime is passed as ARGN. #! #! params: #! proj - The name of the project #! step - Buildstep used to label the generated outputs, e.g. configure;build;install #! _python_executable - The python executable #! _bin_dir - The current binary from where commands are executed relative to it #! ARGN - Python command that will be run in the _bin_dir/proj-src folder #! e.g. setup.py build --someflags #! function(mitkFunctionExternalPythonBuildStep proj step _python_executable _bin_dir) # the specific python build command run by this step set(_command ${ARGN}) - message("Running ${proj} ${step}:${PYTHON_EXECUTABLE} ${_command}") + message("Running ${proj} ${step}:${_python_executable} ${_command}") + + set(_workdir ${_bin_dir}/${proj}-src) + set(_prefixdir ${_bin_dir}/${proj}-cmake) + set(_python ${_python_executable}) + # escape spaces + if(UNIX) + STRING(REPLACE " " "\ " _workdir ${_workdir}) + STRING(REPLACE " " "\ " _prefixdir ${_prefixdir}) + STRING(REPLACE " " "\ " _python ${_python}) + endif() execute_process( - COMMAND ${_python_executable} ${_command} - WORKING_DIRECTORY ${_bin_dir}/${proj}-src + COMMAND ${_python} ${_command} + WORKING_DIRECTORY ${_workdir} RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE error ) - set(output_file "${_bin_dir}/${proj}-cmake/${proj}_${step}_step_output.txt") + set(output_file "${_prefixdir}/${proj}_${step}_step_output.txt") file(WRITE ${output_file} ${output}) - set(error_file "${_bin_dir}/${proj}-cmake/${proj}_${step}_step_error.txt") + set(error_file "${_prefixdir}/${proj}_${step}_step_error.txt") file(WRITE ${error_file} ${error}) if(NOT ${result} EQUAL 0) message(FATAL_ERROR "Error in: ${proj}: ${error}") endif() endfunction() diff --git a/CMakeExternals/Numpy.cmake b/CMakeExternals/Numpy.cmake index 9ebcedd385..171fc41833 100644 --- a/CMakeExternals/Numpy.cmake +++ b/CMakeExternals/Numpy.cmake @@ -1,91 +1,98 @@ #----------------------------------------------------------------------------- # Numpy #----------------------------------------------------------------------------- if( MITK_USE_Python AND NOT MITK_USE_SYSTEM_PYTHON ) # Sanity checks if(DEFINED Numpy_DIR AND NOT EXISTS ${Numpy_DIR}) message(FATAL_ERROR "Numpy_DIR variable is defined but corresponds to non-existing directory") endif() if( NOT DEFINED Numpy_DIR ) set(proj Numpy) set(${proj}_DEPENDENCIES Python) set(Numpy_DEPENDS ${proj}) # setup build environment and disable fortran, blas and lapack set(_numpy_env " set(ENV{F77} \"\") set(ENV{F90} \"\") set(ENV{FFLAGS} \"\") set(ENV{ATLAS} \"None\") set(ENV{BLAS} \"None\") set(ENV{LAPACK} \"None\") set(ENV{MKL} \"None\") set(ENV{VS_UNICODE_OUTPUT} \"\") set(ENV{CC} \"${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}\") set(ENV{CFLAGS} \"${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}\") set(ENV{CXX} \"${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}\") set(ENV{CXXFLAGS} \"${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}\") set(ENV{LDFLAGS} \"${CMAKE_LINKER_FLAGS} ${CMAKE_LINKER_FLAGS_RELEASE}\") ") set(_numpy_build_step ${MITK_SOURCE_DIR}/CMake/mitkFunctionExternalPythonBuildStep.cmake) set(_configure_step ${CMAKE_BINARY_DIR}/${proj}-cmake/${proj}_configure_step.cmake) file(WRITE ${_configure_step} "${_numpy_env} include(\"${_numpy_build_step}\") file(WRITE \"${CMAKE_BINARY_DIR}/${proj}-src/site.cfg\" \"\") - mitkFunctionExternalPythonBuildStep(${proj} configure ${PYTHON_EXECUTABLE} \"${CMAKE_BINARY_DIR}\" setup.py config) + mitkFunctionExternalPythonBuildStep(${proj} configure \"${PYTHON_EXECUTABLE}\" \"${CMAKE_BINARY_DIR}\" setup.py config) ") # build step set(_build_step ${CMAKE_BINARY_DIR}/${proj}-cmake/${proj}_build_step.cmake) file(WRITE ${_build_step} "${_numpy_env} include(\"${_numpy_build_step}\") - mitkFunctionExternalPythonBuildStep(${proj} build ${PYTHON_EXECUTABLE} \"${CMAKE_BINARY_DIR}\" setup.py build --fcompiler=none) + mitkFunctionExternalPythonBuildStep(${proj} build \"${PYTHON_EXECUTABLE}\" \"${CMAKE_BINARY_DIR}\" setup.py build --fcompiler=none) ") # install step - set(_install_dir ${Python_DIR}) + set(_install_dir "${Python_DIR}") if(WIN32) STRING(REPLACE "/" "\\\\" _install_dir ${Python_DIR}) else() # escape scpaces on unix STRING(REPLACE " " "\ " _install_dir ${Python_DIR}) endif() set(_install_step ${CMAKE_BINARY_DIR}/${proj}-cmake/${proj}_install_step.cmake) file(WRITE ${_install_step} "${_numpy_env} include(\"${_numpy_build_step}\") - mitkFunctionExternalPythonBuildStep(${proj} install ${PYTHON_EXECUTABLE} \"${CMAKE_BINARY_DIR}\" setup.py install --prefix=${_install_dir}) + mitkFunctionExternalPythonBuildStep(${proj} install \"${PYTHON_EXECUTABLE}\" \"${CMAKE_BINARY_DIR}\" setup.py install --prefix=\"${_install_dir}\") ") set(Numpy_URL ${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/numpy-1.4.1.tar.gz) set(Numpy_MD5 "5c7b5349dc3161763f7f366ceb96516b") + # escape spaces + if(UNIX) + STRING(REPLACE " " "\ " _configure_step ${_configure_step}) + STRING(REPLACE " " "\ " _build_step ${_build_step}) + STRING(REPLACE " " "\ " _install_step ${_install_step}) + endif() + ExternalProject_Add(${proj} URL ${Numpy_URL} URL_MD5 ${Numpy_MD5} SOURCE_DIR ${proj}-src PREFIX ${proj}-cmake BUILD_IN_SOURCE 1 CONFIGURE_COMMAND ${CMAKE_COMMAND} -P ${_configure_step} BUILD_COMMAND ${CMAKE_COMMAND} -P ${_build_step} INSTALL_COMMAND ${CMAKE_COMMAND} -P ${_install_step} DEPENDS ${${proj}_DEPENDENCIES} ) set(Numpy_DIR ${MITK_PYTHON_SITE_DIR}/numpy) else() mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") endif() endif()