Warning, /sdk/pology/cmake/ProjectTools.cmake is written in an unsupported language. File is not indexed.

0001 # TODO: Add doc comments for all this stuff.
0002 
0003 
0004 function(GET_CURRENT_SOURCE_SUBDIR subdirvar)
0005     set(argn ${ARGN})
0006 
0007     string(REPLACE ${CMAKE_SOURCE_DIR}/ "" subdir
0008                    ${CMAKE_CURRENT_SOURCE_DIR})
0009 
0010     if(${ARGC} GREATER 1)
0011         string(REPLACE "/" ";" subdirlst ${subdir})
0012         list(LENGTH subdirlst subdepth)
0013         set(start 0)
0014         if(${ARGC} GREATER 1)
0015             list(GET argn 0 start)
0016             string(REGEX MATCH "^-" isneg ${start})
0017             if(isneg)
0018                 math(EXPR start "${subdepth} ${start}")
0019             endif()
0020         endif()
0021         set(end ${subdepth})
0022         if(${ARGC} GREATER 2)
0023             list(GET argn 1 end)
0024             string(REGEX MATCH "^-" isneg ${end})
0025             if(isneg)
0026                 math(EXPR end "${subdepth} ${end}")
0027             endif()
0028         endif()
0029         set(subdir "")
0030         set(i 0)
0031         math(EXPR startm1 "${start} - 1")
0032         math(EXPR endp1 "${end} + 1")
0033         foreach(cdir ${subdirlst})
0034             if(i GREATER startm1 AND i LESS endp1)
0035                 if(subdir)
0036                     set(subdir "${subdir}/${cdir}")
0037                 else()
0038                     set(subdir "${cdir}")
0039                 endif()
0040             endif()
0041             math(EXPR i "${i} + 1")
0042         endforeach()
0043     endif()
0044 
0045     set(${subdirvar} "${subdir}" PARENT_SCOPE)
0046 
0047 endfunction()
0048 
0049 
0050 macro(LINK_INSTALL_SCRIPTS instdir linkdir)
0051     set(scripts ${ARGN})
0052 
0053     # If install directory is a relative path, prepend install prefix.
0054     if(NOT IS_ABSOLUTE ${instdir})
0055         set(instdir ${CMAKE_INSTALL_PREFIX}/${instdir})
0056     endif()
0057 
0058     # Determine base name for targets.
0059     get_current_source_subdir(srcsubdir)
0060     string(REPLACE "/" "-" targbase ${srcsubdir})
0061 
0062     if(UNIX)
0063         # On UNIX platforms, make symlinks to point as installed.
0064         set(scriptlinks)
0065         foreach(script ${scripts})
0066             get_filename_component(scriptname ${script} NAME)
0067             get_filename_component(scriptnamewe ${script} NAME_WE)
0068             set(scriptlinkdir ${CMAKE_CURRENT_BINARY_DIR}/bin)
0069             set(scriptlink ${scriptlinkdir}/${scriptnamewe})
0070             set(scriptlinks ${scriptlinks} ${scriptlink})
0071             add_custom_command(OUTPUT ${scriptlink}
0072                                COMMAND mkdir -p ${scriptlinkdir}
0073                                COMMAND ln -sf
0074                                        ${instdir}/${scriptname}
0075                                        ${scriptlink}
0076                                DEPENDS ${script})
0077             install(PROGRAMS ${script} DESTINATION ${instdir})
0078             install(PROGRAMS ${scriptlink} DESTINATION ${linkdir})
0079         endforeach()
0080         add_custom_target(${targbase}-links ALL DEPENDS ${scriptlinks})
0081     else()
0082         # On non-UNIX platforms, put scripts directly into linkdir instead.
0083         # FIXME: Batch files for WIN32?
0084         foreach(script ${scripts})
0085             get_filename_component(scriptnamewe ${script} NAME_WE)
0086             install(PROGRAMS ${script} DESTINATION ${linkdir}
0087                     RENAME ${scriptnamewe})
0088         endforeach()
0089     endif()
0090 
0091 endmacro()
0092 
0093