Using CMake in GAUDI based Projects Understanding its
Using CMake in GAUDI based Projects Understanding its Feasibility P. Mato/CERN, September 8 th, 2010
Why changing the build system? � CMT (has became) is too complex � CMT is too slow ◦ Too many concepts: macros, sets, tags, patterns, fragments, actions, projects, packages, etc. ◦ Relatively simple build operations require complicated interactions between these concepts ◦ The added complexity has caused CMT to became slower and slower ◦ Big improvements in speed are not in horizon � Missing support for new IDEs ◦ Eclipse, XCode, Visual. Studio 9, etc. Using CMake in GAUDI based Projects - P. Mato/CERN 2
Why CMake? � Generates native build environments. It does not do the build itself ◦ UNIX/Linux->Makefiles ◦ Windows->VSProjects/Workspaces ◦ Apple->Xcode � Open-Source, Cross-Platform, Docs, etc. � Can cope with complex, large build environments � Flexible & Extensible ◦ ◦ ◦ Scripting language (turing-complete) Modules for finding/configuring software Extensible to new platforms and languages Create custom targets/commands Run external programs Using CMake in GAUDI based Projects - P. Mato/CERN 3
Main Questions 1. Can we build GAUDI (and other LHCb projects) with CMake? ◦ What about the build performance? ◦ What about the support for IDEs? ◦ Is anything missing? 2. What would be the impact for end-users? ◦ Can we reproduce the same functionality? ◦ How difficult would be to learn the new system? 3. Can we ‘automatically’ migrate from CMT to Cmake? ◦ Would it be possible the co-existence of both systems in parallel? Using CMake in GAUDI based Projects - P. Mato/CERN 4
Tested with GAUDI, LHCB and REC � Exercised with GAUDI and LHCb projects ◦ Easy to learn and produce high-level macros that build the major products (linker/component libraries, dictionaries, test programs, etc. ) ◦ Product installation can be made identical to CMT ◦ CMake does not runtime environment setting Needed to generate setup file at build/install time � Tested on SLC 5, Mac. OSX and Windows ◦ Verified that generation for Xcode and Eclipse works nicely (not completely finished) ◦ Make it work also for Windows (nmake, vcexpress) � Converted all tests to Ctest ◦ Cpp. Unit, QMtest Using CMake in GAUDI based Projects - P. Mato/CERN 5
A Macro Example #---------------------------------#---GAUDI_LINKER_LIBRARY ( <name> src 1 src 2. . . LIBRARIES lib 1. . . ) #---------------------------------function(GAUDI_LINKER_LIBRARY library sources ) PARSE_ARGUMENTS(ARG "LIBRARIES" "" ${ARGN}) foreach( fp ${ARG_DEFAULT_ARGS}) file(GLOB files src/${fp}) if(files) set( lib_srcs ${lib_srcs} ${files}) else() set( lib_srcs ${lib_srcs} ${fp}) endif() endforeach() add_library( ${library} ${lib_srcs}) set_target_properties(${library} PROPERTIES COMPILE_FLAGS –DGAUDI_ target_link_libraries(${library} ${ARGN}) if(TARGET ${library}Obj 2 doth) add_dependencies( ${library}Obj 2 doth) endif() #----Installation details--------------------install(TARGETS ${library} LIBRARY DESTINATION ${lib}) endfunction() Using CMake in GAUDI based Projects - P. Mato/CERN 6
Performance � Comparison between cmt and cmake ◦ Same code version, some machine ◦ “cmt br make –j 8” vs. “make –s –j 8” ◦ LHCB has ~ 100 packages, REC ~ 50 packages cmt GAUDI (noop) cmake 50 s 7 s GAUDI (full) 613 s 148 s LHCB (noop) 480 s 17 s LHCB (full) 2700 s 356 s REC (noop) 335 s 13 s 1594 s 332 s REC (full) Using CMake in GAUDI based Projects - P. Mato/CERN X ~4 X ~7 X ~5 7
Project Source Structure project. A CMake. List cmake CMake. List pack. A src pack. A hat doc CMake. List pack. B src Using CMake in GAUDI based Projects - P. Mato/CERN pack. B doc 8
Missing Functionality � Package dependencies ◦ CMake [only] takes care of the library dependencies within a project and across projects (export/import) ◦ Invented GAUDI_USE_PACKAGE() to emulate CMT use statement (mainly used to set the –I and –L) � Project dependencies ◦ Invented GAUDI_USE_PROJECT() to emulate CMT project use statement (CMake module path, LD_LIBRARY_PATH, etc. ) � Runtime environment ◦ Generation of setup files possible � Windows DLL libraries exporting all symbols ◦ Generation of. DEF files Using CMake in GAUDI based Projects - P. Mato/CERN 9
Example: Gaudi. Kernel Library GAUDI_USE_PACKAGE(Boost) Sources GAUDI_USE_PACKAGE(Cpp. Unit) name GAUDI_USE_PACKAGE(ROOT) #---Libraries---------------------------------GAUDI_LINKER_LIBRARY(Gaudi. Kernel Lib/*. cpp LIBRARIES ${ROOT_LIBRARIES} ${Boost_LIBRARIES}) #---Executables and Tests---------------------------Dependent GAUDI_EXECUTABLE(genconf Util/genconf. cpp LIBRARIES Gaudi. Kernel) libraries GAUDI_UNIT_TEST(Dir. Search. Path_test. . /tests/src/Dir. Search. Path_test. cpp LIBRARIES Gaudi. Kernel) GAUDI_UNIT_TEST(test_Serialize. STL. . /tests/src/test_Serialize. STL. cpp LIBRARIES Gaudi. Kernel cppunit) #---Dictionaries-------------------------------REFLEX_BUILD_DICTIONARY(Gaudi. Kernel dict/dictionary. h dict/dictionary. xml LIBRARIES Gaudi. Kernel) #--Installation--------------------------------GAUDI_INSTALL_HEADERS(Gaudi. Kernel) GAUDI_INSTALL_PYTHON_MODULES() GAUDI_INSTALL_SCRIPTS()
Example: Event/Track. Event GAUDI_USE_PACKAGE(Kernel/LHCb. Kernel) GAUDI_USE_PACKAGE(GSL) GAUDI_USE_PACKAGE(Boost) INCLUDE(Gaudi. Obj. Desc) #---GOD Headers--------------------------GOD_BUILD_HEADERS(xml/*. xml) #---Libraries---------------------------GAUDI_LINKER_LIBRARY(Track. Event *. cpp LHCb. Kernel Gaudi. Kernel ${ROOT_LIBRARIES} Math. Core Gen. Vector ${GSL_LIBRARIES}) #---GOD Dictionary-------------------------GOD_CUSTOM_DICTIONARY(dict/lcg. Dict. h xml/lcgdict/lcg_selection. xml) GOD_BUILD_DICTIONARY(xml/*. xml) #---Installation--------------------------GAUDI_INSTALL_HEADERS(Event)
Example: LHCB project CMAKE_MINIMUM_REQUIRED(VERSION 2. 4. 6) INCLUDE($ENV{CMAKEGAUDIPROJECT}) #------------------------------GAUDI_PROJECT(LHCB v 31 r 4) Project GAUDI_USE_PROJECT(GAUDI v 21 r 10 p 1) Declaration INCLUDE(Gaudi. Policy) GAUDI_USE_PACKAGE(Boost) Project GAUDI_USE_PACKAGE(ROOT) Dependencies GAUDI_USE_PACKAGE(AIDA) GAUDI_USE_PACKAGE(CLHEP) Common commands and package dependencies GAUDI_GET_PACKAGES(packages) GAUDI_SORT_PACKAGES( packages ${packages}) foreach( package ${packages}) Find dynamically all add_subdirectory(${package}) packages and sort endforeach() them out (not really needed) GAUDI_PROJECT_VERSION_HEADER() GAUDI_BUILD_PROJECT_SETUP() Project build artifacts
Impact for CMT users � In the prototype I have ‘copied’ the same structure of CMT, project organization and main procedures � Some exceptions: ◦ The build is done out-of-source ◦ The installation step is done after the build (make install) � We could take advantage of the new functionality ◦ Managing ‘build’ options and cache them Using CMake in GAUDI based Projects - P. Mato/CERN 13
Migration from CMT � Developed a small python script that is able to ‘translate’ CMT packages to CMake ◦ It makes use of the knowledge CMT has of the package (cmt show uses; cmt show constituents; cmt show <library>_use_linkopts; etc. ) ◦ It works almost 100% for LHCB and REC projects ◦ The results can be committed to SVN and keep them in sync either by hand or re-run the script � Building projects with CMake can produce exactly the same output ◦ In principle is easy to test the build results Using CMake in GAUDI based Projects - P. Mato/CERN 14
Summary 1. Can we build GAUDI (and other LHCb projects) with CMake? YES. It has been quite easy. Scripting has been essential. ◦ What about the build performance? Much better than CMT ◦ What about the support for IDEs? Very good so far ◦ Is anything missing? Few things: dependencies, runtime env. I could easily implement so far the missing functionality 2. What would be the impact for end-users? I think is small. The paradigm is the same ◦ Can we reproduce the same functionality? I think so E. g. user package overriding an existing released one, etc. ◦ How difficult would be to learn the new system? Trivial ‘translation’ of requirements to CMake. Lists files Good native CMake documentation 3. Can we ‘automatically’ migrate from CMT to CMake? YES ◦ Would it be possible the co-existence of both systems in parallel? I think so Using CMake in GAUDI based Projects - P. Mato/CERN 15
- Slides: 15