Added python

This commit is contained in:
Guilhem Lavaux 2014-05-25 10:43:06 +02:00
parent 950cfb3eb1
commit b584ff54a7
5 changed files with 66 additions and 3 deletions

View File

@ -7,6 +7,11 @@ include(GetGitRevisionDescription)
include(ExternalProject) include(ExternalProject)
include(FindOpenMP) include(FindOpenMP)
include(FindPythonLibs)
set(NumPy_FIND_REQUIRED TRUE)
include(${CMAKE_SOURCE_DIR}/FindNumPy.cmake)
get_git_head_revision(HEAD GIT_VER) get_git_head_revision(HEAD GIT_VER)
option(BUILD_SHARED_LIBS "Build shared libraries." OFF) option(BUILD_SHARED_LIBS "Build shared libraries." OFF)
@ -14,6 +19,12 @@ option(BUILD_STATIC_LIBS "Build static libraries." ON)
option(ENABLE_OPENMP "Enable OpenMP support." OFF) option(ENABLE_OPENMP "Enable OpenMP support." OFF)
option(ENABLE_SHARP "Enable SPHT support." ON) option(ENABLE_SHARP "Enable SPHT support." ON)
IF(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)
SET(CosmoTool_local CosmoTool_static)
ELSE(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)
SET(CosmoTool_local CosmoTool)
ENDIF(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)
find_path(NETCDF_INCLUDE_PATH NAMES netcdf.h) find_path(NETCDF_INCLUDE_PATH NAMES netcdf.h)
find_path(NETCDFCPP_INCLUDE_PATH NAMES netcdfcpp.h netcdf) find_path(NETCDFCPP_INCLUDE_PATH NAMES netcdfcpp.h netcdf)
find_path(GSL_INCLUDE_PATH NAMES gsl/gsl_blas.h) find_path(GSL_INCLUDE_PATH NAMES gsl/gsl_blas.h)
@ -31,6 +42,8 @@ find_library(NETCDF_LIBRARY netcdf)
find_library(GSL_LIBRARY gsl) find_library(GSL_LIBRARY gsl)
find_library(GSLCBLAS_LIBRARY gslcblas) find_library(GSLCBLAS_LIBRARY gslcblas)
find_program(CYTHON cython)
find_package(Boost 1.53) find_package(Boost 1.53)
if (ENABLE_SHARP) if (ENABLE_SHARP)
@ -108,5 +121,6 @@ SET(CPACK_SOURCE_IGNORE_FILES
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(sample) add_subdirectory(sample)
add_subdirectory(python)
include(CPack) include(CPack)

49
python/CMakeLists.txt Normal file
View File

@ -0,0 +1,49 @@
set(CMAKE_SHARED_MODULE_PREFIX)
include_directories(${NUMPY_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src)
IF(CYTHON)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_cosmotool.cpp
COMMAND ${CYTHON} --cplus -o ${CMAKE_CURRENT_BINARY_DIR}/_cosmotool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/_cosmotool.pyx
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_cosmotool.pyx)
ENDIF(CYTHON)
add_library(_cosmotool MODULE ${CMAKE_CURRENT_BINARY_DIR}/_cosmotool.cpp)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Bsymbolic-functions")
target_link_libraries(_cosmotool ${CosmoTool_local} ${PYTHON_LIBRARIES} ${GSL_LIBRARIES})
# Discover where to put packages
if (NOT PYTHON_SITE_PACKAGES)
execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" OUTPUT_VARIABLE internal_PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(SYSTEM_PYTHON_SITE_PACKAGES ${internal_PYTHON_SITE_PACKAGES} CACHE PATH "Path to the target system-wide site-package where to install python modules")
execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "from site import USER_SITE; print USER_SITE" OUTPUT_VARIABLE internal_PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(USER_PYTHON_SITE_PACKAGES ${internal_PYTHON_SITE_PACKAGES} CACHE PATH "Path to the target user site-package where to install python modules")
mark_as_advanced(USER_PYTHON_SITE_PACKAGES SYSTEM_PYTHON_SITE_PACKAGES)
endif (NOT PYTHON_SITE_PACKAGES)
OPTION(INSTALL_PYTHON_LOCAL OFF)
IF (NOT INSTALL_PYTHON_LOCAL)
SET(PYTHON_SITE_PACKAGES ${SYSTEM_PYTHON_SITE_PACKAGES})
ELSE (NOT INSTALL_PYTHON_LOCAL)
SET(PYTHON_SITE_PACKAGES ${USER_PYTHON_SITE_PACKAGES})
ENDIF(NOT INSTALL_PYTHON_LOCAL)
if (WIN32 AND NOT CYGWIN)
SET_TARGET_PROPERTIES(_cosmotool PROPERTIES SUFFIX ".pyd")
endif (WIN32 AND NOT CYGWIN)
INSTALL(TARGETS _cosmotool
LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}/flints
)
INSTALL(DIRECTORY cosmotool DESTINATION ${PYTHON_SITE_PACKAGES}
FILES_MATCHING PATTERN "*.py")

1
python/_cosmotool.pyx Normal file
View File

@ -0,0 +1 @@
import numpy as np

View File

@ -1,4 +1,4 @@
SET(tolink ${GSL_LIBRARIES} CosmoTool ${CosmoTool_LIBS}) SET(tolink ${GSL_LIBRARIES} ${CosmoTool_local} ${CosmoTool_LIBS})
include_directories(${CMAKE_SOURCE_DIR}/src) include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${FFTW3_INCLUDE_DIRS} include_directories(${FFTW3_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS} ${NETCDF_INCLUDE_PATH} ${GSL_INCLUDE_PATH}) ${EIGEN3_INCLUDE_DIRS} ${NETCDF_INCLUDE_PATH} ${GSL_INCLUDE_PATH})
@ -32,7 +32,7 @@ add_executable(testPool testPool.cpp)
target_link_libraries(testPool ${tolink}) target_link_libraries(testPool ${tolink})
if (HDF5_FOUND) if (HDF5_FOUND)
add_executable(testReadFlash testReadFlash.cpp) add_executable(testReadFlash testReadFlash.cpp)
target_link_libraries(testReadFlash ${tolink}) target_link_libraries(testReadFlash ${tolink})
add_executable(testHDF5 testHDF5.cpp) add_executable(testHDF5 testHDF5.cpp)

View File

@ -69,7 +69,6 @@ set(CosmoTool_LIBS ${CosmoTool_LIBS} PARENT_SCOPE)
if (BUILD_SHARED_LIBS) if (BUILD_SHARED_LIBS)
add_library(CosmoTool SHARED ${CosmoTool_SRCS}) add_library(CosmoTool SHARED ${CosmoTool_SRCS})
target_link_libraries(CosmoTool ${CosmoTool_LIBS}) target_link_libraries(CosmoTool ${CosmoTool_LIBS})
if (BUILD_STATIC_LIBS) if (BUILD_STATIC_LIBS)
add_library(CosmoTool_static STATIC ${CosmoTool_SRCS}) add_library(CosmoTool_static STATIC ${CosmoTool_SRCS})
endif(BUILD_STATIC_LIBS) endif(BUILD_STATIC_LIBS)