-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
162 lines (142 loc) · 5.09 KB
/
CMakeLists.txt
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Set the minimum CMake version required to build the project.
cmake_minimum_required( VERSION 3.1 )
# Silence some warnings on macOS with new CMake versions.
if( NOT ${CMAKE_VERSION} VERSION_LESS 3.9 )
cmake_policy( SET CMP0068 NEW )
endif()
# Set the project's name and version.
project( ttree2hdf5 VERSION 1.0 )
# Set the warning flag(s) to use.
set( CMAKE_CXX_STANDARD 14)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic" )
include_directories(include src)
# find zlib
find_package( ZLIB REQUIRED )
get_filename_component(ZLIB_LIB_DIR ZLIB_LIBRARIES DIRECTORY)
# TODO: figure out how to use this in the hdf5 builder. We should pass
# it an option like `--with-zlib=${ZLIB_INCLUDE_DIRS},${ZLIB_LIB_DIR}`
# but this screws up on some systems because the strings from FindZLIB
# are generators
# find HDF5
#
# Ideally we would like to use find_package, but in ATLAS code we're
# waiting on a fix for this here:
#
# https://sft.its.cern.ch/jira/browse/SPI-984
#
option(BUILTIN_HDF5 "Build hdf5 internally" NO)
if( BUILTIN_HDF5 )
# one option is to build HDF5 here
set( H5_LOC ${CMAKE_BINARY_DIR}/externals/hdf5 )
set( HDF5_INCLUDE_DIRS "${H5_LOC}/include/")
set( HDF5_LIB "${H5_LOC}/lib/")
set( SUFFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
set( HDF5_LIBRARIES
${HDF5_LIB}/libhdf5_cpp${SUFFFIX} ${HDF5_LIB}/libhdf5${SUFFFIX} )
# count processors
include(ProcessorCount)
ProcessorCount(NProcs)
message(STATUS "Building HDF5 with ${NProcs} cores")
if(NProcs EQUAL 0)
message(" *** Processor count failed, using 1 core *** ")
set(NProcs 1)
endif()
include( ExternalProject )
# add the external
ExternalProject_Add( HDF5
PREFIX ${H5_LOC}
URL "https://support.hdfgroup.org/ftp/HDF5/current18/src/hdf5-1.8.19.tar.gz"
URL_MD5 "7f568e2464d4ab0a74d16b23956d900b"
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR>
--enable-cxx
BUILD_COMMAND make -j${NProcs}
INSTALL_COMMAND make install
LOG_DOWNLOAD 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
BUILD_BYPRODUCTS ${HDF5_LIBRARIES} )
else()
find_package( HDF5 1.8.12 REQUIRED COMPONENTS CXX HL)
endif()
# CMake often finds the wrong include directories (i.e. on lxplus)
include_directories(BEFORE SYSTEM ${HDF5_INCLUDE_DIRS})
# Add the hdf tuple wrapper
#
# We build two, one static and one shared
#
option(BUILD_SHARED_HDFTUPLE "Build shared library for hdf5 tuple" OFF)
if( BUILD_SHARED_HDFTUPLE )
add_library(HdfTuple-shared SHARED src/HdfTuple.cxx)
target_link_libraries(HdfTuple-shared ${HDF5_LIBRARIES} ${ZLIB_LIBRARIES})
target_include_directories(HdfTuple-shared
PRIVATE ${HDF5_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
install(TARGETS HdfTuple-shared LIBRARY DESTINATION lib)
if( BUILTIN_HDF5 )
add_dependencies(HdfTuple-shared HDF5)
endif()
endif()
add_library(HdfTuple-static STATIC src/HdfTuple.cxx)
target_link_libraries(HdfTuple-static ${HDF5_LIBRARIES} ${ZLIB_LIBRARIES})
target_include_directories(HdfTuple-static
PRIVATE ${HDF5_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
install( TARGETS HdfTuple-static ARCHIVE DESTINATION lib )
if( BUILTIN_HDF5 )
add_dependencies(HdfTuple-static HDF5)
endif()
install( DIRECTORY include/ DESTINATION include)
# set the RPATH so that libraries don't get lost
option( INSTALL_RPATH "Include dependencies in rpath when installing" OFF )
if( INSTALL_RPATH )
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
# _______________________________________________________________________
# ROOT stuff
#
# this can be disabled if we just want the library to write out HDF5,
# or for CI tests
#
option( ROOT_DEPENDANTS "Enable converter from ROOT (requires ROOT)" ON )
if( NOT ROOT_DEPENDANTS )
message(STATUS "Disabled root dependants")
else()
# find root
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
find_package(ROOT REQUIRED COMPONENTS RIO Hist Tree Net Core)
# make root dicts
include(${ROOT_USE_FILE})
ROOT_GENERATE_DICTIONARY(G__Stl src/Stl.h LINKDEF src/LinkDef.h)
# find boost
set(Boost_USE_STATIC_LIBS ON)
find_package( Boost 1.54.0 REQUIRED COMPONENTS program_options)
set( lib_sources
src/copy_root_tree.cxx
src/get_tree.cxx
src/tree_copy_opts.cxx
src/ttree2hdf5.cxx
src/unshittify.cxx)
# build main library
add_library( convert2hdf5 STATIC ${lib_sources})
target_link_libraries(convert2hdf5
HdfTuple-static
${Boost_LIBRARIES}
${ROOT_LIBRARIES})
target_include_directories( convert2hdf5
PRIVATE ${HDF5_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${ROOT_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
# build top level executable
add_executable(ttree2hdf5 src/ttree2hdf5.cxx G__Stl.cxx)
target_link_libraries(ttree2hdf5 convert2hdf5)
# install binary
install(TARGETS ttree2hdf5 convert2hdf5
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include)
# it's not clear to me where this '.pcm' file is supposed to go, so
# we put it in a few places and hopefully the user includes one of
# them.
set( PCM_FILE ${CMAKE_CURRENT_BINARY_DIR}/libStl_rdict.pcm)
install(FILES ${PCM_FILE} DESTINATION bin)
install(FILES ${PCM_FILE} DESTINATION lib)
endif()