Skip to content

Commit 3683aaa

Browse files
authored
Merge pull request #98 from JeffersonLab/re-cmake
Re cmake
2 parents 32e77a6 + 3a6f658 commit 3683aaa

File tree

7 files changed

+565
-225
lines changed

7 files changed

+565
-225
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ jobs:
1212
container: rootproject/root:${{ matrix.version }}
1313
strategy:
1414
matrix:
15-
version: [6.28.12-ubuntu22.04]
15+
version: [6.34.00-ubuntu24.10]
1616

1717
steps:
1818
- name: system dependencies
1919
run: |
2020
apt -y update
2121
apt -y upgrade
2222
apt -y install git python3-pip
23-
python -m pip install meson ninja
23+
python -m pip install --break-system-packages meson ninja
2424

2525
- name: checkout repository
2626
uses: actions/checkout@v4
@@ -54,8 +54,17 @@ jobs:
5454
cmake --build ccdb_build -j4
5555
cmake --install ccdb_build
5656

57+
- name: Install Vdt development libraries
58+
run: |
59+
apt-get update
60+
apt-get install -y libvdt-dev
61+
# This is often the primary fix for "Could NOT find Vdt"
62+
63+
- name: Checkout Clas12Root
64+
uses: actions/checkout@v4
5765
- name: build clas12root
5866
run: |
67+
echo 'check hipo:'
5968
./installC12Root
6069

6170
- name: run example on data file

CMakeLists.txt

