mirror of
https://github.com/triqs/dft_tools
synced 2024-12-26 14:23:38 +01:00
4cb83c370b
modified: cmake/TRIQSConfig.cmake.in
208 lines
10 KiB
CMake
208 lines
10 KiB
CMake
# version
|
|
set(TRIQS_VERSION @TRIQS_VERSION@)
|
|
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 @BOOST_INCLUDE_DIR@)
|
|
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 @BOOST_LIBRARY@)
|
|
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@)
|
|
set(TRIQS_COMPILER_IS_C11_COMPLIANT @TRIQS_COMPILER_IS_C11_COMPLIANT@)
|
|
|
|
# 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@)
|
|
|
|
# for people who want to quickly add everything TRIQS has detected...
|
|
set(TRIQS_LIBRARY_ALL ${TRIQS_LIBRARY} ${TRIQS_LIBRARY_BOOST} ${TRIQS_LIBRARY_PYTHON} ${TRIQS_LIBRARY_MPI} ${TRIQS_LIBRARY_HDF5} ${TRIQS_LIBRARY_LAPACK} ${TRIQS_LIBRARY_FFTW} ${TRIQS_LIBRARY_GMP} ${TRIQS_LIBRARY_GSL} )
|
|
set(TRIQS_INCLUDE_ALL ${TRIQS_INCLUDE} ${TRIQS_INCLUDE_BOOST} ${TRIQS_INCLUDE_PYTHON} ${TRIQS_INCLUDE_MPI} ${TRIQS_INCLUDE_HDF5} ${TRIQS_INCLUDE_LAPACK} ${TRIQS_INCLUDE_FFTW} ${TRIQS_INCLUDE_GMP} ${TRIQS_INCLUDE_GSL} )
|
|
list (REMOVE_DUPLICATES TRIQS_INCLUDE_ALL)
|
|
|
|
# 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
|
|
#
|
|
# NickName =
|
|
# ModuleName = the python name of the module
|
|
# ModuleDest = path in the pytriqs tree [ FOR INSTALLATION ONLY] IMPROVE MAKE THIS OPTIONAL (for test)
|
|
macro (triqs_cython_module NickName ModuleName)
|
|
message(STATUS "TRIQS: Preparing cython module ${NickName} with the interpreter ${TRIQS_PYTHON_INTERPRETER} ")
|
|
get_filename_component(CYTHON_EXECUTABLE_PATH ${TRIQS_PYTHON_INTERPRETER} PATH)
|
|
set(CYTHON_EXECUTABLE ${CYTHON_EXECUTABLE_PATH}/cython CACHE STRING "Path to the cython executable")
|
|
set(cython_src ${CMAKE_CURRENT_SOURCE_DIR}/${ModuleName}.pyx )
|
|
FILE(GLOB all_pyx_src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.pyx *.pxd )
|
|
set(cython_wrap ${CMAKE_CURRENT_BINARY_DIR}/wrap_${NickName}_by_cython.cpp)
|
|
add_custom_command (OUTPUT ${cython_wrap} DEPENDS ${all_pyx_src} COMMAND ${CYTHON_EXECUTABLE} ${cython_src} -I ${CMAKE_CURRENT_SOURCE_DIR}/ -I@CMAKE_INSTALL_PREFIX@/include/pytriqs/ -I@CMAKE_INSTALL_PREFIX@/include/ -X embedsignature=True --cplus -o ${cython_wrap} )
|
|
add_custom_target(cython_${NickName} ALL DEPENDS ${cython_wrap})
|
|
|
|
add_library(${ModuleName} MODULE ${cython_wrap} )
|
|
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 (TARGETS ${ModuleName} DESTINATION @TRIQS_PYTHON_LIB_DEST@/${ARGN} )
|
|
endif (${ARGN} MATCHES "")
|
|
set_property (GLOBAL APPEND PROPERTY DEPENDANCE_TO_ADD triqs_${NickName} )
|
|
|
|
endmacro (triqs_cython_module)
|
|
|
|
|
|
# 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,${CMAKE_INSTALL_PREFIX}/lib)
|
|
set_target_properties(${Target} PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
|
|
set_target_properties(${Target} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/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)
|
|
|
|
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)
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E chdir ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST}
|
|
find . -type d -exec mkdir -p ${CMAKE_BINARY_DIR}/pytriqs/{} \;)
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E chdir ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST}
|
|
find . -type f -exec ln -snf ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST}/{} ${CMAKE_BINARY_DIR}/pytriqs/{} \;)
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E chdir ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST}
|
|
find . -type l -exec ln -snf ${TRIQS_PATH}/${TRIQS_PYTHON_LIB_DEST}/{} ${CMAKE_BINARY_DIR}/pytriqs/{} \;)
|
|
|
|
# Create directories where python files will go and make sure there is an __init__.py all the way
|
|
execute_process(COMMAND mkdir -p ${CMAKE_BINARY_DIR}/pytriqs/${python_destination})
|
|
|
|
# Copy and install __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 ${CMAKE_BINARY_DIR}/pytriqs/${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 ${CMAKE_BINARY_DIR}/pytriqs/${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()
|
|
|