# - AddCommon # To add a common object # SET(myindent "${myindent}\t") message(STATUS "${myindent}\"AddCommon\" included!") if(__AddCommon_INCLUDED) return() endif() set(__AddCommon_INCLUDED TRUE) #------------------------------------------------------------------------------- # _icedust_detach_debinfo() # # Helper macro to detach the debug information from the target. # # The debug info of the given target are extracted and saved on a different file # with the extension '.dbg', that is installed alongside the binary. #------------------------------------------------------------------------------- macro(_icedust_detach_debinfo target) message(STATUS "${myindent}==>macro(_icedust_detach_debinfo target)") SET(myindent "${myindent}\t") if(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo AND ICEDUST_DETACHED_DEBINFO) # get the type of the target (MODULE_LIBRARY, SHARED_LIBRARY, EXECUTABLE) get_property(_type TARGET ${target} PROPERTY TYPE) #message(STATUS "${myindent}_icedust_detach_debinfo(${target}): target type -> ${_type}") if(NOT _type STREQUAL STATIC_LIBRARY) # we ignore static libraries # guess the target file name if(_type MATCHES "MODULE|LIBRARY") #message(STATUS "${myindent}_icedust_detach_debinfo(${target}): library sub-type -> ${CMAKE_MATCH_0}") # TODO: the library name may be different from the default. # see OUTPUT_NAME and LIBRARY_OUPUT_NAME set(_tn ${CMAKE_SHARED_${CMAKE_MATCH_0}_PREFIX}${target}${CMAKE_SHARED_${CMAKE_MATCH_0}_SUFFIX}) set(_builddir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) set(_dest lib) else() set(_tn ${target}) if(ICEDUST_USE_EXE_SUFFIX) set(_tn ${_tn}.exe) endif() set(_builddir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) set(_dest bin) endif() endif() #message(STATUS "${myindent}_icedust_detach_debinfo(${target}): target name -> ${_tn}") # From 'man objcopy': # objcopy --only-keep-debug foo foo.dbg # objcopy --strip-debug foo # objcopy --add-gnu-debuglink=foo.dbg foo add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${_tn} ${_tn}.dbg COMMAND ${CMAKE_OBJCOPY} --strip-debug ${_tn} COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${_tn}.dbg ${_tn} WORKING_DIRECTORY ${_builddir} COMMENT "Detaching debug infos for ${_tn} (${target}).") # ensure that the debug file is installed on 'make install'... install(FILES ${_builddir}/${_tn}.dbg DESTINATION ${_dest} OPTIONAL) # ... and removed on 'make clean'. set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${_builddir}/${_tn}.dbg) endif() string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}") message(STATUS "${myindent}<==macro(_icedust_detach_debinfo target)") endmacro() #------------------------------------------------------------------------------- # icedust_common_add_build(sources... # LINK_LIBRARIES library1 package2 ... # INCLUDE_DIRS dir1 package2 ...) # # Internal. Helper macro to factor out the common code to configure a buildable # target (library, module, dictionary...) #------------------------------------------------------------------------------- macro(icedust_common_add_build) message(STATUS "${myindent}==>macro(icedust_common_add_build) (${ARGN})") SET(myindent "${myindent}\t") CMAKE_PARSE_ARGUMENTS(ARG "" "" "LIBRARIES;LINK_LIBRARIES;INCLUDE_DIRS" ${ARGN}) # obsolete option if(ARG_LIBRARIES) message(WARNING "${myindent}Deprecated option 'LIBRARIES', use 'LINK_LIBRARIES' instead") set(ARG_LINK_LIBRARIES ${ARG_LINK_LIBRARIES} ${ARG_LIBRARIES}) endif() set(ARG_LINK_LIBRARIES ${ARG_LINK_LIBRARIES} -L${CMAKE_BINARY_DIR}/lib) # find the sources icedust_expand_sources(library_srcs ${ARG_UNPARSED_ARGUMENTS}) # find the headers icedust_expand_incdirs(ARG_INCLUDE_DIRS) # find the links icedust_expand_links(ARG_LINK_LIBRARIES) string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}") message(STATUS "${myindent}<==macro(icedust_common_add_build)") endmacro() #------------------------------------------------------------------------------- # icedust_expand_sources( source_pattern1 source_pattern2 ...) # # Expand glob patterns for input files to a list of files, first searching in # ``src`` then in the current directory. #------------------------------------------------------------------------------- macro(icedust_expand_sources VAR) SET(myindent "${myindent}\t") message(STATUS "${myindent}==>macro(icedust_expand_sources ${VAR})") SET(myindent "${myindent}\t") message(STATUS "${myindent}Expand ${ARGN} to ${VAR}") set(${VAR}) foreach(fp ${ARGN}) FILE(GLOB srcfiles ${package_dir}/src/${fp}) message(STATUS "${myindent} found: ${srcfiles}") set(${VAR} ${${VAR}} ${srcfiles}) endforeach() message(STATUS "${myindent}result: ${${VAR}}") string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}") message(STATUS "${myindent}<==macro(icedust_expand_sources ${VAR})") endmacro() macro(get_dirs2inc i_package_reldir) message(STATUS "${myindent}==>macro(get_dirs2inc ${i_package_reldir})") SET(myindent "${myindent}\t") # message(STATUS "${myindent}package: "${i_package_reldir}) if(EXISTS ${project_dir}/packages/${i_package_reldir}/cmake/CMakeCache.txt) # message(STATUS "${myindent}${project_dir}/packages/${i_package_reldir}/cmake/CMakeCache.txt!") file(READ ${project_dir}/packages/${i_package_reldir}/cmake/CMakeCache.txt ${i_package_reldir}_file_contents) else() message(STATUS "${myindent}${project_dir}/packages/${i_package_reldir}/cmake/CMakeCache.txt?") endif() if(NOT "${${i_package_reldir}_file_contents}" STREQUAL "") string(REGEX MATCHALL "dirs2inc:STRING=[^\n]*" ${i_package_reldir}_vars "${${i_package_reldir}_file_contents}") if(NOT "${${i_package_reldir}_vars}" STREQUAL "") # message(STATUS "${myindent}Got dirs2inc!") string(REGEX REPLACE "dirs2inc:STRING=" "" ${i_package_reldir}_vars "${${i_package_reldir}_vars}") # string(REGEX REPLACE ";" " " ${i_package_reldir}_vars "${${i_package_reldir}_vars}") message(STATUS "${myindent}${i_package_reldir}_vars: ${${i_package_reldir}_vars}") foreach(${i_package_reldir}_var ${${i_package_reldir}_vars}) message(STATUS "${myindent}add_inc( ${${i_package_reldir}_var} )") SET(${ARGN} ${${ARGN}} ${${i_package_reldir}_var}) endforeach() message(STATUS "${myindent}${ARGN}: ${${ARGN}}") else() message(STATUS "${myindent}dirs2inc?") endif() endif() string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}") message(STATUS "${myindent}<==macro(get_dirs2inc ${i_package_reldir})") endmacro() #------------------------------------------------------------------------------- # icedust_expand_incdirs(Package1 [Package2 ...]) # # Get all the directories needed for building up this package #------------------------------------------------------------------------------- macro(icedust_expand_incdirs) message(STATUS "${myindent}==>macro(icedust_expand_incdirs) (${ARGN})") SET(myindent "${myindent}\t") message(STATUS "${myindent}add_include( ${package_dirs2inc})") SET(${ARGN} ${${ARGN}} ${package_dirs2inc}) foreach(i_package_reldir ${dependency_tree}) get_dirs2inc(${i_package_reldir}) message(STATUS "${myindent}${i_package_reldir}_vars = \"${${i_package_reldir}_vars}\"") foreach(${i_package_reldir}_var ${${i_package_reldir}_vars}) message(STATUS "${myindent}add_include( ${${i_package_reldir}_var})") SET(${ARGN} ${${ARGN}} ${${i_package_reldir}_var}) endforeach() endforeach() message(STATUS "${myindent}${ARGN} = \"${${ARGN}}\"") # FIXME: need to support ARGN # foreach(package ${ARGN}) # # we need to ensure that the user can call this function also for directories # # message(STATUS "${myindent} #in "${package}) # message(STATUS "${myindent} CMAKE_CURRENT_SOURCE_DIR:"${CMAKE_CURRENT_SOURCE_DIR}) # message(STATUS "${myindent} CMAKE_SOURCE_DIR:"${CMAKE_SOURCE_DIR}) # if(TARGET ${package}) # get_target_property(to_incl ${package} SOURCE_DIR) # if(to_incl) # message(STATUS ${to_incl}) # #message(STATUS "${myindent} icedust_expand_incdirs1 include_directories(${to_incl})") # include_directories(${to_incl}) # else() # endif() # elseif(IS_ABSOLUTE ${package} AND IS_DIRECTORY ${package}) # #message(STATUS "${myindent} icedust_expand_incdirs2 include_directories(${package})") # include_directories(${package}) # elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${package}) # #message(STATUS "${myindent} icedust_expand_incdirs3 include_directories(${package})") # include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${package}) # elseif(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/${package}) # package can be the name of a subdir # #message(STATUS "${myindent} icedust_expand_incdirs4 include_directories(${package})") # include_directories(${CMAKE_SOURCE_DIR}/${package}) # else() # # ensure that the current directory knows about the package # find_package(${package} QUIET) # set(to_incl) # string(TOUPPER ${package} _pack_upper) # if(${_pack_upper}_FOUND OR ${package}_FOUND) # # Handle some special cases first, then try for package uppercase (DIRS and DIR) # # If the package is found, add INCLUDE_DIRS or (if not defined) INCLUDE_DIR. # # If none of the two is defined, do not add anything. # if(${package} STREQUAL PythonLibs) # set(to_incl PYTHON_INCLUDE_DIRS) # elseif(${_pack_upper}_INCLUDE_DIRS) # set(to_incl ${_pack_upper}_INCLUDE_DIRS) # elseif(${_pack_upper}_INCLUDE_DIR) # set(to_incl ${_pack_upper}_INCLUDE_DIR) # elseif(${package}_INCLUDE_DIRS) # set(to_incl ${package}_INCLUDE_DIRS) # endif() # # Include the directories # #message(STATUS "${myindent} icedust_expand_incdirs5 include_directories(${${to_incl}})") # include_directories(${${to_incl}}) # endif() # endif() # endforeach() string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}") message(STATUS "${myindent}<==macro(icedust_expand_incdirs)") endmacro() #------------------------------------------------------------------------------- # icedust_expand_links(Package1 [Package2 ...]) # # Get all the link options needed for building up this package #------------------------------------------------------------------------------- macro(icedust_expand_links) message(STATUS "${myindent}==>macro(icedust_expand_links) (${ARGN})") SET(myindent "${myindent}\t") SET(${ARGN} ${${ARGN}} ${package_tars2link}) foreach(i_package_reldir ${dependency_tree}) # message(STATUS "${myindent} package: "${i_package_reldir}) if(EXISTS ${project_dir}/packages/${i_package_reldir}/cmake/CMakeCache.txt) # message(STATUS "${myindent} ${project_dir}/packages/${i_package_reldir}/cmake/CMakeCache.txt!") file(READ ${project_dir}/packages/${i_package_reldir}/cmake/CMakeCache.txt ${i_package_reldir}_file_contents) else() # message(STATUS "${myindent} ${project_dir}/packages/${i_package_reldir}/cmake/CMakeCache.txt?") endif() if(NOT "${${i_package_reldir}_file_contents}" STREQUAL "") # message(STATUS "${myindent} Got CMakeCache!") string(REGEX MATCHALL "tars2link:STRING=([^\n]*)" ${i_package_reldir}_vars "${${i_package_reldir}_file_contents}") if(NOT "${${i_package_reldir}_vars}" STREQUAL "") # message(STATUS "${myindent} Got tars2link!") string(REGEX REPLACE "tars2link:STRING=(.*)" "\\1" ${i_package_reldir}_vars "${${i_package_reldir}_vars}") # string(REGEX REPLACE ";" " " ${i_package_reldir}_vars "${${i_package_reldir}_vars}") message(STATUS "${myindent} ${i_package_reldir}_vars: ${${i_package_reldir}_vars}") foreach(${i_package_reldir}_var ${${i_package_reldir}_vars}) message(STATUS "${myindent} add_link( ${${i_package_reldir}_var} )") SET(${ARGN} ${${ARGN}} ${${i_package_reldir}_var}) endforeach() else() # message(STATUS "${myindent} tars2link?") endif() endif() endforeach() # FIXME: need to support ARGN message(STATUS "${myindent}${ARGN} = \"${${ARGN}}\"") string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}") message(STATUS "${myindent}<==macro(icedust_expand_links)") endmacro() #--------------------------------------------------------------------------------------------------- # icedust_install_headers(dir1 dir2 ...) # # Install the declared directories in the 'include' directory. # To be used in case the header files do not have a library. #--------------------------------------------------------------------------------------------------- function(icedust_install_headers) message(STATUS "${myindent}==>function(icedust_install_headers) (${ARGN})") SET(myindent "${myindent}\t") message(STATUS "${myindent} Under developing...") # set_target_properties(${DIRECTORY} PROPERTIES local_headers "") # foreach(hdr_dir ${ARGN}) # message(STATUS "${myindent} !!! Hi it's me, "${hdr_dir}) # install(DIRECTORY ${hdr_dir} # DESTINATION include # FILES_MATCHING # PATTERN "*.h" # PATTERN "*.icpp" # PATTERN "*.hpp" # PATTERN "*.hxx" # PATTERN "CVS" EXCLUDE # PATTERN ".svn" EXCLUDE) # if(NOT IS_ABSOLUTE ${hdr_dir}) # set_target_properties(${DIRECTORY} PROPERTIES local_headers ${hdr_dir}) # message(STATUS "${myindent} setting local_headers to "${local_headers}) # endif() # endforeach() # # flag the current directory as one that installs headers # # the property is used when collecting the include directories for the # # dependent subdirs # if(NOT ${local_headers} STREQUAL "") # set_property(DIRECTORY PROPERTY INSTALLS_LOCAL_HEADERS TRUE) # endif() string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}") message(STATUS "${myindent}<==function(icedust_install_headers) (${ARGN})") endfunction() string(REGEX REPLACE "(\t*)\t" "\\1" myindent "${myindent}")