Lines changed: 241 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,249 @@
1-
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2-
project(clas12hipo4root)
1+
# ==============================================================================
2+
# Project Preamble
3+
# ==============================================================================
4+
# Set a modern CMake version. This is CRITICAL. Version 3.16 or higher
5+
# enables the modern policies needed for features like IMPORTED targets to
6+
# work reliably. Using 3.5 forces old, buggy behavior.
7+
cmake_minimum_required(VERSION 3.16)
8+
9+
# Provide a friendly error message if the user's CMake is too old.
10+
if(${CMAKE_VERSION} VERSION_LESS 3.16)
11+
message(FATAL_ERROR "This project requires CMake 3.16 or higher.")
12+
endif()
13+
message(STATUS "Using cmake version ${CMAKE_VERSION}" )
14+
15+
# Define the project name, version, and language
16+
project(clas12root VERSION 1.9 LANGUAGES CXX)
17+
18+
# ==============================================================================
19+
# Set Project-Wide Build Output Directories
20+
# ==============================================================================
21+
# The root_generate_dictionary command needs to know
22+
# where to place the .pcm and .rootmap files. It checks this global variable.
23+
# By setting it, all libraries and their corresponding ROOT dictionary files
24+
# will be placed in a consistent "lib" directory inside your build folder.
25+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
26+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
27+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
28+
29+
# Set a modern C++ standard. C++17 is a good choice for modern ROOT.
30+
# Currently leave ROOT to choose standard
31+
#set(CMAKE_CXX_STANDARD 17)
32+
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
33+
set(CMAKE_CXX_EXTENSIONS OFF)
34+
35+
# Use PIC for shared libraries and set a default build type if none is specified.
36+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
37+
if(NOT CMAKE_BUILD_TYPE)
38+
set(CMAKE_BUILD_TYPE Release)
39+
endif()
40+
41+
# ==============================================================================
42+
# Set Default Installation Prefix from Environment Variable
43+
# ==============================================================================
44+
45+
# This logic sets a default CMAKE_INSTALL_PREFIX based on the CLAS12ROOT
46+
# environment variable, but ONLY if the user has not already specified one
47+
# on the command line (e.g., with -DCMAKE_INSTALL_PREFIX=...).
48+
# The command line always takes priority.
49+
50+
if(DEFINED ENV{CLAS12ROOT})
51+
# This checks if the user has NOT provided a -D... flag for the prefix.
52+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
53+
# We MUST use FORCE here to overwrite the default /usr/local that CMake
54+
# has already put in the cache. This is safe because this whole block
55+
# is skipped if the user provides the -D flag.
56+
set(CMAKE_INSTALL_PREFIX "$ENV{CLAS12ROOT}" CACHE PATH "Default install path from CLAS12ROOT env variable" FORCE)
57+
endif()
58+
endif()
59+
60+
# This message now accurately reports the final installation prefix,
61+
# whether it came from the default, the environment variable, or the user.
62+
message(STATUS "Installation prefix set to: ${CMAKE_INSTALL_PREFIX}")
63+
64+
# ==============================================================================
65+
# Find Dependencies
66+
#
67+
# We find all required packages and define IMPORTED targets for libraries that
68+
# are not CMake-aware (like HIPO).
69+
# ==============================================================================
70+
71+
# --- 1. Find ROOT ---
72+
# This single command replaces the old system. It finds ROOT and creates the
73+
# modern ROOT::* library targets.
74+
# NOTE: Ensure you have sourced 'thisroot.sh' in your terminal first!
75+
find_package(ROOT REQUIRED COMPONENTS
76+
Core # Fundamental ROOT classes (TObject, TString, TTree, basic I/O)
77+
RIO # ROOT I/O system (reading/writing .root files, crucial for TTree)
78+
Hist # Histogramming (TH1, TH2, TGraph, etc.)
79+
Graf # Basic graphics primitives (TPolyLine, TMarker, etc.)
80+
Graf3d # 3D Graphics primitives (if you use any 3D drawing)
81+
Gpad # Graphics Pads (TPad), crucial for canvases
82+
Gui # GUI elements (buttons, menus, dialogs - if you have a custom GUI)
83+
MathCore # Basic math functions (e.g., TMath, TLorentzVector)
84+
# More advanced/specific components you might need based on your code:
85+
Tree # TTree and related classes (often pulled in by Core, but good to be explicit)
86+
Geom # If you use ROOT's geometry package (TGeo)
87+
GenVector # ROOT's vector and physics vector classes (TLorentzVector, etc.)
88+
Rint # The ROOT interactive interpreter. Usually not needed for compiled executables.
89+
# Only include this if you explicitly link to the interactive shell for some reason.
90+
# It can sometimes pull in many dependencies.
91+
)
92+
include(${ROOT_USE_FILE})
93+
94+
# --- 2. Find HIPO4 ---
95+
# Instead of manually setting variables, we check for the HIPO environment
96+
# variable and create a proper, modern CMake target from it.
97+
message(STATUS "Checking for HIPO4 library...")
98+
if(DEFINED ENV{HIPO})
99+
set(HIPO_INSTALL_DIR $ENV{HIPO})
100+
message(STATUS "Found HIPO4 at: ${HIPO_INSTALL_DIR}")
101+
102+
# Create a modern INTERFACE library target for HIPO.
103+
# This encapsulates its usage requirements in a single target: "hipo::hipo"
104+
add_library(hipo::hipo INTERFACE IMPORTED)
105+
target_include_directories(hipo::hipo INTERFACE ${HIPO_INSTALL_DIR}/include)
106+
target_link_libraries(hipo::hipo INTERFACE ${HIPO_INSTALL_DIR}/lib/libhipo4.so)
107+
108+
else()
109+
message(FATAL_ERROR "HIPO environment variable not set. Please set HIPO to point to your hipo4 installation directory.")
110+
endif()
111+
112+
# --- Find External Dependencies (QADB, CCDB, RCDB) ---
113+
# This logic is now centralized here so that all subdirectories can see
114+
# the dependency targets we create.
115+
116+
# --- 3. Find QADB ---
117+
if(DEFINED ENV{QADB})
118+
message(STATUS "Configuring dependency: QADB")
119+
add_library(clas12::qadb INTERFACE IMPORTED)
120+
target_compile_definitions(clas12::qadb INTERFACE -DCLAS_QADB)
121+
target_include_directories(clas12::qadb INTERFACE $ENV{QADB}/srcC/include)
122+
target_include_directories(clas12::qadb INTERFACE $ENV{QADB}/srcC/rapidjson/include)
123+
include_directories($ENV{QADB}/srcC/include)
124+
include_directories($ENV{QADB}/srcC/rapidjson/include)
125+
endif()
126+
127+
128+
# --- 4. Find CCDB ---
129+
if(DEFINED ENV{CCDB_HOME})
130+
message(STATUS "Configuring dependency: CCDB")
131+
add_library(clas12::ccdb INTERFACE IMPORTED)
132+
target_include_directories(clas12::ccdb INTERFACE $ENV{CCDB_HOME}/include)
133+
target_link_libraries(clas12::ccdb INTERFACE $ENV{CCDB_HOME}/lib/libccdb.so) # Assumes .so, adjust if needed
134+
target_compile_definitions(clas12::ccdb INTERFACE -DCLAS_CCDB)
135+
include_directories($ENV{CCDB_HOME}/include)
136+
endif()
137+
138+
139+
# --- 5. Find RCDB and MySQL ---
140+
if(DEFINED ENV{RCDB_HOME})
141+
message(STATUS "Configuring dependency: RCDB")
142+
add_library(clas12::rcdb INTERFACE IMPORTED)
143+
target_include_directories(clas12::rcdb INTERFACE $ENV{RCDB_HOME}/cpp/include)
144+
target_compile_definitions(clas12::rcdb INTERFACE -DCLAS_RCDB)
145+
include_directories($ENV{RCDB_HOME}/cpp/include)
146+
147+
find_package(MySQL QUIET)
148+
149+
150+
if(MySQL_FOUND)
151+
message(STATUS "Found MySQL for RCDB support")
152+
else()
153+
message(STATUS "MySQL not found via find_package. Attempting to locate headers and library manually.")
154+
155+
# --- Manual Search for MySQL ---
156+
# Find MySQL Header (mysql.h)
157+
FIND_PATH(MySQL_INCLUDE_DIR
158+
mysql.h
159+
PATHS
160+
/usr/local/include/mysql
161+
/usr/include/mysql
162+
/opt/homebrew/opt/mysql-client/include # Common Homebrew path
163+
/usr/local/Cellar/mysql-client/*/include # More generic Homebrew path
164+
"$ENV{MYSQL_HOME}/include" # Check an environment variable hint
165+
"$ENV{MYSQL_ROOT}/include"
166+
NO_DEFAULT_PATH # Only search the paths explicitly listed
167+
)
168+
169+
# Find MySQL Library (libmysqlclient)
170+
FIND_LIBRARY(MySQL_LIBRARIES
171+
NAMES mysqlclient libmysqlclient # Common names for the library
172+
PATHS
173+
/usr/local/lib
174+
/usr/lib
175+
/usr/lib/x86_64-linux-gnu # Common Linux specific path
176+
/opt/homebrew/opt/mysql-client/lib # Common Homebrew path
177+
/usr/local/Cellar/mysql-client/*/lib # More generic Homebrew path
178+
"$ENV{MYSQL_HOME}/lib"
179+
"$ENV{MYSQL_ROOT}/lib"
180+
NO_DEFAULT_PATH # Only search the paths explicitly listed
181+
)
182+
183+
# Check if both header and library were found manually
184+
if (MySQL_INCLUDE_DIR AND MySQL_LIBRARIES)
185+
message(STATUS "MySQL manually found. Header: ${MySQL_INCLUDE_DIR}, Library: ${MySQL_LIBRARIES}")
186+
else()
187+
# If either part of the manual search failed, report an error
188+
message(FATAL_ERROR "MySQL development files not found.
189+
Please ensure 'libmysqlclient-dev' (Debian/Ubuntu) or 'mysql-devel' (Fedora/RHEL) or 'mysql-client' (Homebrew) is installed.
190+
You may also need to set CMAKE_PREFIX_PATH or MYSQL_ROOT_DIR if installed in a non-standard location."
191+
)
192+
endif()
193+
194+
endif()
195+
if (MySQL_INCLUDE_DIR AND MySQL_LIBRARIES)
196+
target_include_directories(clas12::rcdb INTERFACE ${MySQL_INCLUDE_DIR})
197+
target_link_libraries(clas12::rcdb INTERFACE ${MySQL_LIBRARIES})
198+
target_compile_definitions(clas12::rcdb INTERFACE -DRCDB_MYSQL)
199+
include_directories(${MySQL_INCLUDE_DIR})
200+
endif()
201+
endif()
202+
203+
204+
# ==============================================================================
205+
# Installation Rules
206+
#
207+
# This section defines how to install the project's products (libraries,
208+
# executables, headers).
209+
# ==============================================================================
210+
include(GNUInstallDirs)
211+
212+
# ==============================================================================
213+
# Configure Subdirectories
214+
#
215+
# We add our sub-projects. The global include_directories() calls have been
216+
# removed. Each subdirectory is now responsible for defining its own targets
217+
# and public include paths.
218+
# ==============================================================================
3219

