3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 13:53:40 +01:00
dft_tools/cmake/TRIQSConfig.cmake.in
Olivier Parcollet f12eccc69f cmake: add macro to fix rpath to triqs install
- to be tested on mac
2013-07-25 15:19:54 +02:00

167 lines
7.4 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@)
# 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@)
# Fix the rpath
#set(CMAKE_INSTALL_RPATH "@CMAKE_INSTALL_PREFIX@/lib")
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
#set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
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_add_rpath_for_cxx_code)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
else()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
endmacro()
macro (triqs_add_rpath_to_triqs_install)
link_libraries ( -Wl,-rpath,@CMAKE_INSTALL_PREFIX@/lib)
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()