ClhepToolchain.cmake 7.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#----------------------------------------------------------------------------
# Finally, we can configure the toolchain files for build and install
# directories.
#
# Toolchains:
#  - CMake via use of 'CLHEPConfig.cmake'
#  - pkgconfig via 'clhep.pc'
#
# We only do this for the main CLHEP library to illustrate the basic
# pattern. It can be extended to handle the component packages, but this
# is more complex and would hide the basic concepts. 
#
# Both are fully relocatable, like clhep-config, so can be distributed in
# relocatable binary packages.

# code supplied by Ben Morgan Ben.Morgan@warwick.ac.uk

macro(clhep_toolchain)

#----------------------------------------------------------------------------
# - First we handle the build tree
# This setup allows a build of CLHEP to be used directly *without* installing
# it. This allows several useful development patterns, such as checking an
# application using CLHEP works with different versions/tag sets.
#
# First we set the needed variables
set(CLHEP_VERSION ${VERSION})
set(CLHEP_INCLUDE_DIR ${PROJECT_BINARY_DIR})

# Now we configure the CLHEPConfig and CLHEPConfigVersion file templates,
# outputting to the top level of the build tree.
# This allows users to 'point' CMake to the build by something like
#  
#  # Some CMakeLists.txt
#  ...
#  find_package(CLHEP 2.1.0.1 REQUIRED)
#
# in their buildscript, and then pointing cmake to the build directory via
#
#  cmake -DCLHEP_DIR=/path/to/clhep/build  /path/to/source/of/app
#
configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/CLHEPConfigVersion.cmake.in
  ${PROJECT_BINARY_DIR}/CLHEPConfigVersion.cmake 
  @ONLY
  )

configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/CLHEPConfig.cmake.in
  ${PROJECT_BINARY_DIR}/CLHEPConfig.cmake 
  @ONLY
  )

# We 'export' the main CLHEP library targets from the build tree.
# This file is include()d by CLHEPConfig.cmake
54
55
56
57
58
59
60
61
# First build up list of all modular targets, static and shared
set(CLHEP_libraries_all ${CLHEP_libraries})
foreach(_lib ${CLHEP_libraries})
  list(APPEND CLHEP_libraries_all "${_lib}S")
endforeach()

export(TARGETS CLHEP CLHEPS ${CLHEP_libraries_all}
  NAMESPACE "CLHEP::"
62
63
64
65
  FILE ${PROJECT_BINARY_DIR}/CLHEPLibraryDepends.cmake
  )


66
67
68
69
#-----------------------------------------------------------------------
# Pkg-config setup
 
# Full clhep.pc.
70
71
72
73
74
# In the build tree we hardcode all paths, as we never need to relocate
# a build tree
#
set(CLHEP_PKGCONFIG_PREFIX ${PROJECT_BINARY_DIR})
set(CLHEP_PKGCONFIG_INCLUDEDIR ${CLHEP_INCLUDE_DIR})
Lynn Garren's avatar
Lynn Garren committed
75
set(CLHEP_PKGCONFIG_LIBDIR ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX})
76
77
78
79
80
81

configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/clhep.pc.in
  ${PROJECT_BINARY_DIR}/clhep.pc
  @ONLY
  )

82
83
84
85
# Messy deps for now (can't extract them from lower down the build tree)]
set(CLHEP_PC_Exceptions_REQUIRES "clhep-cast = ${CLHEP_VERSION}, clhep-refcount = ${CLHEP_VERSION}")
set(CLHEP_PC_Geometry_REQUIRES "clhep-vector = ${CLHEP_VERSION}")
set(CLHEP_PC_Matrix_REQUIRES "clhep-random = ${CLHEP_VERSION}, clhep-vector = ${CLHEP_VERSION}")
86
set(CLHEP_PC_RandomObjects_REQUIRES  "clhep-random = ${CLHEP_VERSION}, clhep-matrix = ${CLHEP_VERSION}, clhep-vector = ${CLHEP_VERSION}")
87
88
89
90
91
92
93
94
95
96
97
98

# Now the components
foreach(_lib ${CLHEP_libraries})
  set(CLHEP_PC_COMPONENT  ${_lib})
  string(TOLOWER ${CLHEP_PC_COMPONENT} _pcfilename)
  set(CLHEP_PC_COMPONENT_REQUIRES "${CLHEP_PC_${_lib}_REQUIRES}")

  configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/clhep-component.pc.in
    ${PROJECT_BINARY_DIR}/clhep-${_pcfilename}.pc
    @ONLY
    )
endforeach()
99
100
101
102
103
104
105
106
107
108
109
110
111

#----------------------------------------------------------------------------
# - Now we handle the installation tree
#
# Again we set the needed variable first. Not all have actually changed,
# but we set again for clarity and just to be sure.
set(CLHEP_VERSION ${VERSION})

