]> git.uio.no Git - u/mrichter/AliRoot.git/blob - cmake/GenParFile.cmake
Merge branch 'feature-parfiles'
[u/mrichter/AliRoot.git] / cmake / GenParFile.cmake
1 # This CMake function generates a target that, in turn, will generate a PARfile for the given
2 # library.
3 #
4 # Usage: in the CMakeLists.txt, for a given library, add the following:
5 #   add_target_parfile(${MODULE} "${SRCS}" "${HDRS}" "${MODULE}LinkDef.h" "${LIBDEPS}" ["extrainclude1 extrainclude2..."])
6 #
7 # Arguments are, in order:
8 #  - library's name: for libBLAHBLAH it will generate a target BLAHBLAH.par
9 #  - source files: classes to include in the PARfile, they must be exactly the ones used to generate
10 #    the library
11 #  - headers
12 #  - the LinkDef used by ROOT
13 #  - dependent libraries: used to generate the rootmap
14 #  - extra include paths (optional): passed during compilation
15 #
16 # To generate a parfile, if enabled in its CMakeLists.txt, go to the build directory and run:
17 #   make BLAHBLAH.par
18
19 function(add_target_parfile PARMODULE PARSOURCES PARHEADERS PARLINKDEF PARLIBDEPS)
20
21   # Libraries: result is a space-separated string
22   foreach(_THISLIB ${PARLIBDEPS})
23     set(_PARLIBDEPS "${_PARLIBDEPS} lib${_THISLIB}")
24   endforeach()
25   string(STRIP "${_PARLIBDEPS}" PARLIBDEPS)
26
27   # Export variables: used in configure_file()
28   set(PARMODULE "${PARMODULE}")
29   string(REPLACE ";" " " PARSOURCES_FLAT "${PARSOURCES}")
30
31   #message(STATUS "[add_target_parfile] Library (space-separated): ${PARMODULE}")
32   #message(STATUS "[add_target_parfile] Sources (list): ${PARSOURCES}")
33   #message(STATUS "[add_target_parfile] Dependencies (space-separated): ${PARLIBDEPS}")
34
35   if(NOT "${ARGV5}" STREQUAL "")
36     # Optional: extra includes, space-separated
37     set(PAREXTRAINCLUDES "${ARGV5}")
38     #message(STATUS "[add_target_parfile] Extra Includes (space-separated): ${PAREXTRAINCLUDES}")
39   endif()
40
41   # PARfile output directory (the one we will tar)
42   set(PARDIR ${CMAKE_CURRENT_BINARY_DIR}/PARfiles/${PARMODULE})
43
44   # Create base directory for this module's PARfile: this is the directory we will tar
45   # This works as "mkdir -p" (i.e. it's recursive and creates parents)
46   file(MAKE_DIRECTORY ${PARDIR}/PROOF-INF)
47
48   # Create Makefile
49   configure_file(
50       ${PROJECT_SOURCE_DIR}/cmake/PARfiles/Makefile.in
51       ${PARDIR}/Makefile
52       @ONLY
53   )
54
55   # Create BUILD.sh
56   configure_file(
57       ${PROJECT_SOURCE_DIR}/cmake/PARfiles/BUILD.sh.in
58       ${PARDIR}/PROOF-INF/BUILD.sh
59       @ONLY
60   )
61   execute_process(COMMAND chmod a+x ${PARDIR}/PROOF-INF/BUILD.sh)
62
63   # Create SETUP.C
64   configure_file(
65       ${PROJECT_SOURCE_DIR}/cmake/PARfiles/SETUP.C.in
66       ${PARDIR}/PROOF-INF/SETUP.C
67       @ONLY
68   )
69
70   # Target for creating PARfile (would stop after the first failed COMMAND)
71   add_custom_target("${PARMODULE}.par"
72     COMMAND rsync --relative ${PARSOURCES} ${PARHEADERS} ${PARLINKDEF} ${PARDIR}/
73     COMMAND tar -C ${PARDIR}/.. -czf ${PARDIR}/../${PARMODULE}.par ${PARMODULE}/
74     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
75   )
76
77   # Install target
78   install(FILES ${PARDIR}/../${PARMODULE}.par DESTINATION PARfiles OPTIONAL)
79
80   # Add this module to the list of generated PARfiles
81   list(APPEND ALIPARFILES ${PARMODULE})
82   set(ALIPARFILES ${ALIPARFILES} CACHE INTERNAL "ALIPARFILES")
83
84 endfunction()