3 Anatomy of a CMakeLists.txt file
4 ================================
9 The root CMakeLists.txt should contain the following elements:
11 * Versioning: definition of the major, minor and patch version number. This is the sole place where those numbers should be defined.
12 * Platform setup: specific flags, detection of the architecture, ... This it typically done by including the SalomeSetupPlatform macro.
13 * User option definitions: in SALOME the following flags should be found in all modules:
15 * SALOME_USE_MPI: wether Salome should be built using MPI containers
16 * SALOME_BUILD_TESTS: wether the unit tests should be built
17 * SALOME_BUILD_DOC: wether the documentation for the current module should be generated and installed
19 Other flags specific to the module might be added, and should then start with *SALOME_XYZ_* where <XYZ> is the module's name (MED for example).
21 * Detection of the required prerequisites for the module. All prerequisites in SALOME are detected through a call to FIND_PACKAGE(SalomeXYZ ...). See section :ref:`package`::
23 FIND_PACKAGE(SalomePython REQUIRED)
24 FIND_PACKAGE(SalomePThread REQUIRED)
25 FIND_PACKAGE(SalomeSWIG REQUIRED)
28 * Detection of the optional prerequisites (potentially conditioned on some user options - see :ref:`package` for more on this)::
31 FIND_PACKAGE(SalomeDoxygen)
32 FIND_PACKAGE(SalomeGraphviz)
33 FIND_PACKAGE(SalomeSphinx)
34 SALOME_UPDATE_FLAG_AND_LOG_PACKAGE(Doxygen SALOME_BUILD_DOC)
35 SALOME_UPDATE_FLAG_AND_LOG_PACKAGE(Graphviz SALOME_BUILD_DOC)
36 SALOME_UPDATE_FLAG_AND_LOG_PACKAGE(Sphinx SALOME_BUILD_DOC)
37 ENDIF(SALOME_BUILD_DOC)
40 * Printing a report about the detection status::
42 SALOME_PACKAGE_REPORT()
45 * Common installation directories. Those directories should be used consistently across all SALOME modules::
47 SET(SALOME_INSTALL_BINS bin/salome CACHE PATH "Install path: SALOME binaries")
48 SET(SALOME_INSTALL_LIBS lib/salome CACHE PATH "Install path: SALOME libs")
49 SET(SALOME_INSTALL_IDLS idl/salome CACHE PATH "Install path: SALOME IDL files")
50 SET(SALOME_INSTALL_HEADERS include/salome CACHE PATH "Install path: SALOME headers")
51 SET(SALOME_INSTALL_SCRIPT_SCRIPTS ${SALOME_INSTALL_BINS} CACHE PATH "Install path: SALOME scripts")
55 * Specific installation directories. Those should start with SALOME_<MODULE>::
57 SET(SALOME_GUI_INSTALL_PARAVIEW_LIBS lib/paraview CACHE PATH "Install path: SALOME GUI ParaView libraries")
58 SET(SALOME_GUI_INSTALL_RES_DATA "${SALOME_INSTALL_RES}/gui" CACHE PATH "Install path: SALOME GUI specific data")
62 * Inclusion of the source code directories to be compiled::
64 IF(NOT SALOME_LIGHT_ONLY)
70 * Header configuration: creation of the version header files, among other
71 * Configuration export (see dedicated section :ref:`config`)
74 CMakeLists.txt dedicated to the build of a target
75 -------------------------------------------------
77 First, include directories::
80 ${OMNIORB_INCLUDE_DIR}
81 ${PTHREAD_INCLUDE_DIRS}
82 ${PROJECT_BINARY_DIR}/salome_adm
83 ${CMAKE_CURRENT_SOURCE_DIR}/../Basics
84 ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMELocalTrace
85 ${CMAKE_CURRENT_SOURCE_DIR}/../Utils
86 ${PROJECT_BINARY_DIR}/idl
89 Then we define the sources list <target>_SOURCES::
92 SALOME_NamingService.cxx
93 ServiceUnreachable.cxx
94 NamingService_WaitForServerReadiness.cxx
97 Set the common compilation flags of all targets of the directory::
99 ADD_DEFINITIONS(${OMNIORB_DEFINITIONS})
101 Ensure dependencies are correctly set, if needed (please refer to :ref:`dependencies`)::
103 ADD_DEPENDENCIES(SalomeNS SalomeIDLKernel)
105 Then the standard way to compile, link and install a library or executable is::
107 ADD_LIBRARY(SalomeNS ${SalomeNS_SOURCES})
108 TARGET_LINK_LIBRARIES(SalomeNS OpUtil)
109 INSTALL(TARGETS SalomeNS DESTINATION ${SALOME_INSTALL_LIBS})
111 Note that there is no SHARED reference, no SET_TARGET_PROPERTIES( .. COMPILE_FLAGS ..). If you need to link against a KERNEL or other SALOME target, use the variable name of the target, not the target directly::
113 TARGET_LINK_LIBRARIES(xyz ${KERNEL_SalomeNS}) # OK
114 TARGET_LINK_LIBRARIES(xyz SalomeNS) # Bad!!
116 Finally write the specific installation rule for scripts or headers::
118 SALOME_INSTALL_SCRIPTS(SALOME_NamingServicePy.py ${SALOME_INSTALL_SCRIPT_SCRIPTS})
119 FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
120 INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS})