Skip to content
Snippets Groups Projects
Commit b10fb3a4 authored by Franck Pérignon's avatar Franck Pérignon
Browse files

CMake and distutils

parent 58ec1a27
No related branches found
No related tags found
No related merge requests found
#======================================================= #===============================================================================
# cmake utility to compile,link and install : # cmake utility to compile and install parmepy python modules and libraries
# - parmes library (libparmes...) #
# - parmesscales library particular solver from scales, (libparmesscales...) # It includes :
# - high level python interface to parmes routines
# - parmes fortran library (libparmes...)
# - parmesscales (fortran library) particular solver from scales, (libparmesscales...)
# #
# parmes may (optionally) depends on : # parmes depends (optionally) on :
# - parmesscales (USE_SCALES=ON, default) # - parmesscales (USE_SCALES=ON, default)
# - ppm-core (USE_PPM=ON, default=OFF) # - ppm-core (USE_PPM=ON, default=OFF)
# - ppm-numerics (USE_PPMNumerics, default=OFF) # - ppm-numerics (USE_PPMNumerics, default=OFF)
# #
# F. Pérignon, 17 fev 2011 # LJK-CNRS, F. Pérignon, june 2012
# #
#======================================================= #===============================================================================
# ============= Global cmake Settings ============= # ============= Global cmake Settings =============
# Set minimum version for cmake # Set minimum version for cmake
...@@ -22,52 +25,25 @@ include(OutOfSourceBuild) ...@@ -22,52 +25,25 @@ include(OutOfSourceBuild)
# Some usefull macros # Some usefull macros
include(MyTools) include(MyTools)
# ============= Specific settings for PPMCore =============
# In this file (PPMCoreSettings.cmake) we set all variables
# required to compile and install PPMCore such as the name of
# the library to be created, the place where we can find the sources,
# the version number of the current package ...
# User defined options # User defined options
option(VERBOSE_MODE "enable verbose mode for cmake exec. Default = on" ON) option(VERBOSE_MODE "enable verbose mode for cmake exec. Default = on" ON)
option(DOUBLEPREC "set precision for real numbers to double precision when this mode is enable. Default = on." ON)
option(USE_MPI "compile and link parmes with mpi when this mode is enable. Default = on." ON) option(USE_MPI "compile and link parmes with mpi when this mode is enable. Default = on." ON)
option(WITH_SCALES "compile/create parmesscales lib and link it with Parmes. Default = on." ON) option(WITH_SCALES "compile/create parmesscales lib and link it with Parmes. Default = on." ON)
option(WITH_PPM "link Parmes with PPM library (core component). Default = off." OFF) option(WITH_PPM "link Parmes with PPM library (core component). Default = off." OFF)
option(WITH_PPMNumerics "link Parmes with PPM-numerics. Default = off" OFF) option(WITH_PPMNumerics "link Parmes with PPM-numerics. Default = off" OFF)
option(DOUBLEPREC "set precision for real numbers to double precision when this mode is enable. Default = on." ON)
option(WITH_TESTS "Enable testing. Default = off" OFF) option(WITH_TESTS "Enable testing. Default = off" OFF)
option(BUILD_SHARED_LIBS "Enable dynamic library build, default = ON" ON) option(BUILD_SHARED_LIBS "Enable dynamic library build, default = ON" ON)
# cmake project name # cmake project name
set(PROJECT_NAME parmes) set(PROJECT_NAME parmespy)
# --- Name for the package --- # --- Name for the package ---
# This name will be used to install Parmes (library, headers, ...) and when another lib or soft will need to search for Parmes. # This name will be used as the Python Package name
set(PACKAGE_NAME "Parmes") set(PYPACKAGE_NAME "parmespy")
# --- Set a version number for the package --- # --- Set a version number for the package ---
set(${PACKAGE_NAME}_version 1.0.0) set(${PYPACKAGE_NAME}_version 1.0.0)
# --- The name (without extension) of the lib to be created --- # --- The name (without extension) of the lib to be created ---
set(PROJECT_LIBRARY_NAME ${PROJECT_NAME}) set(PROJECT_LIBRARY_NAME ${PROJECT_NAME})
# --- The name of the exe to be created (test purpose)
# This exe will be linked with libPROJECT_LIBRARY_NAME
set(EXE_NAME ${PROJECT_NAME}Run)
# The list of all dirs containing sources to be compiled for the Parmes lib
# Any file in those dirs will be used to create libparmes
set(${PROJECT_LIBRARY_NAME}_SRCDIRS
src
# src/poisson
#src/interfaces/Fortran2Cpp
# src/interfaces/ppm
)
# A main file to create an executable (test purpose)
# Any files in these dirs will be used to create Parmes exec (linked with libparmes)
set(${EXE_NAME}_SRCDIRS src/main)
# Matching expr for files to be compiled.
set(EXTS *.f90 *.f95)
# Matching expr for headers (install purpose)
set(EXTS_HDRS *.hpp *.h)
# Note FP : we can also use cmake vars ${CMAKE_Fortran_SOURCE_FILE_EXTENSIONS} ${CMAKE_C_SOURCE_FILE_EXTENSIONS} ${CMAKE_CXX_SOURCE_FILE_EXTENSIONS}
# ============= The project ============= # ============= The project =============
# Set project name and project languages # Set project name and project languages
...@@ -75,7 +51,6 @@ set(EXTS_HDRS *.hpp *.h) ...@@ -75,7 +51,6 @@ set(EXTS_HDRS *.hpp *.h)
# - ${PROJECT_NAME}_BINARY_DIR : where you have run cmake, i.e. the place for compilation # - ${PROJECT_NAME}_BINARY_DIR : where you have run cmake, i.e. the place for compilation
# - ${PROJECT_NAME}_SOURCE_DIR : where sources (.f and .h and this CMakeLists.txt) are located # - ${PROJECT_NAME}_SOURCE_DIR : where sources (.f and .h and this CMakeLists.txt) are located
# Note that because of OutOfSourceBuild, binary_dir and source_dir must be different. # Note that because of OutOfSourceBuild, binary_dir and source_dir must be different.
project(${PROJECT_NAME} Fortran) project(${PROJECT_NAME} Fortran)
# ============= Tests ============= # ============= Tests =============
...@@ -87,174 +62,30 @@ endif(WITH_TESTS) ...@@ -87,174 +62,30 @@ endif(WITH_TESTS)
# We search for libraries Parmes depends on and # We search for libraries Parmes depends on and
# set the compile/link conf (-I and -L opt) # set the compile/link conf (-I and -L opt)
# --- Boost --- set(PARMES_LIBRARY_NAME parmes)
#set(Boost_ADDITIONAL_VERSIONS "1.49" "1.49.0") set(PACKAGE_NAME Parmes)
#set(Boost_NO_SYSTEM_PATHS ON) add_subdirectory(src)
#find_package(Boost REQUIRED)
#include_directories(${Boost_INCLUDE_DIRS}) # ============= Generates setup.py =============
# The file setup.py will be generated from setup.py.in.
# ============= Prepare compilation ============= if(EXISTS ${CMAKE_SOURCE_DIR}/setup.py.in)
# if(NOT CONFIG_H_GLOBAL_CONFIGURED)
# Force a default build type if not provided by user message(STATUS "Generate setup.py file ...")
# CMAKE_BUILD_TYPE = empty, Debug, Release, RelWithDebInfo or MinSizeRel. # set(CONFIG_H_GLOBAL_CONFIGURED 1 CACHE BOOL "setup.py generation." )
if (NOT CMAKE_BUILD_TYPE) configure_file(setup.py.in setup.py)
set (CMAKE_BUILD_TYPE RELEASE CACHE STRING "Choose the type of build, options are: None, Debug, Release, RelWithDebInfo or MinSizeRel." FORCE) # endif()
endif (NOT CMAKE_BUILD_TYPE)
# If the project uses Fortran ...
# Set module files directory (i.e. where .mod will be created)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/Modules)
# Add compilation flags:
append_Fortran_FLAGS("-Wall")
# --- MPI ---
if(USE_MPI)
# Find MPI for C++ and fortran.
find_package(MPI REQUIRED)
# -I
include_directories(${MPI_Fortran_INCLUDE_PATH})
# Add compilation flags
set(${PROJECT_NAME}_LINK_FLAGS ${${PROJECT_NAME}_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
# -I
# Add compilation flags
append_Fortran_flags(${MPI_Fortran_COMPILE_FLAGS})
#set(${PROJECT_NAME}_LINK_FLAGS ${${PROJECT_NAME}_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
set(LIBS ${LIBS} ${MPI_Fortran_LIBRARIES} )
endif(USE_MPI)
# --- scales ---
if(WITH_SCALES)
add_subdirectory(src/scalesInterface)
endif()
# --- PPM ---
if(WITH_PPM)
add_subdirectory(src/ppmInterface)
endif()
find_package(FFTW REQUIRED)
include_directories(${FFTW_INCLUDE_DIRS})
set(LIBS ${LIBS} ${FFTW_LIBRARIES})
display(FFTW_LIBRARIES)
# ============= Generates ParmesConfig.hpp =============
# The file PROJECT_NAME_defines.hpp will be generated from config.hpp.cmake;
if(EXISTS ${CMAKE_SOURCE_DIR}/config.hpp.cmake)
if(NOT CONFIG_H_GLOBAL_CONFIGURED)
set(CONFIG_H_GLOBAL_CONFIGURED 1 CACHE BOOL "Parmes_defines.hpp generation." )
configure_file(config.hpp.cmake ${PROJECT_NAME}_defines.hpp)
endif()
include_directories(${CMAKE_BINARY_DIR})
endif()
# ============= Source and header files list =============
# We scan all files with matching extension in directories
# containing sources.
# Source and header files list:
foreach(_DIR ${${PROJECT_LIBRARY_NAME}_SRCDIRS})
set(_DIR_FILES)
foreach(_EXT ${EXTS}) # Source files
file(GLOB _DIR_FILES_EXT ${_DIR}/${_EXT})
if(_DIR_FILES_EXT)
list(APPEND ${PROJECT_LIBRARY_NAME}_SRC ${_DIR_FILES_EXT})
endif()
endforeach()
foreach(_EXT ${EXTS_HDRS}) # Headers
file(GLOB _DIR_FILES_EXT ${_DIR}/${_EXT})
if(_DIR_FILES_EXT)
list(APPEND ${PROJECT_LIBRARY_NAME}_HDRS ${_DIR_FILES_EXT})
endif()
endforeach()
endforeach()
# We add headers to source files
list(APPEND ${PROJECT_LIBRARY_NAME}_SRC ${${PROJECT_LIBRARY_NAME}_HDRS})
# The same for main dir ...
foreach(_DIR ${${EXE_NAME}_SRCDIRS})
set(_DIR_FILES)
foreach(_EXT ${EXTS})
file(GLOB _DIR_FILES_EXT ${_DIR}/${_EXT})
if(_DIR_FILES_EXT)
list(APPEND ${EXE_NAME}_SRC ${_DIR_FILES_EXT})
endif()
endforeach()
foreach(_EXT ${EXTS_HDRS})
file(GLOB _DIR_FILES_EXT ${_DIR}/${_EXT})
if(_DIR_FILES_EXT)
list(APPEND ${EXE_NAME}_HDRS ${_DIR_FILES_EXT})
endif()
endforeach()
endforeach()
list(APPEND ${EXE_NAME}_SRC ${${EXE_NAME}_HDRS})
# Add directories to those searched by compiler ...
# -I
include_directories(${${PROJECT_LIBRARY_NAME}_SRCDIRS})
include_directories(${${EXE_NAME}_HDRS})
include_directories(${CMAKE_Fortran_MODULE_DIRECTORY})
# Cmake tools to handle fortran-c interface. It will generate F2CMangle.hpp, a file
# that will contain some useful macros to deal with fortran-C name mangling.
# See cmake doc for this module.
#include(FortranCInterface)
#FortranCInterface_HEADER(${CMAKE_Fortran_MODULE_DIRECTORY}/F2CMangle.hpp
# MACRO_NAMESPACE "F2C_"
# SYMBOL_NAMESPACE "F2C_")
# ============= Creates the library =============
if(BUILD_SHARED_LIBS) # shared library
add_library(${PROJECT_LIBRARY_NAME} SHARED ${${PROJECT_LIBRARY_NAME}_SRC})
else() # static library
add_library(${PROJECT_LIBRARY_NAME} STATIC ${${PROJECT_LIBRARY_NAME}_SRC})
endif() endif()
# Libs to link with PROJECT__LIBRARY_NAME
target_link_libraries(${PROJECT_LIBRARY_NAME} ${LIBS})
# ============= Creates the executable =============
add_executable(${EXE_NAME} ${${EXE_NAME}_SRC})
add_dependencies(${EXE_NAME} ${PROJECT_LIBRARY_NAME})
# libs to link with EXE_NAME
target_link_libraries(${EXE_NAME} ${PROJECT_LIBRARY_NAME})
target_link_libraries(${EXE_NAME} ${LIBS})
# ============== Add tests ==============
if(WITH_TESTS)
message(STATUS "Enable testing ...")
begin_test(src/tests/F2003)
new_test(testAllocatedPtr userMod.f90 wrapper.f90 testAllocatedPtr.cxx)
new_test(testNullPtr userMod.f90 wrapper.f90 testNullPtr.cxx)
end_test()
begin_test(src/tests/Particles)
new_test(testCreate3D testCreate3D.f90)
new_test(testCreate2D testCreate2D.f90)
end_test()
endif(WITH_TESTS)
# ============= Prepare install =============
# The library
# The library, the headers and mod files, the cmake generated files
# will be install in CMAKE_INSTALL_PREFIX/lib include and share
include(InstallPackage)
install_package(${PACKAGE_NAME} ${PROJECT_LIBRARY_NAME} ${${PROJECT_NAME}_HDRS})
#install(TARGETS ${EXE_NAME} set(PYTHON_EXECUTABLE python)
#RUNTIME DESTINATION bin # executables
# )
ADD_CUSTOM_TARGET(python-build COMMAND python ${CMAKE_CURRENT_BINARY_DIR}/setup.py build --user config_fc --f90exec=${CMAKE_Fortran_COMPILER}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "build parmepy package")
#configure_file(${PACKAGE_NAME}Config.cmake.in ADD_CUSTOM_TARGET(python-install COMMAND python ${CMAKE_CURRENT_BINARY_DIR}/setup.py install --user config_fc --f90exec=${CMAKE_Fortran_COMPILER}
# "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}Config.cmake") WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "build/install parmepy package")
#configure_file(${PACKAGE_NAME}ConfigVersion.cmake.in
# "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}ConfigVersion.cmake" @ONLY)
#install(FILES
# "${PROJECT_BINARY_DIR}/InstallFiles/${_PACK}Config.cmake"
# "${PROJECT_BINARY_DIR}/InstallFiles/${_PACK}ConfigVersion.cmake"
# DESTINATION "${${PACKAGE_NAME}_CMAKE_DIR}" COMPONENT dev)
add_dependencies(python-build ${PARMES_LIBRARY_NAME})
add_dependencies(python-install ${PARMES_LIBRARY_NAME})
# ============= RPATH ============= # ============= RPATH =============
# Concerning rpath see for example http://www.itk.org/Wiki/CMake_RPATH_handling # Concerning rpath see for example http://www.itk.org/Wiki/CMake_RPATH_handling
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
setup.py file for @PYPACKAGE_NAME@
"""
from numpy.distutils.core import setup, Extension
import os, glob
# List of all directories for sources
#os.listdir(os.path.join('ParMePy','New_ParmePy'))
# Full package name
name = '@PYPACKAGE_NAME@'
# List of modules (directories) to be included
packages = ['ParMePy','ParMePy.domain','ParMePy.fields']
# 'examples']
# 'new_ParMePy',
# 'new_ParMePy/Domain',
# 'new_ParMePy/Operator',
# 'new_ParMePy/Problem',
# 'new_ParMePy/Utils',
# 'new_ParMePy/Variable']
# Enable this to get debug info
# DISTUTILS_DEBUG=1
fortran_src = glob.glob('@CMAKE_SOURCE_DIR@/ParMePy/parmesfftw2py/*.f90')
parmes_dir=['@CMAKE_BINARY_DIR@/Modules']
parmes_libdir=['@CMAKE_BINARY_DIR@/src']
parmeslib=['@PARMES_LIBRARY_NAME@']
#,f2py_options=['-c --f90exec=/Users/Franck/Softs/install-gnu/openmpi-1.5.3/bin/mpif90'])
#f2py_options=['skip: discretisation_init :']
# Example with include and link :
#include_mpi='/Users/Franck/Softs/install-gnu/openmpi-1.5.3/lib/'
#fortran_dir='./ParMePy/scales2py'
#legi_dir =os.path.join(fortran_dir,'srcLegi')
#legi_lib = [os.path.join(fortran_dir,'.')]
#print legi_lib
#parpyModule=Extension(name='ParMePy.scales2py',sources=fortran_src,include_dirs=[legi_dir],library_dirs=legi_lib,libraries=['parmeslegi'])
#parpyModule=Extension(name='parpy',sources=fortran_src)#,f2py_options=f2py_options)
parpyModule=Extension(name='ParMePy.fftw2py',sources=fortran_src,include_dirs=parmes_dir,library_dirs=parmes_libdir,libraries=parmeslib)
#ppm_lib_dir=[os.path.join(ppm_dir,'lib')]
#ppm_lib=['ppm_core']
#pyParMesModule=Extension(name=name,sources=f2py_sources,include_dirs=[include_mpi],library_dirs=ppm_lib_dir,libraries=ppm_lib)
setup(name=name,
version='1.0.0',
description='Particular Methods implementation in Python',
author='Jean-Matthieu Etancelin, Franck Pérignon, Christophe Picard',
author_email='parmes-devel@lists.forge.imag.fr',
url='https://forge.imag.fr/projects/parmes/',
license='GNU public license',
package_dir = {'': '@CMAKE_SOURCE_DIR@'},
ext_modules=[parpyModule],
packages=packages
#data_files=[('new_ParMePy/Utils', ['./new_ParMePy/Utils/gpu_src.cl'])]
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment