[cmake-developers] [CMake 0012282]: get_filename_component interprets first period (.) as start of extension (EXT)

Mantis Bug Tracker mantis at public.kitware.com
Wed Jun 15 23:45:27 EDT 2011


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=12282 
====================================================================== 
Reported By:                Andreas Schuh
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   12282
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2011-06-15 23:45 EDT
Last Modified:              2011-06-15 23:45 EDT
====================================================================== 
Summary:                    get_filename_component interprets first period (.)
as start of extension (EXT)
Description: 
The get_filename_component (VAR PATH EXT) command returns everything starting
with the first encountered period (.) as file name extension. Often, periods are
also just used to separate file name components, for example, in the naming of
DICOM files. I had expected that only the part starting with the *last* period
will be interpreted as file name extension.

Steps to Reproduce: 
get_filename_component (VAR "this.is.a.text.file.txt" EXT)

if (${VAR} STREQUAL ".txt")
  message ("GREAT! It is working as expected.")
else ()
  message (FATAL_ERROR "Sorry, the returned extensions is \"${EXT}\" !=
\".txt\"")
endif ()

Additional Information: 
Here is a workaround implemented in CMake itself:

function (get_filename_component)
  _get_filename_component (${ARGN})
  list (GET ARGN 0 VAR)
  list (GET ARGN 2 CMD)
  if (${CMD} STREQUAL "EXT")
    string (REGEX MATCHALL "\\.[^.]*" PARTS "${${VAR}}")
    list (LENGTH PARTS LEN)
    if (LEN GREATER 1)
      math (EXPR LEN "${LEN} - 1")
      list (GET PARTS ${LEN} ${VAR})
    endif ()
  else ()
  endif ()
  set (${VAR} "${${VAR}}" PARENT_SCOPE)
endfunction ()
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2011-06-15 23:45 Andreas Schuh  New Issue                                    
======================================================================




More information about the cmake-developers mailing list