# The setup of the include dir is slightly different because we want
# to make the install relocatable (Current CLHEP setup *is* relocatable).
# We use a relative path from the directory where the CLHEPConfig.cmake
# file is installed to the actual include dir. 
file(RELATIVE_PATH _relincpath 
Lynn Garren's avatar
Lynn Garren committed
112
  ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/CLHEP-${VERSION}
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  ${CMAKE_INSTALL_PREFIX}/include
  )
set(CLHEP_INCLUDE_DIR "\${_thisdir}/${_relincpath}")

# Now we configure the CLHEPConfig and CLHEPConfigVersion file templates,
# outputting to a directory in the build directory. This is simply a
# placeholder to store them until we install later.  
configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/CLHEPConfigVersion.cmake.in
  ${PROJECT_BINARY_DIR}/InstallTreeFiles/CLHEPConfigVersion.cmake 
  @ONLY
  )

configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/CLHEPConfig.cmake.in
  ${PROJECT_BINARY_DIR}/InstallTreeFiles/CLHEPConfig.cmake 
  @ONLY
  )

130
# Also configure the pkgconfig files, again outputting to a directory under
131
132
133
134
135
136
137
138
# the build directory ready for installation
# Now we use the 'pcfiledir' variable of pkg-config - this tells us the
# directory where clhep.pc is located. Since we know we'll install clhep.pc
# in CMAKE_INSTALL_PREFIX/lib/pkgconfig, we can calculate relative paths
# to the include and lib dirs.... This make the pc file fully relocatable!!
# If you later use GNUInstallDirs.cmake, this would need more work to
# ensure accurate calculation of the relative path.
set(CLHEP_PKGCONFIG_PREFIX "\${pcfiledir}/../..")
Lynn Garren's avatar
Lynn Garren committed
139
set(CLHEP_PKGCONFIG_LIBDIR "\${prefix}/lib${LIB_SUFFIX}")
140
141
142
143
144
145
146
set(CLHEP_PKGCONFIG_INCLUDEDIR "\${prefix}/include")

configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/clhep.pc.in
  ${PROJECT_BINARY_DIR}/InstallTreeFiles/clhep.pc
  @ONLY
  )

147
148
149
150
151
152
153
154
155
156
157
158
# Now the components
foreach(_lib ${CLHEP_libraries})
  set(CLHEP_PC_COMPONENT  ${_lib})
  string(TOLOWER ${CLHEP_PC_COMPONENT} _pcfilename)
  set(CLHEP_PC_COMPONENT_REQUIRES "${CLHEP_PC_${_lib}_REQUIRES}")

  configure_file(${PROJECT_SOURCE_DIR}/cmake/Templates/clhep-component.pc.in
    ${PROJECT_BINARY_DIR}/InstallTreeFiles/clhep-${_pcfilename}.pc
    @ONLY
    )
endforeach()

159
160
161
162
163
164
165
166
167
168
# - Install the config files, and 'install export' the library depends file
#   The choice of 'lib/CLHEP-<VERSION>' is based on the recommendations
#   in the CMake documentation for find_package on UNIX so that 
#   CMake can potentially find the Config file automatically. We don't
#   consider the Apple case because we don't (yet) build CLHEP as a Framework.
#   The Windows case can be easily added later.
#   The location can of course be modified if you wish.
install(FILES
  ${PROJECT_BINARY_DIR}/InstallTreeFiles/CLHEPConfigVersion.cmake 
  ${PROJECT_BINARY_DIR}/InstallTreeFiles/CLHEPConfig.cmake 
Lynn Garren's avatar
Lynn Garren committed
169
  DESTINATION lib${LIB_SUFFIX}/CLHEP-${VERSION}
170
171
  )

172
173
174
install(EXPORT CLHEPLibraryDepends 
        NAMESPACE "CLHEP::"
        DESTINATION lib${LIB_SUFFIX}/CLHEP-${VERSION})
175

Lynn Garren's avatar
Lynn Garren committed
176
# Install the pkg-config file. The choice of 'lib${LIB_SUFFIX}/pkgconfig' for the 
177
178
179
# installation seems fairly standard.
install(FILES
  ${PROJECT_BINARY_DIR}/InstallTreeFiles/clhep.pc
Lynn Garren's avatar
Lynn Garren committed
180
  DESTINATION lib${LIB_SUFFIX}/pkgconfig
181
  )
182
183
184
185
186
187
188
189
 
foreach(_lib ${CLHEP_libraries})
  string(TOLOWER ${_lib} _pcfilename)
  install(FILES
    ${PROJECT_BINARY_DIR}/InstallTreeFiles/clhep-${_pcfilename}.pc
    DESTINATION lib${LIB_SUFFIX}/pkgconfig
    )
endforeach()
190
191
192
193

# - And we should be done...

endmacro(clhep_toolchain)