Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: ODR violation #396

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/ccpp-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ jobs:
run: |
echo "ldd bin/jana"
ldd bin/jana
echo "ldd bin/libJANA.so"
echo "ldd lib/libJANA.so"
ldd lib/libJANA.so
echo "bin/jana rpath"
objdump -x bin/jana | grep PATH
echo "lib/libJANA.so rpath"
objdump -x lib/libJANA.so | grep PATH
echo "lib/JANA/plugins/TimesliceExample.so"
objdump -x lib/JANA/plugins/TimesliceExample.so | grep PATH
echo "bin/PodioExample"
objdump -x bin/PodioExample | grep PATH
echo "RPATH of bin/jana:"
objdump -x bin/jana | grep PATH || echo "Empty!"
echo "RPATH of lib/libJANA.so:"
objdump -x lib/libJANA.so | grep PATH || echo "Empty!"
echo "RPATH of lib/JANA/plugins/TimesliceExample.so:"
objdump -x lib/JANA/plugins/TimesliceExample.so | grep PATH || echo "Empty!"
echo "RPATH of bin/PodioExample:"
objdump -x bin/PodioExample | grep PATH || echo "Empty!"

- name: JTest
run: |
export LD_LIBRARY_PATH=/app/podio/install/lib:$LD_LIBRARY_PATH
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/eicshell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ jobs:
export LD_LIBRARY_PATH=$JANA_HOME/lib:$JANA_HOME/lib/JANA/plugins:$LD_LIBRARY_PATH
echo "ldd bin/jana"
ldd bin/jana
echo "ldd bin/libJANA.so"
echo "ldd lib/libJANA.so"
ldd lib/libJANA.so
echo "bin/jana rpath"
objdump -x bin/jana | grep PATH
echo "lib/libJANA.so rpath"
objdump -x lib/libJANA.so | grep PATH
echo "lib/JANA/plugins/TimesliceExample.so"
objdump -x lib/JANA/plugins/TimesliceExample.so | grep PATH
echo "bin/PodioExample"
objdump -x bin/PodioExample | grep PATH
echo "RPATH of bin/jana:"
objdump -x bin/jana | grep PATH || echo "Empty!"
echo "RPATH of lib/libJANA.so:"
objdump -x lib/libJANA.so | grep PATH || echo "Empty!"
echo "RPATH of lib/JANA/plugins/TimesliceExample.so:"
objdump -x lib/JANA/plugins/TimesliceExample.so | grep PATH || echo "Empty!"
echo "RPATH of bin/PodioExample:"
objdump -x bin/PodioExample | grep PATH || echo "Empty!"

- name: Run JTest plugin with 100 events
uses: eic/run-cvmfs-osg-eic-shell@main
Expand Down
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ else()
endif()


