Commit a5c21f99 authored by Remi Perenon's avatar Remi Perenon
Browse files

Setting up cmake for Python API

parent ba9d629f
......@@ -10,6 +10,7 @@ option(USE_HDF "Build crysfml and wcrysfml library" OFF)
option(GUI "Build crysfml and wcrysfml library" OFF)
option(ARCH32 "32 or 64 bit architecture" ON)
option(CRYSFML08 "Build CrysFML08" OFF)
option(PYTHON_API "Build Python API" OFF)
if(DEFINED CMAKE_Fortran_COMPILER)
set(CMAKE_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING "The Fortran compiler. One of 'ifort', 'g95' or 'gfortran'.")
......@@ -46,6 +47,14 @@ endif()
set (CRYSFML_PREFIX ${CMAKE_INSTALL_PREFIX}/${CRYSFML_PREFIX})
message(STATUS "CrysFML installation path set to ${CRYSFML_PREFIX}")
# Include and library paths for Python.
# They must be set by the user.
if(DEFINED PYTHON_LIBRARY_PATH)
set(PYTHON_LIBRARY_PATH ${PYTHON_LIBRARY_PATH} CACHE PATH "Python library path")
else()
set(PYTHON_LIBRARY_PATH "" CACHE PATH "Python library path")
endif()
# Include and library paths for HDF5.
# They must be set by the user.
if(DEFINED HDF5_INCLUDE_PATH)
......@@ -101,3 +110,8 @@ else()
# The subdirectories of the project.
add_subdirectory(Src08)
endif()
if (PYTHON_API)
set(PYTHON_API_PREFIX ${CMAKE_INSTALL_PREFIX}/Python_API)
add_subdirectory(Python_API/Src)
endif()
\ No newline at end of file
#################################
# Commad line arguments section
#################################
cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
#################################
# Project section
#################################
# The project is declared. It is a Fortran project.
project(Python_API Fortran)
set(LIBRARY_NAME powder_generation)
add_library(${LIBRARY_NAME} SHARED Extensions/powder_generation.f90 Extensions/forpy_mod.f90)
# Forpy must be preprocessed
set_source_files_properties(forpy_mod.f90 PROPERTIES COMPILE_FLAG "-cpp")
#################################
# Dependencies section
#################################
# Add a dependency to crysfml_common to keep sure that the crysfml_common library will be built first.
add_dependencies(${LIBRARY_NAME} crysfml_common)
#find_package(Python3 REQUIRED)
#include_directories(${Python3_INCLUDE_DIRS})
if(NOT PYTHON_LIBRARY_PATH)
#For a strange reason, find_package must be launched twice !
find_package(Python3 COMPONENTS Interpreter Development)
find_package(Python3 COMPONENTS Interpreter Development)
set(PYTHON_LIBRARY_PATH ${Python3_LIBRARIES})
endif()
if (UNIX)
add_library(Python3_LIB SHARED IMPORTED)
set_property(TARGET Python3_LIB PROPERTY IMPORTED_LOCATION ${PYTHON_LIBRARY_PATH})
elseif(WIN32)
add_library(Python3_LIB STATIC IMPORTED)
set_property(TARGET Python3_LIB PROPERTY IMPORTED_LOCATION ${PYTHON_LIBRARY_PATH})
endif()
# Set include and linking
include_directories(${CRYSFML_COMMON_MODULE_DIRECTORY})
target_link_libraries(${LIBRARY_NAME} crysfml_common)
target_link_libraries(${LIBRARY_NAME} Python3_LIB)
#################################
# Install section
#################################
set_target_properties(${LIBRARY_NAME} PROPERTIES PREFIX "" OUTPUT_NAME "powder_generation")
if(APPLE)
set_target_properties(${LIBRARY_NAME} PROPERTIES SUFFIX ".so")
elseif(WIN32)
set_target_properties(${LIBRARY_NAME} PROPERTIES SUFFIX ".pyd")
endif()
# The rules for installing the library.
install(DIRECTORY "" DESTINATION ${PYTHON_API_PREFIX}/CFML_api FILES_MATCHING PATTERN "*.py" PATTERN "Extensions" EXCLUDE)
if(WIN32)
install(TARGETS ${LIBRARY_NAME} RUNTIME DESTINATION ${PYTHON_API_PREFIX}/CFML_api)
else()
install(TARGETS ${LIBRARY_NAME} LIBRARY DESTINATION ${PYTHON_API_PREFIX}/CFML_api)
endif()
# Installing example files
install(DIRECTORY "../Examples" DESTINATION ${PYTHON_API_PREFIX} FILES_MATCHING PATTERN "*.py")
install(DIRECTORY "../Examples/Data" DESTINATION ${PYTHON_API_PREFIX}/Examples FILES_MATCHING PATTERN "*.cfl" PATTERN "*.cif")
\ No newline at end of file
......@@ -103,7 +103,7 @@ set(LIBRARY_NAME crysfml_common)
add_library(${LIBRARY_NAME} STATIC ${CRYSFML_COMMON_SOURCES})
# The directory where the CrySFML modules files will be stored.
set(CRYSFML_COMMON_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/crysfml_common_modules)
set(CRYSFML_COMMON_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/crysfml_common_modules CACHE INTERNAL "")
# Sets the path where to place the mod files for the crysfml_common library.
set_target_properties(${LIBRARY_NAME} PROPERTIES Fortran_MODULE_DIRECTORY ${CRYSFML_COMMON_MODULE_DIRECTORY})
......@@ -25,12 +25,12 @@ macro(set_compiler_flags)
endif()
elseif(APPLE)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(CMAKE_Fortran_FLAGS_DEBUG "-g -warn -cpp -qopt-report=0")
set(CMAKE_Fortran_FLAGS_DEBUG "-g -warn -cpp -qopt-report=0 -fPIC")
set(OPT_FLAGS "-g")
set(OPT_FLAGS1 "-g")
set(OPT_FLAGS0 "-O0")
elseif(CMAKE_BUILD_TYPE STREQUAL Release)
set(CMAKE_Fortran_FLAGS_RELEASE "-warn -cpp -qopt-report=0")
set(CMAKE_Fortran_FLAGS_RELEASE "-warn -cpp -qopt-report=0 -fPIC")
set(OPT_FLAGS0 "-O0")
set(OPT_FLAGS "-O2")
set(OPT_FLAGS1 "-O0")
......@@ -123,7 +123,7 @@ macro(set_compiler_flags)
set(OPT_FLAGS1 "-g")
set(OPT_FLAGS2 "-g")
set(OPT_FLAGS0 "-O0")
set(CMAKE_Fortran_FLAGS_DEBUG "-cpp -ffree-line-length-none")
set(CMAKE_Fortran_FLAGS_DEBUG "-cpp -ffree-line-length-none -fPIC")
elseif(CMAKE_BUILD_TYPE STREQUAL Release)
set(CMAKE_Fortran_FLAGS_RELEASE "-cpp -ffree-line-length-none -fPIC")
set(OPT_FLAGS0 "-O0")
......
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