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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
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 @@ -79,7 +79,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 @@ -94,28 +94,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,13 +9,16 @@
#include <iostream>
#include <sstream>
#include <chrono>
#include <thread>
#include <iomanip>
#include <time.h>
#include <mutex>
#include <atomic>


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 @@ -86,6 +89,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 @@ -97,9 +107,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/libraries/JANA/Services/JPluginLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void JPluginLoader::attach_plugin(std::string name, std::string path) {

// Open shared object
dlerror(); // Clear any earlier dlerrors
void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE);
void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL);
if (!handle) {
std::string err = dlerror();
LOG_ERROR(m_logger) << "Plugin \"" << name << "\" dlopen() failed: " << err << LOG_END;
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)

Loading