# Add library directories to rpath so users don't need to use LD_LIBRARY_PATH.
# (see https://dev.my-gate.net/2021/08/04/understanding-rpath-with-cmake )
# TODO: detector MacOS and set MACOSX_RPATH to TRUE
# Add library directories to RPATH for all targets
set( CMAKE_SKIP_BUILD_RPATH FALSE )
set( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
set( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib/JANA/plugins" )
set( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib/JANA/plugins" )
set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )

# Generate a compilation database, e.g. for IDE autocompletion
Expand Down
8 changes: 4 additions & 4 deletions cmake/AddJanaPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
macro(add_jana_plugin plugin_name)

# Parse remaining arguments
set(options LINK_SHARED)
set(options LINK_STATIC)
set(oneValueArgs EXPORT)
set(multiValueArgs SOURCES PUBLIC_HEADER TESTS)

cmake_parse_arguments(PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if (LINK_SHARED)
set(PLUGIN_JANA_LIB jana2_shared_lib)
else()
if (LINK_STATIC)
set(PLUGIN_JANA_LIB jana2_static_lib)
else()
set(PLUGIN_JANA_LIB jana2_shared_lib)
endif()

if (NOT PLUGIN_SOURCES AND NOT PLUGIN_PUBLIC_HEADER AND NOT PLUGIN_TESTS)
Expand Down
19 changes: 17 additions & 2 deletions cmake/AddJanaTest.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

macro(add_jana_test test_target_name)

cmake_parse_arguments(JANATEST "" "" "SOURCES" ${ARGN})
set(options LINK_STATIC)
cmake_parse_arguments(JANATEST "LINK_STATIC" "" "SOURCES" ${ARGN})

if (NOT JANATEST_SOURCES)
file(GLOB JANATEST_SOURCES "*.c*")
Expand All @@ -10,7 +11,21 @@ macro(add_jana_test test_target_name)
# Set up target
add_executable(${test_target_name} ${JANATEST_SOURCES})

target_link_libraries(${test_target_name} PRIVATE jana2_static_lib VendoredCatch2)
if (${PROJECT_NAME} STREQUAL "jana2")
# This is an internal plugin
set(JANA_NAMESPACE "")
else()
# This is an external plugin
set(JANA_NAMESPACE "JANA::")
endif()

if (LINK_STATIC)
set(PLUGIN_JANA_LIB jana2_static_lib)
else()
set(PLUGIN_JANA_LIB jana2_shared_lib)
endif()

target_link_libraries(${test_target_name} PRIVATE "${JANA_NAMESPACE}${PLUGIN_JANA_LIB}" VendoredCatch2)

set_target_properties(${test_target_name} PROPERTIES
SKIP_BUILD_RPATH FALSE
Expand Down
38 changes: 17 additions & 21 deletions src/libraries/JANA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ elseif (${USE_ROOT})
endif()


# static library, always there
# Build static library
add_library(jana2_static_lib STATIC $<TARGET_OBJECTS:jana2> $<TARGET_OBJECTS:VendoredMD5>)
set_target_properties(jana2_static_lib PROPERTIES PREFIX "lib" OUTPUT_NAME "JANA")

Expand All @@ -95,28 +95,24 @@ elseif (${USE_ROOT})
endif()
install(TARGETS jana2_static_lib EXPORT jana2_targets DESTINATION lib)

# optionally build shared lib
if (BUILD_SHARED_LIBS)
message(STATUS "Building both shared and static libraries")
add_library(jana2_shared_lib SHARED $<TARGET_OBJECTS:jana2> $<TARGET_OBJECTS:VendoredMD5>)
set_target_properties(jana2_shared_lib PROPERTIES PREFIX "lib" OUTPUT_NAME "JANA")

target_include_directories(jana2_shared_lib PUBLIC $<INSTALL_INTERFACE:include>)
target_link_libraries(jana2_shared_lib PUBLIC ${CMAKE_DL_LIBS} Threads::Threads)
target_link_libraries(jana2_shared_lib PUBLIC VendoredTomlPlusPlus)

if (${USE_PODIO})
target_link_libraries(jana2_shared_lib PUBLIC podio::podio podio::podioRootIO ${ROOT_LIBRARIES})
elseif (${USE_ROOT})
target_link_libraries(jana2_shared_lib PUBLIC ${ROOT_LIBRARIES})
endif()

install(TARGETS jana2_shared_lib EXPORT jana2_targets DESTINATION lib)
set(INSTALL_RPATH_USE_LINK_PATH True)
else()
message(STATUS "Building static library only")

# Build shared library
add_library(jana2_shared_lib SHARED $<TARGET_OBJECTS:jana2> $<TARGET_OBJECTS:VendoredMD5>)
set_target_properties(jana2_shared_lib PROPERTIES PREFIX "lib" OUTPUT_NAME "JANA")

target_include_directories(jana2_shared_lib PUBLIC $<INSTALL_INTERFACE:include>)
target_link_libraries(jana2_shared_lib PUBLIC ${CMAKE_DL_LIBS} Threads::Threads)
target_link_libraries(jana2_shared_lib PUBLIC VendoredTomlPlusPlus)

if (${USE_PODIO})
target_link_libraries(jana2_shared_lib PUBLIC podio::podio podio::podioRootIO ${ROOT_LIBRARIES})
elseif (${USE_ROOT})
target_link_libraries(jana2_shared_lib PUBLIC ${ROOT_LIBRARIES})
endif()

install(TARGETS jana2_shared_lib EXPORT jana2_targets DESTINATION lib)
set(INSTALL_RPATH_USE_LINK_PATH True)


# Install "public" header files

Expand Down
2 changes: 2 additions & 0 deletions src/libraries/JANA/JLogger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
JLogger jout {JLogger::Level::INFO, &std::cout, "jana"};
JLogger jerr {JLogger::Level::ERROR, &std::cerr, "jana"};

thread_local int JLogger::thread_id = -1;
std::atomic_int JLogger::next_thread_id = 0;

15 changes: 11 additions & 4 deletions src/libraries/JANA/JLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
#include <iostream>
#include <sstream>
#include <chrono>
#include <thread>
#include <iomanip>
#include <time.h>
#include <mutex>
#include <atomic>

#ifndef JANA2_USE_LOGGER_MUTEX
#define JANA2_USE_LOGGER_MUTEX 0
#endif


struct JLogger {
static thread_local int thread_id;
static std::atomic_int next_thread_id;

enum class Level { TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF };
Level level;
std::ostream *destination;
Expand Down Expand Up @@ -90,6 +93,13 @@ class JLogMessage : public std::stringstream {
builder << std::put_time(&tm_buf, "%H:%M:%S.");
builder << std::setfill('0') << std::setw(3) << milliseconds.count() << std::setfill(' ') << " ";
}
if (logger.show_threadstamp) {
if (logger.thread_id == -1) {
logger.thread_id = logger.next_thread_id;
logger.next_thread_id += 1;
}
builder << "#" << std::setw(3) << std::setfill('0') << logger.thread_id << " ";
}
if (logger.show_level) {
switch (level) {
case JLogger::Level::TRACE: builder << "[trace] "; break;
Expand All @@ -101,9 +111,6 @@ class JLogMessage : public std::stringstream {
default: builder << "[?????] ";
}
}
if (logger.show_threadstamp) {
builder << std::this_thread::get_id() << " ";
}
if (logger.show_group && !logger.group.empty()) {
builder << logger.group << " > ";
}
Expand Down
2 changes: 1 addition & 1 deletion src/programs/jana/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
add_executable(jana jana.cc )

find_package(Threads REQUIRED)
target_link_libraries(jana jana2_static_lib Threads::Threads)
target_link_libraries(jana jana2_shared_lib)
target_link_options(jana PRIVATE -rdynamic)
install(TARGETS jana DESTINATION bin)