View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0012282CMakeCMakepublic2011-06-15 23:452016-06-10 14:31
ReporterAndreas Schuh 
Assigned ToKitware Robot 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionmoved 
PlatformApple MacOSOS XOS Version10.4.10
Product VersionCMake 2.8.4 
Target VersionFixed in Version 
Summary0012282: get_filename_component interprets first period (.) as start of extension (EXT)
DescriptionThe 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 Reproduceget_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 InformationHere 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 ()
TagsCMake, extension, filename, get_filename_component
Attached Files

 Relationships

  Notes
(0026879)
David Cole (manager)
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 (manager)
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 (administrator)
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.

 Issue History
Date Modified Username Field Change
2011-06-15 23:45 Andreas Schuh New Issue
2011-06-15 23:46 Andreas Schuh Tag Attached: CMake
2011-06-15 23:46 Andreas Schuh Tag Attached: extension
2011-06-15 23:46 Andreas Schuh Tag Attached: filename
2011-06-15 23:46 Andreas Schuh Tag Attached: get_filename_component
2011-06-16 07:09 David Cole Note Added: 0026879
2011-06-16 07:11 David Cole Note Edited: 0026879
2012-08-11 11:09 David Cole Status new => backlog
2012-08-11 11:09 David Cole Note Added: 0030267
2016-06-10 14:28 Kitware Robot Note Added: 0041851
2016-06-10 14:28 Kitware Robot Status backlog => resolved
2016-06-10 14:28 Kitware Robot Resolution open => moved
2016-06-10 14:28 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team