mirror of
https://github.com/triqs/dft_tools
synced 2025-01-05 19:08:45 +01:00
[cmake] Provide extract_flags macro in share/cmake directory, simplify creation of docs_cpp2rst target
This commit is contained in:
parent
10fd7f19a0
commit
9f5aa8578c
@ -4,23 +4,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in ${CMAKE_CURRENT_BINARY_DIR
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Create an optional target that allows us to regenerate the C++ doc with c++2rst
|
# Create an optional target that allows us to regenerate the C++ doc with c++2rst
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
foreach(t app4triqs_c triqs)
|
|
||||||
get_property(INCLUDE_DIRS TARGET ${t} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
|
||||||
get_property(SYSTEM_INCLUDE_DIRS TARGET ${t} PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
|
|
||||||
if(SYTEM_INCLUDE_DIRS)
|
|
||||||
list(REMOVE_ITEM INCLUDE_DIRS ${SYSTEM_INCLUDE_DIRS})
|
|
||||||
endif()
|
|
||||||
foreach(DIR ${INCLUDE_DIRS})
|
|
||||||
set(CPP2RST_INCLUDE_FLAGS ${CPP2RST_INCLUDE_FLAGS} -I${DIR})
|
|
||||||
endforeach()
|
|
||||||
foreach(DIR ${SYSTEM_INCLUDE_DIRS})
|
|
||||||
set(CPP2RST_INCLUDE_FLAGS ${CPP2RST_INCLUDE_FLAGS} -isystem=${DIR})
|
|
||||||
endforeach()
|
|
||||||
get_property(COMPILE_OPTIONS TARGET ${t} PROPERTY INTERFACE_COMPILE_OPTIONS)
|
|
||||||
set(CPP2RST_CXXFLAGS ${CPP2RST_CXXFLAGS} ${COMPILE_OPTIONS})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
add_custom_target(docs_cpp2rst)
|
add_custom_target(docs_cpp2rst)
|
||||||
|
include(${PROJECT_SOURCE_DIR}/share/cmake/extract_flags.cmake)
|
||||||
|
extract_flags(app4triqs_c)
|
||||||
|
separate_arguments(app4triqs_c_CXXFLAGS)
|
||||||
macro(generate_docs header_file)
|
macro(generate_docs header_file)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET docs_cpp2rst
|
TARGET docs_cpp2rst
|
||||||
@ -30,8 +17,8 @@ macro(generate_docs header_file)
|
|||||||
${header_file}
|
${header_file}
|
||||||
-N app4triqs
|
-N app4triqs
|
||||||
--output_directory ${CMAKE_CURRENT_SOURCE_DIR}/cpp2rst_generated
|
--output_directory ${CMAKE_CURRENT_SOURCE_DIR}/cpp2rst_generated
|
||||||
--cxxflags="${CPP2RST_CXXFLAGS}"
|
-I${PROJECT_SOURCE_DIR}/c++
|
||||||
${CPP2RST_INCLUDE_FLAGS}
|
--cxxflags="${app4triqs_c_CXXFLAGS}"
|
||||||
)
|
)
|
||||||
endmacro(generate_docs)
|
endmacro(generate_docs)
|
||||||
|
|
||||||
|
67
share/cmake/extract_flags.cmake
Normal file
67
share/cmake/extract_flags.cmake
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# Recursively fetch all targets that the interface of a target depends upon
|
||||||
|
macro(get_all_interface_targets name target)
|
||||||
|
get_property(TARGET_LINK_LIBRARIES TARGET ${target} PROPERTY INTERFACE_LINK_LIBRARIES)
|
||||||
|
foreach(lib IN LISTS TARGET_LINK_LIBRARIES)
|
||||||
|
if(TARGET ${lib})
|
||||||
|
# Append to list
|
||||||
|
list(APPEND ${name}_INTERFACE_TARGETS ${lib})
|
||||||
|
# Recure into target dependencies
|
||||||
|
get_all_interface_targets(${name} ${lib})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# Extract the property from the target and recursively from all targets it depends upon
|
||||||
|
macro(get_property_recursive)
|
||||||
|
cmake_parse_arguments(get_property_recursive "" "TARGET" "PROPERTY" ${ARGN})
|
||||||
|
set(target ${get_property_recursive_TARGET})
|
||||||
|
set(property ${get_property_recursive_PROPERTY})
|
||||||
|
get_all_interface_targets(${target} ${target})
|
||||||
|
foreach(t IN LISTS ${target}_INTERFACE_TARGETS ITEMS ${target})
|
||||||
|
get_property(p TARGET ${t} PROPERTY ${property})
|
||||||
|
list(APPEND ${ARGV0} ${p})
|
||||||
|
endforeach()
|
||||||
|
# Clean duplicates and any occurance of '/usr/include' dirs
|
||||||
|
if(${ARGV0})
|
||||||
|
list(REMOVE_DUPLICATES ${ARGV0})
|
||||||
|
list(REMOVE_ITEM ${ARGV0} /usr/include)
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# Recursively fetch all compiler flags attached to the interface of a target
|
||||||
|
macro(extract_flags target)
|
||||||
|
|
||||||
|
get_property_recursive(opts TARGET ${target} PROPERTY INTERFACE_COMPILE_OPTIONS)
|
||||||
|
foreach(opt ${opts})
|
||||||
|
set(${target}_LDFLAGS "${${target}_LDFLAGS} ${opt}")
|
||||||
|
set(${target}_CXXFLAGS "${${target}_CXXFLAGS} ${opt}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
get_property_recursive(defs TARGET ${target} PROPERTY INTERFACE_COMPILE_DEFINITIONS)
|
||||||
|
foreach(def ${defs})
|
||||||
|
set(${target}_CXXFLAGS "${${target}_CXXFLAGS} -D${def}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
get_property_recursive(inc_dirs TARGET ${target} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||||
|
get_property_recursive(sys_inc_dirs TARGET ${target} PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
|
||||||
|
list(REMOVE_ITEM inc_dirs ${sys_inc_dirs})
|
||||||
|
foreach(dir ${inc_dirs})
|
||||||
|
set(${target}_CXXFLAGS "${${target}_CXXFLAGS} -I${dir}")
|
||||||
|
endforeach()
|
||||||
|
foreach(dir ${sys_inc_dirs})
|
||||||
|
set(${target}_CXXFLAGS "${${target}_CXXFLAGS} -isystem${dir}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
get_property_recursive(libs TARGET ${target} PROPERTY INTERFACE_LINK_LIBRARIES)
|
||||||
|
foreach(lib ${libs})
|
||||||
|
if(NOT TARGET ${lib})
|
||||||
|
set(${target}_LDFLAGS "${${target}_LDFLAGS} ${lib}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# We have to replace generator expressions explicitly
|
||||||
|
string(REGEX REPLACE "\\$<INSTALL_INTERFACE:([^ ]*)>" "\\1" ${target}_LDFLAGS "${${target}_LDFLAGS}")
|
||||||
|
string(REGEX REPLACE "\\$<INSTALL_INTERFACE:([^ ]*)>" "\\1" ${target}_CXXFLAGS "${${target}_CXXFLAGS}")
|
||||||
|
string(REGEX REPLACE " [^ ]*\\$<[^ ]*:[^ ]*>" "" ${target}_LDFLAGS "${${target}_LDFLAGS}")
|
||||||
|
string(REGEX REPLACE " [^ ]*\\$<[^ ]*:[^ ]*>" "" ${target}_CXXFLAGS "${${target}_CXXFLAGS}")
|
||||||
|
endmacro()
|
Loading…
Reference in New Issue
Block a user