4-
5-
set(CMAKE_INSTALL_BINDIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)
6-
set(CMAKE_INSTALL_LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
7-
set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
8-
set(CMAKE_INSTALL_MANDIR ${CMAKE_CURRENT_SOURCE_DIR}/man)
9-
set(CMAKE_CXX_FLAGS "-fPIC -O3")
10-
11-
12-
##########For local ROOT cmake files comment in the line below and remove the lines commented ##USEROOTSYS
13-
#####include("cmake/FindROOT.cmake")
14-
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS}) ############USEROOTSYS
15-
16-
#---Locate the ROOT package and defines a number of variables (e.g. ROOT_INCLUDE_DIRS)
17-
find_package(ROOT REQUIRED COMPONENTS Proof) ###########USEROOTSYS
18-
19-
#---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)
20-
#include(${ROOT_USE_FILE}) ##########USEROOTSYS
21-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ROOT_CXX_FLAGS}")
22-
23-
#find_package(hipo4 REQUIRED) #for cmake
24-
#find_package(PkgConfig REQUIRED) #for pkg
25-
#pkg_check_modules(hipo4 REQUIRED IMPORTED_TARGET hipo4)
26-
27-
#currently load hipo via simple env paths
28-
MESSAGE( CHECK_START "Checking for installed hipo..." )
29-
30-
if (DEFINED ENV{HIPO})
31-
32-
set(HIPOEXT $ENV{HIPO})
33-
set(HIPO_INCLUDE_DIR ${HIPOEXT}/include/)
34-
set(HIPO_LIBS "-L${HIPOEXT}/lib -lhipo4")
35-
36-
MESSAGE( STATUS "HIPO INCLUDE_DIR : " ${HIPO_INCLUDE_DIR} )
37-
MESSAGE( STATUS "HIPO LIBRARIES : " ${HIPO_LIBS} )
38-
39-
else ()
40-
41-
MESSAGE( CHECK_FAIL "$HIPO not set" )
42-
MESSAGE( FATAL_ERROR , "\n ... $HIPO must be set to local install of the hipo library\n ... see clas12root/README.md\n ... cmake exiting")
43-
44-
endif ()
45-
46-
#include clas12-qadb c++ library and rapidjson library
47-
IF (DEFINED ENV{QADB})
48-
include_directories($ENV{QADB}/srcC/include)
49-
include_directories($ENV{QADB}/srcC/rapidjson/include)
50-
add_definitions(-DCLAS_QADB)
51-
ENDIF (DEFINED ENV{QADB})
220+
set(HIPOROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/hipo4)
52221

