[Cmake] please provide example of use of STRING(REGEX REPLACE ... )

Bitter, Ingmar (NIH/CC/DRD) IBitter at cc.nih.gov
Tue Apr 1 13:44:37 EST 2003


Hi,

This (below) was very helpful.  Thanks.

STRING(REGEX REPLACE <pattern> <replacement string> 
                     <target variable> <source string>)

Can this syntax clarification be added to CMake.rtf that comes with the
distribution?

-Ingmar

PS: the directory names created by CMake have forward slashes, hence the
following sets the project name (or workspace name in VC++60 terms) the
complete path which I find very helpful

###projectDir/build/CMakeLists.txt  // build in separate dir from sources

# find current dir
FIND_PATH(BUILD_PATH CMakeLists.txt . ) 

# remove ":" from path
STRING(REGEX REPLACE ":" "_" PROJECT_NAME ${BUILD_PATH})

# convert "/" to "_"
STRING(REGEX REPLACE "/" "_" PROJECT_NAME ${PROJECT_NAME})

# remove build subdir from path
STRING(REGEX REPLACE "_build" "" PROJECT_NAME ${PROJECT_NAME})

# store new assembled name as project name
PROJECT(${PROJECT_NAME})


-----Original Message-----
From: Ian Main [mailto:imain at stemwinder.org] 
Sent: Monday, March 31, 2003 8:24 PM
To: Bitter, Ingmar (NIH/CC/DRD)
Cc: 'cmake at public.kitware.com'
Subject: Re: [Cmake] please provide example of use of STRING(REGEX REPLACE
... )

STRING(REGEX REPLACE "[1-9]$" "pod" podpage ${manpage})

or

STRING(REGEX REPLACE <pattern> <replacement string> <target variable>
<source string>)

so I think you'd want..

STRING(REGEX REPLACE "\\" "_" PROJECT_NAME ${BUILD_PATH})

or something.. it's a very quirky language ;-)


    Ian


On Mon, Mar 31, 2003 at 06:35:04PM -0500, Bitter, Ingmar (NIH/CC/DRD) wrote:
> Hi,
> 
> Can someone please give an example of the use of STRING(REGEX REPLACE ...
)
> 
> I am trying to name my workspace according to the full path, as MSVC++ is
> usually not telling me that anywhere.
> 
> Here is what I would like to do:
> 
> FIND_PATH(BUILD_PATH CMakeLists.txt . ) 
> STRING("\\" REPLACE "_" BUILD_PATH PROJECT_NAME)
> PROJECT(${PROJECT_NAME})
> 
> But my use of the STRING command is wrong.
> How do I use it correctly?
> 
> -Ingmar
> _______________________________________________
> Cmake mailing list
> Cmake at public.kitware.com
> http://public.kitware.com/mailman/listinfo/cmake



More information about the CMake mailing list