Auto Build SystemAlexey PodobaSenior C++ Developer at Ciklum
Auto Build System•   Preview•   CMake•   CTest•   CDash•   CPack
Auto Build System• CMake             • qmake• Scons             • Jam, FTJam, Kjam, BJa• Waf                 m• Fbuild    ...
What to choose?•   Type•   Simplicity•   Flexibility•   Speed•   Cross platform•   Parallel build•   …
Type            Builder          Generators•   Scons             • Generators•   Waf               • GNU Autotools•   Jam ...
Simply && Flexibility• Own syntax                   • XML  •   CMake                      • Maven  •   GNU Autotools      ...
Linux && SpeedBUILD SYSTEM    FULL BUILD INCREMENTAL   INCREMENTAL LIBGNU Make        2m 21s    0m 2.4s        0m 0.0sJam ...
Windows && SpeedBUILD SYSTEM                                       FULL BUILD   INCREMENTAL   INCREMENTAL LIBMicrosoft Vis...
CMake vs AutotoolsTask        CMake    Autotools                     Automake 00:41Configure   0:08                     Co...
Auto Build System• CMake             • qmake• Scons• Waf               • Jam, FTJam, Kjam, BJa                      m• Ant...
CMake/CPack/CTest/CDash
Why CMake?•   Process•   Fast•   Easy to implement•   Easy to use•   Easy to use across platform•   Easy to have multi con...
Process                   ...     Release              Implementation               …         Testing
Process                 …     CPack                 CMake             …       CDash/CTest
Fast• Implement on C++• http://blog.qgis.org/?q=node/16 “I was quite surprised with  the speed of building Quantum GIS cod...
Easy to implementCMakeLists.txtcmake_minimum_required (VERSION 2.8)project (HELLO)add_executable (hello main.cpp)
Easy to use• Just call “cmake ./” in project directory with CMakeLists.txt• And than “make”• Or
Easy to use• Or
Easy use across platform• One simple language for all platforms  •   Windows  •   Linux  •   Unix  •   Mac  •   High-perfo...
Easy use across platform•   Borland Makefiles     •   Visual Studio 6-10•   MSYS Makefiles        •   Watcom WMake•   MinG...
Easy to use multi configuration• Build Configuration  •   Debug  •   Release  •   RelWithDebInfo  •   MinSizeRel  •   etc•...
CMake Init Fileset (CPACK_PACKAGE_VERSION_MAJOR 5)set (CPACK_PACKAGE_VERSION_MINOR 7)set (CPACK_PACKAGE_VERSION_PATCH 1)se...
Easy to have clean code• Out-of-source build trees leave source cleanJust call cmake command with parameter –B“../build”Sa...
Easy to convert• am2cmake  http://websvn.kde.org/trunk/KDE/kdesdk/cmake/scripts/am2  cmake?view=markup• qmake converter  h...
Everyone Uses It• Avidemux               Registration Toolkit   • PvPGN• Bullet Physics     •   KDE                    • Q...
What is CMake?• CMakeLists.txt• *.cmake
CMake• Built-in rules for common targets  •   Executable  •   Shared Libraries/ DLLs  •   Static libraries ( archives)  • ...
CMake• Custom targets  • Generated Documentation  • Generated sources and headers  add_custom_target (Docs ALL COMMAND  ${...
CMake Features• Custom command  add_custom_command( OUTPUT Foo.trx COMMAND perl      ${SOURCE_DIR}/combine.pl ${trofiles} ...
CMake• include_directories ([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)• link_directories(directory1 directory2 ...)• target_li...
CMake• foreach        foreach (val ${FILES})        ...        endforeach()• if else      if (MSVC)        add_definitions...
CMake Macros• Macrosmacro(MyMacro ${var})       …endmacro()• Functionsfunction(myfunc ${var})       ….endfunction(myfunc)
Macromacro(list_header_directory _PATH _HEADERS)  include_directories("${_PATH}")  file (GLOB headers "${_PATH}/*.h")  if(...
External library & package• find_library• find_package• set (BOOST_ROOT "${EXTERNAL_PATH}/boost_1_47")  FIND_PACKAGE(Boost...
Find package• FindMPI           •   FindALSA          •   FindSubversion• FindwxWidgets     •   FindProtobuf      •   Find...
CMake & Boostset (BOOST_COMPONENTS thread filesystem)set (Boost_USE_STATIC_LIBS ON)set (Boost_USE_MULTITHREADED ON)find_pa...
CMake & Qtfind_package (Qt4 REQUIRED)include (${QT_USE_FILE})...target_link_libraries (${PROJECT} ${QT_LIBRARIES})
CMake & SubversionFIND_PACKAGE(Subversion)IF(Subversion_FOUND)       Subversion_WC_INFO(${CMAKE_HOME_DIRECTORY}Project)   ...
CMake & CppCheckFIND_PACKAGE(cppcheck)add_library (MyTarget source.cpp)add_to_cppcheck(MyTarget PRE_BUILD FAILED )add_to_c...
CMake Scripts• cmake -E command  •   Copy file  •   Remove file  •   Compare and conditionally copy  •   time  •   etc• cm...
Using CMake
./hello/CMakeLists.txtadd_library (Hello hello.cpp)
./demo/CMakeLists.txt include_directories (../Hello) add_executable (helloDemo demo.cpp) target_link_libraries (helloDemo ...
./CMakeLists.txtcmake_minimum_required (VERSION 2.6)project (HELLO)if(WIN32)   add_definitions (-DUNICODE -D_UNICODE)   se...
CTest
CTestenable_testing ()ADD_TEST (TestIdentifier ExecutableName [AnyArgsForTest])How to run itCTestmake testRUN_TESTS In IDE...
CTest & Boost Testset (TESTS_SOURCES ../tests/test.cpp)find_package (Boost COMPONENTS unit_test_frameworkREQUIRED)include_...
CTest & GTestset (TESTS_SOURCES ../tests/test.cpp)find_package (GTest REQUIRED)include_directories(${GTest_INCLUDE_DIRS})s...
CTest and build
CTestset (PROJECT_NAME "MyProject")set (CTEST_DROP_METHOD "http")set (CTEST_DROP_SITE "my.cdash.org")set (CTEST_DROP_LOCAT...
CTestMemory checkerSET (PURIFYCOMMAND:FILEPATH ${PATH}/purify.exe)SET (MEMORYCHECK_COMMAND:FILEPATH ${PATH}/valgrind )Test...
CTestctest_empty_binary_directory (${CTEST_BINARY_DIRECTORY})ctest_start (Experimental)ctest_update (SOURCE "${CTEST_SOURC...
CDash
CDash
CDash
CDash
CDash
CDash
CPack
CPack•   TGZ                       •   TZ•   STGZ                      •   ZIP•   TBZ2                      •   NSIS•   Dr...
CPack• Setting variables       set (CPACK_PACKAGE_VERSION_MAJOR 5)       set (CPACK_PACKAGE_VERSION_MINOR 7)       set (CP...
CPack• Define taragets       INSTALL(TARGETS ${APPLICATION} DESTINATION bin)       INSTALL(FILES ${APPLICATION} DESTINATIO...
CPack• make install• make package• make package_source
CPack Mac
CPack Windows
Question?Alexey PodobaSenior C++ Developer at Ciklum
Upcoming SlideShare
Loading in...5
×

CiklumCPPSat: Alexey Podoba "Automatic assembly. Cmake"

1,204

Published on

Presentation of Alexey Podoba from CPP Saturday in Dnepropetrovsk, November, 19, 2011.

Published in: Education, Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,204
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "CiklumCPPSat: Alexey Podoba "Automatic assembly. Cmake""

  1. 1. Auto Build SystemAlexey PodobaSenior C++ Developer at Ciklum
  2. 2. Auto Build System• Preview• CMake• CTest• CDash• CPack
  3. 3. Auto Build System• CMake • qmake• Scons • Jam, FTJam, Kjam, BJa• Waf m• Fbuild • Makepp• A-A-P • Rake• Maven • Rant• Ant • Phing• NAnt • Makeit• GNU Autotools • Etc
  4. 4. What to choose?• Type• Simplicity• Flexibility• Speed• Cross platform• Parallel build• …
  5. 5. Type Builder Generators• Scons • Generators• Waf • GNU Autotools• Jam • QMake• Ant• NAnt• RAnt• Rake
  6. 6. Simply && Flexibility• Own syntax • XML • CMake • Maven • GNU Autotools • Ant • qmake • NAnt • Jam, FTJam, Kjam, BJam • Perl• Python • Makepp • Scons • Ruby • Waf • Rake • Fbuild • Rant • A-A-P
  7. 7. Linux && SpeedBUILD SYSTEM FULL BUILD INCREMENTAL INCREMENTAL LIBGNU Make 2m 21s 0m 2.4s 0m 0.0sJam 2m 42s 0m 1.6s 0m 0.1sBoostBuild v2 3m 28s 0m 46s 0m 1.6sScons 5m 08s 1m 06s 0m 10.4sAnt 2m 8s 0m 21s 0m 1.7sRant 2m 32s 0m 10s 0m 4.9s
  8. 8. Windows && SpeedBUILD SYSTEM FULL BUILD INCREMENTAL INCREMENTAL LIBMicrosoft Visual Studio 2003 7m 28s 0m 54s 0m 4sMicrosoft Visual Studio 2003 + FastSolutionBuild 7m 26s 0m 1s 0m 1sMicrosoft Visual Studio 2005 6m 46s 0m 20s 0m 3.5sVCBuild 6m 56s 0m 18s 0m 0.5sJam 6m 52s 0m 3.1s 0m 0.3sBoostBuild v2 12m 03s 0m 55s 0m 2sScons 7m 52s 0m 57s 0m 7sAnt 3m 42s 0m 33s 0m 1.9sNant 3m 24s 0m 35s 0m 1.4sRant 5m 47s 0m 25s 0m 14s
  9. 9. CMake vs AutotoolsTask CMake Autotools Automake 00:41Configure 0:08 Configure 00:20Make 12:15 21:16Install 0:20 0:36Total 12:43 22:43
  10. 10. Auto Build System• CMake • qmake• Scons• Waf • Jam, FTJam, Kjam, BJa m• Ant• NAnt
  11. 11. CMake/CPack/CTest/CDash
  12. 12. Why CMake?• Process• Fast• Easy to implement• Easy to use• Easy to use across platform• Easy to have multi configuration• Easy to have clean code• Easy to convert any project to CMake• Everyone Uses It• Etc
  13. 13. Process ... Release Implementation … Testing
  14. 14. Process … CPack CMake … CDash/CTest
  15. 15. Fast• Implement on C++• http://blog.qgis.org/?q=node/16 “I was quite surprised with the speed of building Quantum GIS codebase in comparison to Autotools” Task CMake Autotools Automake 00:41 Configure 0:08 Configure 00:20 Make 12:15 21:16 Install 0:20 0:36 Total 12:43 22:43
  16. 16. Easy to implementCMakeLists.txtcmake_minimum_required (VERSION 2.8)project (HELLO)add_executable (hello main.cpp)
  17. 17. Easy to use• Just call “cmake ./” in project directory with CMakeLists.txt• And than “make”• Or
  18. 18. Easy to use• Or
  19. 19. Easy use across platform• One simple language for all platforms • Windows • Linux • Unix • Mac • High-performance computing • Embeded • Etc
  20. 20. Easy use across platform• Borland Makefiles • Visual Studio 6-10• MSYS Makefiles • Watcom WMake• MinGW Makefiles • CodeBlocks• NMake Makefiles • Eclipse CDT4• NMake Makefiles JOM • KDevelop3• Unix Makefiles • XCodeSample:cmake –G”CodeBlocks”
  21. 21. Easy to use multi configuration• Build Configuration • Debug • Release • RelWithDebInfo • MinSizeRel • etc• CMake build parameteres -DVERSION=1.1.1• CMake build init file with sated variables cmake -Cinitfile.cmake
  22. 22. CMake Init Fileset (CPACK_PACKAGE_VERSION_MAJOR 5)set (CPACK_PACKAGE_VERSION_MINOR 7)set (CPACK_PACKAGE_VERSION_PATCH 1)set (CPACK_RESOURCE_FILE_LICENSE Copyright.txt")set (CPACK_RESOURCE_FILE_README "Description.txt")set (CPACK_RESOURCE_FILE_WELCOME "Welcome.txt")
  23. 23. Easy to have clean code• Out-of-source build trees leave source cleanJust call cmake command with parameter –B“../build”Sample:cmake “./src” –B”build” –G”NMake Makefiles” –demover.cmake-DEXECUTABLE_OUTPUT_PATH /tmp/bin_result
  24. 24. Easy to convert• am2cmake http://websvn.kde.org/trunk/KDE/kdesdk/cmake/scripts/am2 cmake?view=markup• qmake converter http://www.vtk.org/Wiki/CMake:ConvertFromQmake• vcproj2cmake.rb http://sourceforge.net/projects/vcproj2cmake/files/• folders4cmake http://sourceforge.net/projects/folders4cmake/• etc
  25. 25. Everyone Uses It• Avidemux Registration Toolkit • PvPGN• Bullet Physics • KDE • Quantum GIS Library • Choqok • qutIM• Chicken • Kicad • ReactOS• Clementine • LeechCraft • Scribus• Cuneiform • LLVM • Slicer• DevIL • LMMS • Stellarium• Drishti • MuseScore • Supertux• EiskaltDC++ • MySQL • The Visualization• FreeCAD • OGRE Toolkit• GDCM • OpenSceneGraph • OpenCV• IGSTK • ParaView • Boost• Insight • PCSX2 Segmentation and • Pichi
  26. 26. What is CMake?• CMakeLists.txt• *.cmake
  27. 27. CMake• Built-in rules for common targets • Executable • Shared Libraries/ DLLs • Static libraries ( archives) • OS X Frameworks and App Bundles add_executable(<name> [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] source1 source2 ... sourceN) add_library(<name> [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 source2 ... sourceN)
  28. 28. CMake• Custom targets • Generated Documentation • Generated sources and headers add_custom_target (Docs ALL COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile SOURCES ${PROJECT_BINARY_DIR}/Doxyfile) add_custom_target ( generateheader ALL DEPENDS results/header.h COMMAND blablabla )
  29. 29. CMake Features• Custom command add_custom_command( OUTPUT Foo.trx COMMAND perl ${SOURCE_DIR}/combine.pl ${trofiles} -o Foo.trx DEPENDS ${trofiles} ) add_custom_target(do_trofiles DEPENDS Foo.trx) add_custom_command( TARGET target PRE_BUILD | PRE_LINK | POST_BUILD COMMAND command [ARGS [args...]] [COMMENT comment])
  30. 30. CMake• include_directories ([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)• link_directories(directory1 directory2 ...)• target_link_libraries (<target> [lib1 [lib2 [...]]] [[debug|optimized|general] <lib>] ...)• add_dependencies(target-name depend-target1 depend-target2 ...)
  31. 31. CMake• foreach foreach (val ${FILES}) ... endforeach()• if else if (MSVC) add_definitions (/W3) elseif (CMAKE_COMPILER_IS_GNUCXX) add_definitions (-Wall -pedantic) else () message ("Unknown compiler") endif ()
  32. 32. CMake Macros• Macrosmacro(MyMacro ${var}) …endmacro()• Functionsfunction(myfunc ${var}) ….endfunction(myfunc)
  33. 33. Macromacro(list_header_directory _PATH _HEADERS) include_directories("${_PATH}") file (GLOB headers "${_PATH}/*.h") if( NOT "${ARGV2}" STREQUAL "") SOURCE_GROUP(${ARGV2} FILES ${headers}) endif( NOT "${ARGV2}" STREQUAL "") set(${_HEADERS} ${headers})endmacro()
  34. 34. External library & package• find_library• find_package• set (BOOST_ROOT "${EXTERNAL_PATH}/boost_1_47") FIND_PACKAGE(Boost COMPONENTS system REQUIRED)
  35. 35. Find package• FindMPI • FindALSA • FindSubversion• FindwxWidgets • FindProtobuf • FindCoin3D• FindLATEX • FindFreeType • FindSWIG• FindImageMagick • FindGDAL • FindJNI• FindBLAS • FindGIFLIB • FindJava• FindLAPACK • FindLua50 • FindOpenSSL• FindBoost • FindLua51 • FindDCMTK• FindGTK2 • FindOpenAL • FindQt4• FindCxxTest • FindOpenThreads • FindRTI• FindDoxygen • FindPhysFS • FindHDF5• FindGnuTLS • FindProducer • FindZLIB• FindFLEX • FindQuickTime • FindCUDA• FindBISON • FindSDL • FindArmadillo• FindGTest • FindosgDB Framework) • FindosgFX• FindBullet • FindosgViewer
  36. 36. CMake & Boostset (BOOST_COMPONENTS thread filesystem)set (Boost_USE_STATIC_LIBS ON)set (Boost_USE_MULTITHREADED ON)find_package (Boost COMPONENTS ${BOOST_COMPONENTS}REQUIRED)include_directories(${Boost_INCLUDE_DIRS})…target_link_libraries (${PROJECT} ${Boost_LIBRARIES})
  37. 37. CMake & Qtfind_package (Qt4 REQUIRED)include (${QT_USE_FILE})...target_link_libraries (${PROJECT} ${QT_LIBRARIES})
  38. 38. CMake & SubversionFIND_PACKAGE(Subversion)IF(Subversion_FOUND) Subversion_WC_INFO(${CMAKE_HOME_DIRECTORY}Project) MESSAGE("Current revision is ${Project_WC_REVISION}")ENDIF(Subversion_FOUND)
  39. 39. CMake & CppCheckFIND_PACKAGE(cppcheck)add_library (MyTarget source.cpp)add_to_cppcheck(MyTarget PRE_BUILD FAILED )add_to_cppcheck( TARGET target PRE_BUILD | PRE_LINK | POST_BUILD | TEST [FAILED | WARNING ] )
  40. 40. CMake Scripts• cmake -E command • Copy file • Remove file • Compare and conditionally copy • time • etc• cmake -P script.cmake
  41. 41. Using CMake
  42. 42. ./hello/CMakeLists.txtadd_library (Hello hello.cpp)
  43. 43. ./demo/CMakeLists.txt include_directories (../Hello) add_executable (helloDemo demo.cpp) target_link_libraries (helloDemo Hello) ADD_DEPENDENCIES(helloDemo Hello)
  44. 44. ./CMakeLists.txtcmake_minimum_required (VERSION 2.6)project (HELLO)if(WIN32) add_definitions (-DUNICODE -D_UNICODE) set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /MTd /Zi /Od ") set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Ob2 /D NDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /MTd /Zi /Od /MP) set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /D NDEBUG /MP")else(WIN32) set(CMAKE_CXX_FLAGS_DEBUG "-g3 -pipe -O0 -DDEBUG -g") set(CMAKE_CXX_FLAGS_RELEASE "-g0 -pipe -O2 -finline-functions -DNDEBUG -s")endif(WIN32)add_subdirectory (Hello Demo)
  45. 45. CTest
  46. 46. CTestenable_testing ()ADD_TEST (TestIdentifier ExecutableName [AnyArgsForTest])How to run itCTestmake testRUN_TESTS In IDEoradd_custom()
  47. 47. CTest & Boost Testset (TESTS_SOURCES ../tests/test.cpp)find_package (Boost COMPONENTS unit_test_frameworkREQUIRED)include_directories(${Boost_INCLUDE_DIRS})set (TEST boost.${PROJECT} )add_executable (${TEST} ${TESTS_SOURCES})target_link_libraries (${TEST} ${PROJECT} ${Boost_LIBRARIES})enable_testing ()add_test (${TEST} ${TEST})
  48. 48. CTest & GTestset (TESTS_SOURCES ../tests/test.cpp)find_package (GTest REQUIRED)include_directories(${GTest_INCLUDE_DIRS})set (TEST gtest. ${PROJECT} )add_executable (${TEST} ${TESTS_SOURCES})target_link_libraries (${TEST} ${PROJECT} ${Gtest_BOTH_LIBRARIES})enable_testing ()add_test (${TEST} ${TEST})
  49. 49. CTest and build
  50. 50. CTestset (PROJECT_NAME "MyProject")set (CTEST_DROP_METHOD "http")set (CTEST_DROP_SITE "my.cdash.org")set (CTEST_DROP_LOCATION "/submit.php?project=VALG1")set (CTEST_DROP_SITE_CDASH TRUE)set (CTEST_SITE "MyPCName")set (CTEST_BUILD_NAME "Windows")set (CTEST_SOURCE_DIRECTORY "${ROOT_DIRECTORY }/src")set (CTEST_BINARY_DIRECTORY ${ROOT_DIRECTORY}/build")set (CTEST_BUILD_CONFIGURATION Debug)
  51. 51. CTestMemory checkerSET (PURIFYCOMMAND:FILEPATH ${PATH}/purify.exe)SET (MEMORYCHECK_COMMAND:FILEPATH ${PATH}/valgrind )Test coverageSET (CTEST_COVERAGE_COMMAND “tools/gcov")
  52. 52. CTestctest_empty_binary_directory (${CTEST_BINARY_DIRECTORY})ctest_start (Experimental)ctest_update (SOURCE "${CTEST_SOURCE_DIRECTORY}")ctest_configure (BUILD "${CTEST_BINARY_DIRECTORY}")ctest_read_custom_files ("${CTEST_BINARY_DIRECTORY}")ctest_build (BUILD "${CTEST_BINARY_DIRECTORY}")ctest_test (BUILD "${CTEST_BINARY_DIRECTORY}")ctest_coverage (BUILD "${CTEST_BINARY_DIRECTORY}")ctest_memcheck (BUILD "${CTEST_BINARY_DIRECTORY}")ctest_submit()
  53. 53. CDash
  54. 54. CDash
  55. 55. CDash
  56. 56. CDash
  57. 57. CDash
  58. 58. CDash
  59. 59. CPack
  60. 60. CPack• TGZ • TZ• STGZ • ZIP• TBZ2 • NSIS• DragNDrop (OSX only) • CygwinBinary (Cygwin only)• PackageMaker (OSX only) • CygwinSource (Cygwin only)• OSXX11 (OSX only) • DEB (UNIX only)• Bundle (OSX only) • RPM (Unix Only)
  61. 61. CPack• Setting variables set (CPACK_PACKAGE_VERSION_MAJOR 5) set (CPACK_PACKAGE_VERSION_MINOR 7) set (CPACK_PACKAGE_VERSION_PATCH 1) set (CPACK_RESOURCE_FILE_LICENSE Copyright.txt") set (CPACK_RESOURCE_FILE_README "Description.txt") set (CPACK_RESOURCE_FILE_WELCOME "Welcome.txt")• Choose generator set(CPACK_GENERATOR TGZ) set(CPACK_GENERATOR NSIS)• Include CPack include(CPack)
  62. 62. CPack• Define taragets INSTALL(TARGETS ${APPLICATION} DESTINATION bin) INSTALL(FILES ${APPLICATION} DESTINATION bin)
  63. 63. CPack• make install• make package• make package_source
  64. 64. CPack Mac
  65. 65. CPack Windows
  66. 66. Question?Alexey PodobaSenior C++ Developer at Ciklum

×