222+
#include_directories(${HIPOROOT_DIR})
223+
#add_subdirectory (${HIPOROOT_DIR})
224+
add_subdirectory(hipo4)
225+
add_subdirectory(Clas12Banks)
226+
add_subdirectory(Clas12Root)
53227

54228

55-
set(HIPOROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/hipo4)
56-
set(CLAS12ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Clas12Root)
57-
set(CLAS12BANKS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Clas12Banks)
58229

230+
# NOTE: You need to replace "your_lib_target" and "your_exe_target" with the
231+
# actual names of the targets defined in your subdirectories' CMakeLists.txt files.
232+
# You can have multiple install() commands.
59233

60-
include_directories(${HIPOROOT_DIR})
61-
add_subdirectory (${HIPOROOT_DIR})
234+
# Example of installing a library:
235+
# install(TARGETS Hipo4
236+
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
237+
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
238+
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
239+
# )
62240

63-
include_directories(${CLAS12BANKS_DIR})
64-
add_subdirectory (${CLAS12BANKS_DIR})
241+
# Example of installing an executable:
242+
# install(TARGETS your_exe_target
243+
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
244+
# )
65245

66-
include_directories(${CLAS12ROOT_DIR})
67-
add_subdirectory (${CLAS12ROOT_DIR})
246+
# Example of installing a public header file or directory:
247+
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Clas12Root/include/
248+
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
249+
# )

0 commit comments

Comments
 (0)