It’s an example of b***dy quick attempt to configure CMake-based build of a fairly large library written in C++ programming language. It is GEOS.
Seven. A lucky number. Arnulf‘s nickname. Total number of lines (commands) of CMake script to configure build of GEOS C++ core as a static library using sources form SVN trunk:
Create trunk/CMakeLists.txt file:
project(geos)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
add_subdirectory(src)
Create trunk/src/CMakeLists.txt file:
include_directories(${CMAKE_SOURCE_DIR}/include)
file(GLOB_RECURSE geos_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
add_library(geos STATIC ${geos_SRC})
In fact, only six lines are really required. The third line in file trunk/CMakeLists.txt is optional.
mloskot@dog:~/dev/geos/_svn/trunk$ svn status ? CMakeLists.txt ? src/CMakeLists.txt mloskot@dog:~/dev/geos/_svn/trunk$ mkdir ../build mloskot@dog:~/dev/geos/_svn/trunk$ cd ../build/ mloskot@dog:~/dev/geos/_svn/build$ cmake ../trunk -- The C compiler identification is GNU -- The CXX compiler identification is GNU -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Configuring done -- Generating done -- Build files have been written to: /home/mloskot/dev/geos/_svn/build mloskot@dog:~/dev/geos/_svn/build$ mloskot@dog:~/dev/geos/_svn/build$ make -j5 Scanning dependencies of target geos [ 0%] Building CXX object src/CMakeFiles/geos_lib.dir/operation/valid/RepeatedPointTester.cpp.o ...
and 53 seconds later my Intel Core 2 Duo 2.4GHz box announces:
[100%] Building CXX object src/CMakeFiles/geos.dir/linearref/LengthIndexOfPoint.cpp.o Linking CXX static library libgeos.a [100%] Built target geos
This build configuration is universal and cross platform, thus should work on all platforms supported by CMake.
Simply, you can not afford not use the best cross-platform build system that ever existed :-)
To be honest, if autotools had support MSVC I don’t think I would ever used CMake for any reasonable big project.
For example, in “7″ lines you had only created a static library. Hey! What about dynamic .so/.dll? What about macros for the library? What about installation and packaging, uninstallation?
What if you had been using 3rd part library that has pkg-config…
Wait a second… Accidentally I should use foreach loop to add all flags of this pkg-config library.
What if I use sockets… Let’s check for gethostbyname…
Build system should not be trivial for simple builds, it should be resonable, simple for complex builds…
Let’s check sizeof something? Does not work in cross-compilation builds (issue solved years ago in auto*)
Take a look on this: http://cppcms.svn.sourceforge.net/viewvc/cppcms/framework/branches/refactoring/CMakeLists.txt?revision=977&view=markup
How verbouse it is! Simple tasks require lots of headache!
CMake is reasonable working build system but it is so far from being called best…
Pingback: GIS-Lab Blog» ????? ????? » ??????? ??????