[CMake] Please critique my "hello world" CMakeLists.txt and Config.cmake
Alexander Neundorf
a.neundorf-work at gmx.net
Sun Feb 24 05:20:36 EST 2013
Hi Chris,
On Sunday 24 February 2013, Chris Stankevitz wrote:
> Hello,
>
> Would you please critique my CMakeLists.txt and helloConfig.cmake.in
> files? I am particularly interested in comments that will help me fix
> these problems:
>
> - In helloConfig.cmake.in, I assume static libraries will be built
> (".a"). I imaging a better approach would make no assumptions about
> this.
>
> - In helloConfig.cmake.in, I assume ${PREFIX} will expand to the
> installed prefix, but it does not.
Yes.
You should
* "export" the target (use the EXPORT option in install(TARGETS))
* the install this "export", using install(EXPORT ...), this will install a
cmake script file
* include() this export-file in the Config.cmake file
* use configure_package_config_file() instead of the plain configure_file() to
configure the file. This will help with absolute and relative paths etc.
You may want to have a look at an example for this, e.g. here:
http://quickgit.kde.org/?p=kdelibs.git&a=tree&h=734d0c1887c89dd8260e67f912f026723226ff88&hb=e3f5b30fd287e83f32c2cc756fc3ea4a17358ef7&f=tier1%2Fitemmodels
(you can ignore ecm_setup_version() )
> - I type the same expression many times:
> "hello-${hello_VERSION_MAJOR}.${hello_VERSION_MINOR}". I imagine the
> better approach would derive this expression from some built-in cmake
> variables or from a variable I create.
It's ok.
Of course you can do
set(helloSubDir "hello-${hello_VERSION_MAJOR}.${hello_VERSION_MINOR}")
and then use that.
> - INSTALL is looking for helloConfig.cmake in the source directory but
> it is in the build directory.
install( ... ${CMAKE_CURRENT_BINARY_DIR}/hellConfig.cmake .... )
and maybe also use the full path in configure_file():
configure_file(helloConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/helloConfig.cmake)
Alex
More information about the CMake
mailing list