]> git.uio.no Git - u/mrichter/AliRoot.git/blob - cmake/GenParFile.cmake
PAR: changed macro name and added instructions
[u/mrichter/AliRoot.git] / cmake / GenParFile.cmake
1 # This CMake macro generates a target that, in turn, will generate a PARfile for the given library.
2 #
3 # Usage: in the CMakeLists.txt, for a given library, add the following:
4 #   add_target_parfile(${MODULE} "${SRCS}" "${HDRS}" "${MODULE}LinkDef.h" "${LIBDEPS}")
5 #
6 # Arguments are, in order:
7 #  - library's name: for libBLAHBLAH it will generate a target BLAHBLAH.par
8 #  - source files: classes to include in the PARfile, they must be exactly the ones used to generate
9 #    the library
10 #  - headers
11 #  - the LinkDef used by ROOT
12 #  - dependent libraries: used to generate the rootmap
13 #
14 # To generate a parfile, if enabled in its CMakeLists.txt, go to the build directory and run:
15 #   make BLAHBLAH.par
16
17 macro(add_target_parfile PARMODULE PARSOURCES PARHEADERS PARLINKDEF PARLIBDEPS)
18
19   message(STATUS "PARfile generation: ${PARMODULE}")
20
21   # Libraries
22   foreach(THISLIB ${PARLIBDEPS})
23     set(_PARLIBDEPS "${_PARLIBDEPS} lib${THISLIB}")
24   endforeach()
25   string(STRIP "${_PARLIBDEPS}" PARLIBDEPS)
26
27   # Export variable
28   set(PARMODULE "${PARMODULE}")
29
30   message(STATUS "--> Module: ${PARMODULE}")
31   message(STATUS "--> Sources: ${PARSOURCES}")
32   message(STATUS "--> Deps: ${PARLIBDEPS}")
33
34   foreach(LOOPVAR ${PARSOURCES})
35     message(STATUS "----> ${LOOPVAR}")
36   endforeach()
37
38   # PARfile output directory (the one we will tar)
39   set(PARDIR ${CMAKE_CURRENT_BINARY_DIR}/PARfiles/${PARMODULE})
40
41   # Create base directory for this module's PARfile: this is the directory we will tar
42   # This works as "mkdir -p" (i.e. it's recursive and creates parents)
43   file(MAKE_DIRECTORY ${PARDIR}/PROOF-INF)
44
45   # Create Makefile
46   configure_file(
47       ${PROJECT_SOURCE_DIR}/cmake/PARfiles/Makefile.in
48       ${PARDIR}/Makefile
49       @ONLY
50   )
51
52   # Create BUILD.sh
53   configure_file(
54       ${PROJECT_SOURCE_DIR}/cmake/PARfiles/BUILD.sh.in
55       ${PARDIR}/PROOF-INF/BUILD.sh
56       @ONLY
57   )
58   execute_process(COMMAND chmod a+x ${PARDIR}/PROOF-INF/BUILD.sh)
59
60   # Create SETUP.C
61   configure_file(
62       ${PROJECT_SOURCE_DIR}/cmake/PARfiles/SETUP.C.in
63       ${PARDIR}/PROOF-INF/SETUP.C
64       @ONLY
65   )
66
67   # Target for creating PARfile (would stop after the first failed COMMAND)
68   add_custom_target("${PARMODULE}.par"
69     COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && cp ${PARSOURCES} ${PARHEADERS} ${PARLINKDEF} ${PARDIR}/
70     COMMAND cmake -E copy ${ROOT_ETCDIR}/Makefile.arch ${PARDIR}/
71     COMMAND tar -C ${PARDIR}/.. -czf ${PARDIR}/../${PARMODULE}.par ${PARMODULE}/
72   )
73
74 endmacro()