[CMake] Please critique my "hello world" CMakeLists.txt and Config.cmake

Alexander Neundorf a.neundorf-work at gmx.net
Sun Feb 24 06:28:48 EST 2013


On Sunday 24 February 2013, J Decker wrote:
> On Sun, Feb 24, 2013 at 2:23 AM, Ansis Māliņš <ansis.malins at gmail.com>wrote:
> > # You don't need the .in file.
> > 
> > CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
> > 
> > PROJECT(hello)
> > 
> > set (hello_VERSION_MAJOR 1)
> > set (hello_VERSION_MINOR 1)
> > 
> > ENABLE_TESTING()
> > 
> > ADD_LIBRARY(hello hello.cpp)
> > 
> > # This works just the same. Unless I'm missing something.
> > SET(hello_INCLUDE_DIRS
> > 
> > ${CMAKE_INSTALL_PREFIX}/include/hello-${hello_VERSION_MAJOR}.${hello_VERS
> > ION_MINOR}) SET(hello_LIBRARIES
> > 
> > ${CMAKE_INSTALL_PREFIX}/lib/hello-${hello_VERSION_MAJOR}.${hello_VERSION_
> > MINOR}/libhello.a)
> 
> s/lib/${CMAKE_STATIC_LIBRARY_PREFIX}/
> s/.a/${CMAKE_STATIC_LIBRARY_SUFFIX}/
> 
> also available ${CMAKE_EXECUTABLE_SUFFIX}  would be blank in your case, but
> not always.
> 
> ${CMAKE_SHARED_LIBRARY_PREFX}
> ${CMAKE_SHARED_LIBRARY_SUFFX}
> 
> PREFIX will be blank for windows platforms and SUFFIX appropriate .lib or
> .dll (.a, .so )

Please use the target-export feature, this handles all that for you, including 
dependent libraries, debug and optimized versions, etc.
http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets

Alex


More information about the CMake mailing list