[CMake] rules for writing cmake modules
David Cole
david.cole at kitware.com
Mon Jan 2 16:39:27 EST 2006
Is the root dir the parent or grandparent of the lib dir or the include
dir? I use the following macros in a project where I need to get to the
grandparent dir of a dir that I've already located... Works with CMake
2.2 and up; not sure about 2.0 and earlier. One of these days maybe I'll
post them to the Wiki...
HTH,
David
MACRO(GET_PARENT_DIR input_dir parent_dir_var)
#
# Get absolute name of parent directory.
#
# NOTES:
# NoSuchFile.txt does *not* have to exist for this to work.
# There will be no "." or ".." in ${parent_dir_var}
# If you are not deep enough to have a parent dir, this returns
# the empty string...
#
IF("${input_dir}" MATCHES "/")
GET_FILENAME_COMPONENT(file ${input_dir}/../NoSuchFile.txt ABSOLUTE)
GET_FILENAME_COMPONENT(${parent_dir_var} ${file} PATH)
ELSE("${input_dir}" MATCHES "/")
SET(${parent_dir_var} "")
ENDIF("${input_dir}" MATCHES "/")
ENDMACRO(GET_PARENT_DIR)
MACRO(GET_GRANDPARENT_DIR input_dir grandparent_dir_var)
#
# Get absolute name of grandparent directory.
#
# NOTES:
# NoSuchFile.txt does *not* have to exist for this to work.
# There will be no "." or ".." in ${grandparent_dir_var}
# If you are not deep enough to have a grandparent dir, this
# returns the empty string...
#
IF("${input_dir}" MATCHES "/.+/")
GET_FILENAME_COMPONENT(file ${input_dir}/../../NoSuchFile.txt ABSOLUTE)
GET_FILENAME_COMPONENT(${grandparent_dir_var} ${file} PATH)
ELSE("${input_dir}" MATCHES "/.+/")
SET(${grandparent_dir_var} "")
ENDIF("${input_dir}" MATCHES "/.+/")
ENDMACRO(GET_GRANDPARENT_DIR)
#
# Uncomment the rest of this file to test the macros with current source
# and binary directories as input...
#
#MESSAGE("")
#MESSAGE("CMAKE_CURRENT_SOURCE_DIR")
#MESSAGE("========================")
#GET_PARENT_DIR(${CMAKE_CURRENT_SOURCE_DIR} parent_dir)
#GET_GRANDPARENT_DIR(${CMAKE_CURRENT_SOURCE_DIR} grandparent_dir)
#MESSAGE("dir='${CMAKE_CURRENT_SOURCE_DIR}'")
#MESSAGE("parent_dir='${parent_dir}'")
#MESSAGE("grandparent_dir='${grandparent_dir}'")
#MESSAGE("")
#
#MESSAGE("")
#MESSAGE("CMAKE_CURRENT_BINARY_DIR")
#MESSAGE("========================")
#GET_PARENT_DIR(${CMAKE_CURRENT_BINARY_DIR} parent_dir)
#GET_GRANDPARENT_DIR(${CMAKE_CURRENT_BINARY_DIR} grandparent_dir)
#MESSAGE("dir='${CMAKE_CURRENT_BINARY_DIR}'")
#MESSAGE("parent_dir='${parent_dir}'")
#MESSAGE("grandparent_dir='${grandparent_dir}'")
#MESSAGE("")
Alexander Neundorf wrote:
>>--- Ursprüngliche Nachricht ---
>>Von: "William A. Hoffman" <billlist at nycap.rr.com>
>>An: Alexander Neundorf <a.neundorf-work at gmx.net>, cmake at www.cmake.org
>>Betreff: Re: [CMake] rules for writing cmake modules
>>Datum: Sun, 01 Jan 2006 17:12:31 -0500
>>
>>See the file Modules/readme.txt for the current documentation on
>>modules.
>>
>>
>>
>>
>
>http://public.kitware.com/cgi-bin/viewcvs.cgi/Modules/readme.txt?rev=1.5&root=CMake&view=auto
>
>
>Ok. Can you please add some comments when to use MESSAGE(STATUS |
>FATAL_ERROR ..) in combination with FIND_PACKAGE( QUIET REQUIRED).
>Also could you please explain a bit more when to mark variables as
>ADVANCED and NO_CACHE ?
>Another "problem": I find KDE3_INCLUDE_DIR and KDE3_LIB_DIR but I have no
>idea how I should find KDE3_ROOT ? It just contains some subdirs (bin/,
>lib/, share/ ). Any suggestions ?
>
>Bye
>Alex
>
>
>
>
More information about the CMake
mailing list