MantisBT - CMake
View Issue Details
0012282CMakeCMakepublic2011-06-15 23:452016-06-10 14:31
Andreas Schuh 
Kitware Robot 
normalminoralways
closedmoved 
Apple MacOS X10.4.10
CMake 2.8.4 
 
0012282: get_filename_component interprets first period (.) as start of extension (EXT)
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.
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 ()
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 ()
CMake, extension, filename, get_filename_component
Issue History
2011-06-15 23:45Andreas SchuhNew Issue
2011-06-15 23:46Andreas SchuhTag Attached: CMake
2011-06-15 23:46Andreas SchuhTag Attached: extension
2011-06-15 23:46Andreas SchuhTag Attached: filename
2011-06-15 23:46Andreas SchuhTag Attached: get_filename_component
2011-06-16 07:09David ColeNote Added: 0026879
2011-06-16 07:11David ColeNote Edited: 0026879bug_revision_view_page.php?bugnote_id=26879#r356
2012-08-11 11:09David ColeStatusnew => backlog
2012-08-11 11:09David ColeNote Added: 0030267
2016-06-10 14:28Kitware RobotNote Added: 0041851
2016-06-10 14:28Kitware RobotStatusbacklog => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0026879)
David Cole   
2011-06-16 07:09   
(edited on: 2011-06-16 07:11)
Here's another (simpler?) work-around in the meantime:

  get_filename_component (VAR "this.is.a.text.file.txt" EXT)
  message("VAR='${VAR}'")

  string(REGEX REPLACE "^.+(\\.[^.]+)$" "\\1" VAR2 "this.is.a.text.file.txt")
  message("VAR2='${VAR2}'")

Use the regex version to get everything after the last "." -- as a bonus, you could simply alter the position of the open paren to either include or exclude the "." itself in the output.

Thanks for the report. We'll have to "fix" this, if we do, by adding new keywords to the get_filename_component command. Because I am quite certain that there are people that are now relying on the existing behavior reported here.

(0030267)
David Cole   
2012-08-11 11:09   
Sending old, never assigned issues to the backlog.

(The age of the bug, plus the fact that it's never been assigned to anyone means that nobody is actively working on it...)

If an issue you care about is sent to the backlog when you feel it should have been addressed in a different manner, please bring it up on the CMake mailing list for discussion. Sign up for the mailing list here, if you're not already on it: http://www.cmake.org/mailman/listinfo/cmake [^]

It's easy to re-activate a bug here if you can find a CMake developer who has the bandwidth to take it on, and ferry a fix through to our 'next' branch for dashboard testing.
(0041851)
Kitware Robot   
2016-06-10 14:28   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.