[Cmake] please provide example of use of STRING(REGEX REPLACE ... )
Andy Cedilnik
andy.cedilnik at kitware.com
Tue Apr 1 14:01:40 EST 2003
Hi Ingmar,
There are some variables that make this much easier.
On Tue, 2003-04-01 at 13:44, Bitter, Ingmar (NIH/CC/DRD) wrote:
> 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 . )
This is CMAKE_CURRENT_SOURCE_DIR. There is also
CMAKE_CURRENT_BINARY_DIR.
> # 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})
What is wrong with cmake variable PROJECT_NAME?
Why would you want to store project name to be path to source?
Andy
More information about the CMake
mailing list