• Save
CiklumCPPSat: Alexey Podoba "Automatic assembly. Cmake"
Upcoming SlideShare
Loading in...5
×
 

CiklumCPPSat: Alexey Podoba "Automatic assembly. Cmake"

on

  • 1,393 views

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

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

Statistics

Views

Total Views
1,393
Views on SlideShare
1,390
Embed Views
3

Actions

Likes
3
Downloads
0
Comments
0

2 Embeds 3

http://www.slashdocs.com 2
http://www.techgig.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

  • 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 • Makepp• A-A-P • Rake• Maven • Rant• Ant • Phing• NAnt • Makeit• GNU Autotools • Etc
  • What to choose?• Type• Simplicity• Flexibility• Speed• Cross platform• Parallel build• …
  • Type Builder Generators• Scons • Generators• Waf • GNU Autotools• Jam • QMake• Ant• NAnt• RAnt• Rake
  • 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
  • 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
  • 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
  • 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
  • Auto Build System• CMake • qmake• Scons• Waf • Jam, FTJam, Kjam, BJa m• Ant• NAnt
  • CMake/CPack/CTest/CDash
  • 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
  • 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 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
  • 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-performance computing • Embeded • Etc
  • 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”
  • 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
  • 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")
  • 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
  • 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
  • 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
  • What is CMake?• CMakeLists.txt• *.cmake
  • 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)
  • 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 )
  • 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])
  • 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 ...)
  • 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 ()
  • 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( NOT "${ARGV2}" STREQUAL "") SOURCE_GROUP(${ARGV2} FILES ${headers}) endif( NOT "${ARGV2}" STREQUAL "") set(${_HEADERS} ${headers})endmacro()
  • External library & package• find_library• find_package• set (BOOST_ROOT "${EXTERNAL_PATH}/boost_1_47") FIND_PACKAGE(Boost COMPONENTS system REQUIRED)
  • 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
  • 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})
  • 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) MESSAGE("Current revision is ${Project_WC_REVISION}")ENDIF(Subversion_FOUND)
  • 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 ] )
  • CMake Scripts• cmake -E command • Copy file • Remove file • Compare and conditionally copy • time • etc• cmake -P script.cmake
  • Using CMake
  • ./hello/CMakeLists.txtadd_library (Hello hello.cpp)
  • ./demo/CMakeLists.txt include_directories (../Hello) add_executable (helloDemo demo.cpp) target_link_libraries (helloDemo Hello) ADD_DEPENDENCIES(helloDemo Hello)
  • ./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)
  • CTest
  • CTestenable_testing ()ADD_TEST (TestIdentifier ExecutableName [AnyArgsForTest])How to run itCTestmake testRUN_TESTS In IDEoradd_custom()
  • 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})
  • 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})
  • CTest and build
  • 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)
  • CTestMemory checkerSET (PURIFYCOMMAND:FILEPATH ${PATH}/purify.exe)SET (MEMORYCHECK_COMMAND:FILEPATH ${PATH}/valgrind )Test coverageSET (CTEST_COVERAGE_COMMAND “tools/gcov")
  • 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()
  • CDash
  • CDash
  • CDash
  • CDash
  • CDash
  • CDash
  • CPack
  • 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)
  • 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)
  • CPack• Define taragets INSTALL(TARGETS ${APPLICATION} DESTINATION bin) INSTALL(FILES ${APPLICATION} DESTINATION bin)
  • CPack• make install• make package• make package_source
  • CPack Mac
  • CPack Windows
  • Question?Alexey PodobaSenior C++ Developer at Ciklum