Commit a86a01ed authored by Mozul Rémy's avatar Mozul Rémy

cmake compilation

parent a0bdbee8
cmake_minimum_required(VERSION 2.8.0)
project(Forthon Fortran C)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR})
find_package(PythonLibs REQUIRED)
find_package(Numpy REQUIRED)
find_program(cython cython)
add_library(f_dtype mod_dtype.f90)
add_custom_target(dtypec ALL ${cython} ${CMAKE_CURRENT_SOURCE_DIR}/dtype.pyx -o ${CMAKE_CURRENT_BINARY_DIR}/dtype.c
DEPENDS dtype dtype.h dtype.pxd
)
include_directories(${PYTHON_INCLUDE_DIR}
${NUMPY_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
add_library(dtype SHARED dtype.c)
target_link_libraries(dtype f_dtype ${PYTHON_LIBRARIES})
set_target_properties(dtype PROPERTIES PREFIX "")
set_target_properties(dtype PROPERTIES SUFFIX ".so")
set_source_files_properties(dtype.c PROPERTIES GENERATED TRUE )
# - Find numpy
# Find the native numpy includes
# This module defines
# NUMPY_INCLUDE_DIR, where to find numpy/arrayobject.h, etc.
# NUMPY_FOUND, If false, do not try to use numpy headers.
if( NOT PYTHONINTERP_FOUND )
find_package(PythonInterp REQUIRED)
endif( NOT PYTHONINTERP_FOUND )
if (NUMPY_INCLUDE_DIR)
# in cache already
set (NUMPY_FIND_QUIETLY TRUE)
endif (NUMPY_INCLUDE_DIR)
if(${PYTHON_VERSION_MAJOR} LESS 3)
EXEC_PROGRAM (${PYTHON_EXECUTABLE}
ARGS "-c \"import numpy; print numpy.get_include()\""
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
RETURN_VALUE NUMPY_NOT_FOUND)
else(${PYTHON_VERSION_MAJOR} LESS 3)
EXEC_PROGRAM (${PYTHON_EXECUTABLE}
ARGS "-c \"import numpy; print(numpy.get_include())\""
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
RETURN_VALUE NUMPY_NOT_FOUND)
endif(${PYTHON_VERSION_MAJOR} LESS 3)
if (NUMPY_INCLUDE_DIR)
set (NUMPY_FOUND TRUE)
set (NUMPY_INCLUDE_DIR ${NUMPY_INCLUDE_DIR} CACHE STRING "Numpy include path")
else (NUMPY_INCLUDE_DIR)
set(NUMPY_FOUND FALSE)
endif (NUMPY_INCLUDE_DIR)
if (NUMPY_FOUND)
if (NOT NUMPY_FIND_QUIETLY)
message (STATUS "Numpy headers found")
endif (NOT NUMPY_FIND_QUIETLY)
else (NUMPY_FOUND)
if (NUMPY_FIND_REQUIRED)
message (FATAL_ERROR "Numpy headers missing")
endif (NUMPY_FIND_REQUIRED)
endif (NUMPY_FOUND)
MARK_AS_ADVANCED (NUMPY_INCLUDE_DIR)
# checking numpy.i file to include...
if(${PYTHON_VERSION_MAJOR} LESS 3)
exec_program( ${PYTHON_EXECUTABLE}
ARGS "-c \"import numpy; print numpy.__version__\""
OUTPUT_VARIABLE NUMPY_VERSION
)
else(${PYTHON_VERSION_MAJOR} LESS 3)
exec_program( ${PYTHON_EXECUTABLE}
ARGS "-c \"import numpy; print(numpy.__version__)\""
OUTPUT_VARIABLE NUMPY_VERSION
)
endif(${PYTHON_VERSION_MAJOR} LESS 3)
string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2\\3"
NUMPY_VERSION ${NUMPY_VERSION}
)
if( NUMPY_VERSION GREATER 17)
set(NUMPY_DOT_I ${CMAKE_SOURCE_DIR}/tools/swig/numpy-1.8.i)
elseif( NUMPY_VERSION EQUAL 17)
set(NUMPY_DOT_I ${CMAKE_SOURCE_DIR}/tools/swig/numpy-1.7.i)
else( )
set(NUMPY_DOT_I ${CMAKE_SOURCE_DIR}/tools/swig/numpy-1.6.i)
endif( )
all: dtype.so
libdtype.so: mod_dtype.f90
gfortran -shared -o $@ $<
dtype.so: dtype.pyx libdtype.so
python setup.py build_ext -i
clean:
@rm -f *.so *.c *.mod
import os
import numpy
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(name='sprint',
ext_modules=[Extension('dtype',['dtype.pyx'],
libraries=['dtype'],
library_dirs=[os.getcwd()],
include_dirs=[numpy.get_include()])],
cmdclass={'build_ext':build_ext}
)
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