Salome HOME
dc4cf6aecd9edf90cd12250ecd0849117674bbbb
[tools/documentation.git] / dev / cmake / source / skeleton.rst
1 .. _skeleton:
2
3 Anatomy of a CMakeLists.txt file
4 ================================
5
6 Root CMakeLists.txt
7 -------------------
8
9 The root CMakeLists.txt should contain the following elements:
10
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:
14
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
18
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).
20
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`::
22
23     FIND_PACKAGE(SalomePython REQUIRED)
24     FIND_PACKAGE(SalomePThread REQUIRED)
25     FIND_PACKAGE(SalomeSWIG REQUIRED)
26
27
28 * Detection of the optional prerequisites (potentially conditioned on some user options - see :ref:`package` for more on this)::
29
30     IF(SALOME_BUILD_DOC)
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)
38
39
40 * Printing a report about the detection status::
41
42     SALOME_PACKAGE_REPORT()
43
44
45 * Common installation directories. Those directories should be used consistently across all SALOME modules::
46
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")
52     ...
53
54
55 * Specific installation directories. Those should start with SALOME_<MODULE>::
56
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")    
59     ...
60
61
62 * Inclusion of the source code directories to be compiled::
63
64     IF(NOT SALOME_LIGHT_ONLY)
65       ADD_SUBDIRECTORY(idl)
66     ENDIF()
67     ADD_SUBDIRECTORY(src)
68
69
70 * Header configuration: creation of the version header files, among other
71 * Configuration export (see dedicated section :ref:`config`)
72
73
74 CMakeLists.txt dedicated to the build of a target
75 -------------------------------------------------
76
77 First, include directories::
78
79   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
87     )
88
89 Then we define the sources list <target>_SOURCES::
90
91   SET(SalomeNS_SOURCES
92     SALOME_NamingService.cxx
93     ServiceUnreachable.cxx
94     NamingService_WaitForServerReadiness.cxx
95   )
96
97 Set the common compilation flags of all targets of the directory::
98
99   ADD_DEFINITIONS(${OMNIORB_DEFINITIONS})
100
101 Ensure dependencies are correctly set, if needed (please refer to :ref:`dependencies`)::
102
103   ADD_DEPENDENCIES(SalomeNS SalomeIDLKernel)
104
105 Then the standard way to compile, link and install a library or executable is::
106
107   ADD_LIBRARY(SalomeNS ${SalomeNS_SOURCES})
108   TARGET_LINK_LIBRARIES(SalomeNS OpUtil)
109   INSTALL(TARGETS SalomeNS DESTINATION ${SALOME_INSTALL_LIBS})
110
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::
112
113   TARGET_LINK_LIBRARIES(xyz ${KERNEL_SalomeNS})   # OK
114   TARGET_LINK_LIBRARIES(xyz SalomeNS)             # Bad!!
115
116 Finally write the specific installation rule for scripts or headers::
117
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})
121
122
123