mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 13:53:40 +01:00
ab3b9b3d4d
- Given a C++ file, e.g. a class, it calls libclang to parse the C++, and retrieve from its AST the necessary info to write a xxx_desc.py file. - THIS IS WORK IN PROGRESS. There are several corner cases for which we may want (or not) the script to do better. - It is not designed to be used automatically, but to to 90 % of the boring typesetting work... - The preamble still needs manual choices - The properties, methods, functions are automatically declared in the _desc file, in the simplest possible way. - An option --properties, -p : to transform some simple methods or get_x, set_x into python properties, not methods. Cf doc. - requires clang (tested on 3.4). - the script is configured by cmake and installed in INSTALLATION_DIRECTORY/bin, with some other files. It can only be used for applications, after the lib has been installed. It is cmake configured, to include automatically the various include paths configure in the triqs installation, including the triqs install dir in order to simplify invocation. - TODO : improve, and test more in real cases.
258 lines
11 KiB
CMake
258 lines
11 KiB
CMake
# version
|
|
set(TRIQS_VERSION @TRIQS_VERSION@)
|
|
set(TRIQS_RELEASE @TRIQS_RELEASE@)
|
|
set(TRIQS_GIT_HASH @TRIQS_GIT_HASH@)
|
|
|
|
# definitions
|
|
set(TRIQS_CXX_DEFINITIONS @TRIQS_CXX_DEFINITIONS@)
|
|
|
|
# Includes
|
|
set(TRIQS_INCLUDE @CMAKE_INSTALL_PREFIX@/include)
|
|
|
|
set(TRIQS_INCLUDE_BOOST @TRIQS_INCLUDE_BOOST@)
|
|
set(TRIQS_INCLUDE_MPI @TRIQS_INCLUDE_MPI@)
|
|
set(TRIQS_INCLUDE_PYTHON @TRIQS_INCLUDE_PYTHON@)
|
|
set(TRIQS_INCLUDE_HDF5 @TRIQS_INCLUDE_HDF5@)
|
|
set(TRIQS_INCLUDE_FFTW @TRIQS_INCLUDE_FFTW@)
|
|
set(TRIQS_INCLUDE_GMP @TRIQS_INCLUDE_GMP@)
|
|
set(TRIQS_INCLUDE_GSL @GSL_INCLUDE_DIR@)
|
|
|
|
# Libraries
|
|
set(TRIQS_LIBRARY -L@CMAKE_INSTALL_PREFIX@/lib -ltriqs)
|
|
|
|
set(TRIQS_LIBRARY_BOOST @TRIQS_LIBRARY_BOOST@)
|
|
set(TRIQS_LIBRARY_MPI @TRIQS_LIBRARY_MPI@)
|
|
set(TRIQS_LIBRARY_PYTHON @TRIQS_LIBRARY_PYTHON@)
|
|
set(TRIQS_LIBRARY_HDF5 @TRIQS_LIBRARY_HDF5@)
|
|
set(TRIQS_LIBRARY_LAPACK @TRIQS_LIBRARY_LAPACK@)
|
|
set(TRIQS_LIBRARY_FFTW @TRIQS_LIBRARY_FFTW@)
|
|
set(TRIQS_LIBRARY_GMP @TRIQS_LIBRARY_GMP@)
|
|
set(TRIQS_LIBRARY_GSL @GSL_LIBRARIES@)
|
|
|
|
# Misc
|
|
set(TRIQS_WITH_PYTHON_SUPPORT @TRIQS_WITH_PYTHON_SUPPORT@)
|
|
set(TRIQS_HDF5_DIFF_EXECUTABLE @TRIQS_HDF5_DIFF_EXECUTABLE@)
|
|
set(TRIQS_PYTHON_LIB_DEST @TRIQS_PYTHON_LIB_DEST@)
|
|
|
|
# for people who want to quickly add everything TRIQS has detected...
|
|
set(TRIQS_LIBRARY_ALL ${TRIQS_LIBRARY} @TRIQS_LIBRARY_ALL@)
|
|
set(TRIQS_INCLUDE_ALL ${TRIQS_INCLUDE} @TRIQS_INCLUDE_ALL@)
|
|
|
|
# Documentation
|
|
set(TRIQS_WITH_DOCUMENTATION @Build_Documentation@)
|
|
set(TRIQS_SPHINXBUILD_EXECUTABLE @SPHINXBUILD_EXECUTABLE@)
|
|
set(TRIQS_THEMES_PATH @CMAKE_INSTALL_PREFIX@/share/triqs/themes)
|
|
set(TRIQS_MATHJAX_PATH @MATHJAX_PATH@)
|
|
|
|
# Git
|
|
set(TRIQS_GIT_EXECUTABLE @GIT_EXECUTABLE@)
|
|
macro(triqs_get_git_hash DIR PREFIX)
|
|
execute_process(COMMAND @GIT_EXECUTABLE@ rev-parse HEAD
|
|
WORKING_DIRECTORY "${DIR}"
|
|
RESULT_VARIABLE GIT_RESULT
|
|
OUTPUT_VARIABLE "${PREFIX}_GIT_HASH"
|
|
ERROR_VARIABLE GIT_ERROR
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
endmacro(triqs_get_git_hash)
|
|
|
|
# Python specific stuff
|
|
set (TRIQS_PYTHON_INTERPRETER @PYTHON_INTERPRETER@)
|
|
|
|
message(STATUS "TRIQS : Adding C++11 compilation flags -std=c++11 ")
|
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ")
|
|
#add_definitions( -std=c++0x)
|
|
|
|
# Check compiler
|
|
if (NOT CMAKE_CXX_COMPILER STREQUAL "@CMAKE_CXX_COMPILER@" )
|
|
message(FATAL_ERROR "For your own safety, you should use the same compiler as the one used to compile TRIQS !")
|
|
endif()
|
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ ")
|
|
message(STATUS "TRIQS : Adding C++11 compilation flags for Os X: -stdlib=libc++ ")
|
|
else ()
|
|
message( WARNING "${line_of_star}You are on Os X but your are not using clang. This is NOT recommended...${line_of_star}")
|
|
endif ()
|
|
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
|
|
################################################################
|
|
# This function add the target to build a python module
|
|
macro (triqs_python_extension ModuleName)
|
|
message(STATUS "Preparing extension module ${ModuleName}")
|
|
|
|
EXECUTE_PROCESS(COMMAND mkdir -p ${CMAKE_BINARY_DIR}/include/pytriqs/converters/)
|
|
|
|
SET(wrap_name ${CMAKE_CURRENT_BINARY_DIR}/${ModuleName}_wrap.cpp)
|
|
SET(converter_name ${CMAKE_BINARY_DIR}/include/pytriqs/converters/${ModuleName}.hpp)
|
|
|
|
# Adjust pythonpath so that pytriqs is visible and the wrap_generator too...
|
|
# pytriqs needed since we import modules with pure python method to extract the doc..
|
|
add_custom_command(OUTPUT ${wrap_name} ${converter_name} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${ModuleName}_desc.py
|
|
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/${ModuleName}_desc.py ${CMAKE_CURRENT_BINARY_DIR} &&
|
|
PYTHONPATH=@CMAKE_INSTALL_PREFIX@/share/triqs/wrap_generator:${CMAKE_BINARY_DIR}/ ${TRIQS_PYTHON_INTERPRETER} ${CMAKE_CURRENT_BINARY_DIR}/${ModuleName}_desc.py
|
|
@CMAKE_INSTALL_PREFIX@/share/triqs/wrap_generator/wrapper.mako.cpp
|
|
${wrap_name}
|
|
@CMAKE_INSTALL_PREFIX@/share/triqs/wrap_generator/py_converter_wrapper.mako.hpp
|
|
${converter_name}
|
|
# after this, list of paths for the header generated by the python wrapper generator
|
|
@CMAKE_INSTALL_PREFIX@/include/pytriqs/converters/
|
|
${CMAKE_BINARY_DIR}/include/pytriqs/converters/
|
|
)
|
|
|
|
#set_property (GLOBAL APPEND PROPERTY TRIQS_PY_CONVERTERS_TARGETS "python_wrap_${ModuleName}")
|
|
|
|
add_custom_target(python_wrap_${ModuleName} ALL DEPENDS ${wrap_name} ${converter_name})
|
|
add_dependencies(python_wrap_${ModuleName} py_copy ${CMAKE_CURRENT_BINARY_DIR}/${ModuleName}_desc.py )
|
|
|
|
add_library(${ModuleName} MODULE ${wrap_name})
|
|
set_target_properties(${ModuleName} PROPERTIES PREFIX "") #eliminate the lib in front of the module name
|
|
target_link_libraries(${ModuleName} ${TRIQS_LINK_LIBS} triqs)
|
|
|
|
if (${ARGN} MATCHES "")
|
|
install (FILES ${converter_name} DESTINATION @TRIQS_PYTHON_LIB_DEST@/include/pytriqs/converters)
|
|
install (TARGETS ${ModuleName} DESTINATION @TRIQS_PYTHON_LIB_DEST@/${ARGN} )
|
|
endif (${ARGN} MATCHES "")
|
|
|
|
endmacro (triqs_python_extension)
|
|
|
|
################################################################
|
|
|
|
# Also duplicate from the FindTriqsMacro.... ? Include ?
|
|
macro (triqs_add_all_subdirectories_with_cmakelist)
|
|
SET( print_decal_sub_dir "${print_decal_sub_dir} ")
|
|
FILE(GLOB ALLSUBS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} */CMakeLists.txt)
|
|
foreach ( f ${ALLSUBS})
|
|
get_filename_component(d ${f} PATH)
|
|
#MESSAGE(STATUS "${print_decal_sub_dir}## Including subdirectory : ${d}")
|
|
add_subdirectory(${d})
|
|
endforeach ( f ${ALLSUBS})
|
|
endmacro (triqs_add_all_subdirectories_with_cmakelist)
|
|
|
|
# RPATH setting
|
|
macro (triqs_set_rpath_for_target Target)
|
|
set_target_properties(${Target} PROPERTIES LINK_FLAGS -Wl,-rpath,${TRIQS_PATH}/lib)
|
|
set_target_properties(${Target} PROPERTIES INSTALL_NAME_DIR ${TRIQS_PATH}/lib)
|
|
set_target_properties(${Target} PROPERTIES INSTALL_RPATH ${TRIQS_PATH}/lib)
|
|
set_target_properties(${Target} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
set_target_properties(${Target} PROPERTIES BUILD_WITH_INSTALL_RPATH FALSE)
|
|
set_target_properties(${Target} PROPERTIES SKIP_BUILD_RPATH FALSE)
|
|
set_target_properties(${Target} PROPERTIES SKIP_INSTALL_RPATH FALSE)
|
|
endmacro()
|
|
|
|
# A macro to create a local copy of triqs with the added python
|
|
macro (triqs_prepare_local_pytriqs_merged_with_my_python python_destination)
|
|
|
|
# Create the local build_pytriqs executable
|
|
file(WRITE ${CMAKE_BINARY_DIR}/build_pytriqs
|
|
"#!/bin/bash
|
|
export PYTHONPATH=${CMAKE_BINARY_DIR}:$PYTHONPATH
|
|
${TRIQS_PYTHON_INTERPRETER} $@"
|
|
)
|
|
execute_process(COMMAND chmod 755 ${CMAKE_BINARY_DIR}/build_pytriqs)
|
|
|
|
# Get a list of all local py and pyx files
|
|
file(GLOB_RECURSE relative_local RELATIVE ${CMAKE_SOURCE_DIR}/python *.py *.pyx)
|
|
foreach(f IN LISTS relative_local)
|
|
string(REGEX REPLACE "pyx" "so" new_f ${f})
|
|
list(APPEND local_files "${python_destination}/${new_f}")
|
|
endforeach()
|
|
|
|
# Get a list of all installed python files and then
|
|
# remove the local ones from that list
|
|
file(GLOB_RECURSE remote_files RELATIVE ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST} ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST}/*)
|
|
foreach(f IN LISTS local_files)
|
|
list(REMOVE_ITEM remote_files ${f})
|
|
endforeach()
|
|
|
|
# Get the remote directory structure, remove duplicates
|
|
foreach(f IN LISTS remote_files)
|
|
get_filename_component(d ${f} PATH)
|
|
list(APPEND remote_dirs "${d}")
|
|
endforeach()
|
|
list(REMOVE_DUPLICATES remote_dirs)
|
|
list(REMOVE_ITEM remote_dirs "")
|
|
|
|
# Create locally the remote directory structure and add the python_destination
|
|
foreach(d IN LISTS remote_dirs)
|
|
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/pytriqs/${d})
|
|
endforeach()
|
|
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/pytriqs/${python_destination})
|
|
|
|
# Do all symbolic links for the files
|
|
foreach(f IN LISTS remote_files)
|
|
execute_process(COMMAND ln -snf ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST}/${f} ${CMAKE_BINARY_DIR}/pytriqs/${f})
|
|
endforeach()
|
|
|
|
# Copy and install the __init__.py files
|
|
file(WRITE ${CMAKE_BINARY_DIR}/.python/__init__.py "__all__=[]")
|
|
set(partial_dir ${python_destination})
|
|
while(partial_dir MATCHES "/")
|
|
string(REGEX REPLACE "/[^/]*$" "" partial_dir ${partial_dir})
|
|
if(NOT EXISTS ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST}/${partial_dir}/__init__.py)
|
|
execute_process(COMMAND cp ${CMAKE_BINARY_DIR}/.python/__init__.py ${CMAKE_BINARY_DIR}/pytriqs/${partial_dir})
|
|
install(FILES ${CMAKE_BINARY_DIR}/.python/__init__.py DESTINATION ${TRIQS_PYTHON_LIB_DEST}/${partial_dir})
|
|
endif(NOT EXISTS ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST}/${partial_dir}/__init__.py)
|
|
endwhile(partial_dir MATCHES "/")
|
|
|
|
# Install all other files
|
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/python/ DESTINATION ${TRIQS_PYTHON_LIB_DEST}/${python_destination} FILES_MATCHING PATTERN *.py)
|
|
|
|
# Set a rule to have original python files copied to their destination if modified
|
|
FILE(GLOB_RECURSE python_sources RELATIVE ${CMAKE_SOURCE_DIR}/python *.py)
|
|
SET(py_copy_tar ${CMAKE_BINARY_DIR}/py_copy.tar)
|
|
add_custom_command (OUTPUT ${py_copy_tar} DEPENDS ${python_sources}
|
|
COMMAND cd ${CMAKE_SOURCE_DIR}/python && tar cf ${py_copy_tar} ${python_sources} &&
|
|
cd ${CMAKE_BINARY_DIR}/pytriqs/${python_destination} && tar xf ${py_copy_tar})
|
|
add_custom_target(py_copy ALL DEPENDS ${py_copy_tar})
|
|
|
|
endmacro()
|
|
|
|
|
|
#
|
|
# This macro builds the f2py module
|
|
# - target_name
|
|
# -
|
|
#
|
|
macro (triqs_build_f2py_module target_name modulename module_pyf_name filelist1)
|
|
|
|
set(filelist ${filelist1} ${ARGN})
|
|
set(filename temp_script.py)
|
|
# Copy all the files
|
|
EXECUTE_PROCESS(COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/${module_pyf_name} ${CMAKE_CURRENT_BINARY_DIR} )
|
|
FOREACH( f ${filelist})
|
|
EXECUTE_PROCESS(COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/${f} ${CMAKE_CURRENT_BINARY_DIR} )
|
|
ENDFOREACH(f)
|
|
# write the script that will build the f2py extension
|
|
SET(filename ${CMAKE_CURRENT_BINARY_DIR}/${filename} )
|
|
FILE(WRITE ${filename} "import sys\n")
|
|
FILE(APPEND ${filename} "from numpy.f2py import main\n")
|
|
FILE(APPEND ${filename} "sys.argv = [''] +'-c --f77exec=${CMAKE_Fortran_COMPILER} --f90exec=${CMAKE_Fortran_COMPILER} -m ${modulename} ${modulename}.pyf ${filelist} -llapack'.split()\n")
|
|
FILE(APPEND ${filename} "main()\n")
|
|
|
|
# We had the normal target of the module
|
|
add_custom_target(${target_name} ALL DEPENDS ${modulename}.so)
|
|
|
|
# TODO : to be corrected with the filelist is more than one file.
|
|
# ... and a special target to build vertex.so, that depends on the sources files
|
|
add_custom_command(OUTPUT ${modulename}.so
|
|
COMMAND echo See `pwd`/f2pyBuild.log for logs
|
|
COMMAND ${TRIQS_PYTHON_INTERPRETER} temp_script.py > f2pyBuild.log 2>&1
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${filelist} ${CMAKE_CURRENT_SOURCE_DIR}/${module_pyf_name}
|
|
)
|
|
|
|
#FILE(RELATIVE_PATH rel ${CMAKE_SOURCE_DIR}/Modules ${CMAKE_CURRENT_SOURCE_DIR}/)
|
|
#install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${modulename}.so
|
|
# DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${ExecutableName}/triqs/${rel}/..)
|
|
|
|
endmacro (triqs_build_f2py_module)
|
|
|
|
macro (triqs_make_target_to_copy_all_py_files_from_python_dir_to_build_dir)
|
|
FILE(GLOB_RECURSE all_py_files RELATIVE ${CMAKE_SOURCE_DIR}/python *.py )
|
|
SET(py_copy_tar ${CMAKE_BINARY_DIR}/py_copy.tar)
|
|
add_custom_command (OUTPUT ${py_copy_tar} DEPENDS ${all_py_files}
|
|
COMMAND cd ${CMAKE_SOURCE_DIR}/python && tar cf ${py_copy_tar} ${all_py_files} && mkdir -p ${CMAKE_BINARY_DIR}/python && cd ${CMAKE_BINARY_DIR}/python && tar xf ${py_copy_tar} )
|
|
add_custom_target(py_copy ALL DEPENDS ${py_copy_tar})
|
|
endmacro()
|
|
|