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: CMake configuration #264

Merged
merged 3 commits into from
Nov 21, 2023
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
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if (${USE_ROOT})
endif()
find_package(ROOT REQUIRED)
include(${ROOT_USE_FILE})
add_compile_definitions(HAVE_ROOT)
add_compile_definitions(JANA2_HAVE_ROOT)
include_directories(${ROOT_INCLUDE_DIRS})
link_libraries(${ROOT_LIBRARIES})
execute_process(
Expand All @@ -101,7 +101,7 @@ if (${USE_XERCES})
set(XercesC_DIR $ENV{XERCESCROOT})
endif()
find_package(XercesC REQUIRED)
add_compile_definitions(HAVE_XERCES)
add_compile_definitions(JANA2_HAVE_XERCES)
add_compile_definitions(XERCES3)
include_directories(${XercesC_INCLUDE_DIRS})
link_libraries(${XercesC_LIBRARIES})
Expand All @@ -123,7 +123,7 @@ endif()

if (${USE_PODIO})
find_package(podio REQUIRED)
add_compile_definitions(HAVE_PODIO)
add_compile_definitions(JANA2_HAVE_PODIO)
include_directories(SYSTEM ${podio_INCLUDE_DIR})
endif()

Expand Down
10 changes: 5 additions & 5 deletions cmake/MakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# in generating the jana-config script so that it can report those flags
# for use when building against this version of JANA.
#
# In addition, some variables such as HAVE_ROOT are set which can be used
# In addition, some variables such as JANA2_HAVE_ROOT are set which can be used
# in preprocessor directives to conditionally compile code depending on
# whether the 3rd party package is present.
#
Expand All @@ -26,7 +26,7 @@ execute_process(COMMAND SBMS/osrelease.pl

# ROOT
if(DEFINED ENV{ROOTSYS})
set(HAVE_ROOT 1)
set(JANA2_HAVE_ROOT 1)
set(ROOTSYS $ENV{ROOTSYS})

execute_process(COMMAND $ENV{ROOTSYS}/bin/root-config --cflags
Expand All @@ -38,13 +38,13 @@ if(DEFINED ENV{ROOTSYS})
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
# message(STATUS "Did not find ROOT")
set(HAVE_ROOT 0)
set(JANA2_HAVE_ROOT 0)
endif()

# XERCESC
# n.b. this is hard-coded for now to assume XERCES 3
if(DEFINED ENV{XERCESCROOT})
set(HAVE_XERCES 1)
set(JANA2_HAVE_XERCES 1)
set(XERCES3 1)
set(XERCESCROOT $ENV{XERCESCROOT})
set(XERCES_CPPFLAGS "-I${XERCESCROOT}/include/xercesc")
Expand All @@ -56,7 +56,7 @@ if(DEFINED ENV{XERCESCROOT})
else()
find_package(XercesC)
if(XercesC_FOUND)
set(HAVE_XERCES 1)
set(JANA2_HAVE_XERCES 1)
set(XERCES3 1)
get_filename_component(XERCESCROOT "${XercesC_INCLUDE_DIRS}" DIRECTORY)
set(XERCES_CPPFLAGS "-I${XercesC_INCLUDE_DIRS} -I${XercesC_INCLUDE_DIRS}/xercesc")
Expand Down
4 changes: 2 additions & 2 deletions scripts/jana-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
BMS_OSNAME="@BMS_OSNAME@"

HAVE_MYSQL="@HAVE_MYSQL@"
HAVE_XERCES="@HAVE_XERCES@"
HAVE_ROOT="@HAVE_ROOT@"
JANA2_HAVE_XERCES="@JANA2_HAVE_XERCES@"
JANA2_HAVE_ROOT="@JANA2_HAVE_ROOT@"
HAVE_CMSG="@HAVE_CMSG@"
HAVE_CURL="@HAVE_CURL@"
HAVE_CCDB="@HAVE_CCDB@"
Expand Down
4 changes: 2 additions & 2 deletions scripts/jana-this.csh.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ setenv JANA_HOME "@JANA_INSTALL_DIR@"
setenv PATH @JANA_INSTALL_DIR@/bin:${PATH}

# ROOT
if ( "@HAVE_ROOT@" == "1" ) then
if ( "@JANA2_HAVE_ROOT@" == "1" ) then
if ( -f "@ROOTSYS@/bin/thisroot.csh" ) then
unsetenv ROOTSYS
source "@ROOTSYS@/bin/thisroot.csh"
endif
endif

# Xerces
if ( "@HAVE_XERCES@" == "1" ) then
if ( "@JANA2_HAVE_XERCES@" == "1" ) then
setenv XERCESCROOT "@XERCESCROOT@"
# only add to LD_LIBRARY_PATH if XERCESCROOT does not appear to be a system directory
if ( ${XERCESCROOT} != /usr ) set MY_TMP_LD_LIBRARY_PATH=${XERCESCROOT}/lib:${MY_TMP_LD_LIBRARY_PATH}
Expand Down
4 changes: 2 additions & 2 deletions scripts/jana-this.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export JANA_HOME="@JANA_INSTALL_DIR@"
export PATH=@JANA_INSTALL_DIR@/bin:${PATH}

# ROOT
if [ "@HAVE_ROOT@" == "1" ]; then
if [ "@JANA2_HAVE_ROOT@" == "1" ]; then
if [ -f "@ROOTSYS@/bin/thisroot.sh" ]; then
unset ROOTSYS
. "@ROOTSYS@/bin/thisroot.sh"
fi
fi

# Xerces
if [ "@HAVE_XERCES@" == "1" ]; then
if [ "@JANA2_HAVE_XERCES@" == "1" ]; then
export XERCESCROOT="@XERCESCROOT@"
# only add to LD_LIBRARY_PATH if XERCESCROOT does not appear to be a system directory
[[ ${XERCESCROOT} != /usr ]] && export LD_LIBRARY_PATH=${XERCESCROOT}/lib:${LD_LIBRARY_PATH}
Expand Down
4 changes: 2 additions & 2 deletions scripts/jana_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// This file was generated by CMake (see cmake/make_config.cmake)
//

#define HAVE_ROOT @HAVE_ROOT@
#define HAVE_XERCES @HAVE_XERCES@
#define JANA2_HAVE_ROOT @JANA2_HAVE_ROOT@
#define JANA2_HAVE_XERCES @JANA2_HAVE_XERCES@
#define XERCES3 @XERCES3@
#define HAVE_CCDB @HAVE_CCDB@
#define HAVE_NUMA @HAVE_NUMA@
Expand Down
42 changes: 34 additions & 8 deletions src/libraries/JANA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,30 +154,56 @@ find_package(Threads REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
target_include_directories(jana2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..)
# So that we can find the generated JVersion.h before install

target_link_libraries(jana2 ${CMAKE_DL_LIBS} Threads::Threads)
if (${USE_PODIO})
target_link_libraries(jana2 ${CMAKE_DL_LIBS} Threads::Threads podio::podio podio::podioRootIO)
else()
target_link_libraries(jana2 ${CMAKE_DL_LIBS} Threads::Threads)
target_compile_definitions(jana2 PUBLIC JANA2_HAVE_PODIO=1 JANA2_HAVE_ROOT=1)
target_link_libraries(jana2 podio::podio podio::podioRootIO ${ROOT_LIBRARIES})
elseif (${USE_ROOT})
target_compile_definitions(jana2 PUBLIC JANA2_HAVE_ROOT=1)
target_link_libraries(jana2 ${ROOT_LIBRARIES})
endif()


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

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

if (${USE_PODIO})
target_compile_definitions(jana2_static_lib PUBLIC JANA2_HAVE_PODIO=1 JANA2_HAVE_ROOT=1)
target_link_libraries(jana2_static_lib podio::podio podio::podioRootIO ${ROOT_LIBRARIES})
elseif (${USE_ROOT})
target_compile_definitions(jana2_static_lib PUBLIC JANA2_HAVE_ROOT=1)
target_link_libraries(jana2_static_lib ${ROOT_LIBRARIES})
endif()
install(TARGETS jana2_static_lib EXPORT jana2_targets DESTINATION lib)


# optionally build shared lib
if (BUILD_SHARED_LIBS)
message("-- Build into both shared and static libs")
message(STATUS "Building both shared and static libraries")
add_library(jana2_shared_lib SHARED $<TARGET_OBJECTS:jana2>)
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 ${CMAKE_DL_LIBS} Threads::Threads)

if (${USE_PODIO})
target_compile_definitions(jana2_shared_lib PUBLIC JANA2_HAVE_PODIO=1 JANA2_HAVE_ROOT=1)
target_link_libraries(jana2_shared_lib podio::podio podio::podioRootIO ${ROOT_LIBRARIES})
elseif (${USE_ROOT})
target_compile_definitions(jana2_shared_lib PUBLIC JANA2_HAVE_ROOT=1)
target_link_libraries(jana2_shared_lib ${ROOT_LIBRARIES})
endif()

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

# Install library
install(TARGETS jana2_static_lib EXPORT jana2_targets DESTINATION lib)

# Install JANATargets.cmake
install(EXPORT jana2_targets FILE JANATargets.cmake NAMESPACE JANA:: DESTINATION lib/cmake/JANA)
Expand Down
26 changes: 13 additions & 13 deletions src/libraries/JANA/Compatibility/JGeometryXML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace std;
#include <JANA/Services/JParameterManager.h>
#include "JGeometryXML.h"

#if HAVE_XERCES
#if JANA2_HAVE_XERCES

#if XERCES3
// XERCES 3
Expand Down Expand Up @@ -66,7 +66,7 @@ JGeometryXML::JGeometryXML(string url, int run, string context):JGeometry(url,ru
valid_xmlfile = false;
md5_checksum = "";
jcalib = NULL;
#if HAVE_XERCES
#if JANA2_HAVE_XERCES
parser = NULL;
doc = NULL;
#endif
Expand Down Expand Up @@ -168,7 +168,7 @@ void JGeometryXML::Init(string xmlfile, string xml)
/// data member jcalib will also be non-NULL.


#if !HAVE_XERCES
#if !JANA2_HAVE_XERCES
(void) xmlfile; // Suppress unused parameter warning
(void) xml; // Suppress unused parameter warning
jerr<<endl;
Expand Down Expand Up @@ -241,15 +241,15 @@ void JGeometryXML::Init(string xmlfile, string xml)
// Make map of node names to speed up code in SearchTree later
MapNodeNames(doc);

#endif // !HAVE_XERCES
#endif // !JANA2_HAVE_XERCES
}

//---------------------------------
// ~JGeometryXML (Destructor)
//---------------------------------
JGeometryXML::~JGeometryXML()
{
#if HAVE_XERCES
#if JANA2_HAVE_XERCES
// Release parser and delete any memory it allocated
if(valid_xmlfile){
//parser->release(); // This seems to be causing seg. faults so it is commented out.
Expand All @@ -260,7 +260,7 @@ JGeometryXML::~JGeometryXML()
#endif
}

#if HAVE_XERCES
#if JANA2_HAVE_XERCES
//---------------------------------
// MapNodeNames
//---------------------------------
Expand All @@ -277,7 +277,7 @@ void JGeometryXML::MapNodeNames(xercesc::DOMNode *current_node)
MapNodeNames(current_node); // attributes are automatically added as the tree is searched
}
}
#endif // HAVE_XERCES
#endif // JANA2_HAVE_XERCES

//---------------------------------
// Get
Expand Down Expand Up @@ -316,7 +316,7 @@ bool JGeometryXML::Get(string xpath, string &sval)
// the cache entry once the mutex is finally released
// below.

#if HAVE_XERCES
#if JANA2_HAVE_XERCES

// XERCES locks its own mutex which causes horrible problems if the thread
// is canceled while it has the lock. Disable cancelibility while here.
Expand Down Expand Up @@ -370,7 +370,7 @@ bool JGeometryXML::Get(string xpath, map<string, string> &svals)

if(!valid_xmlfile)return false;

#if HAVE_XERCES
#if JANA2_HAVE_XERCES

// XERCES locks its own mutex which causes horrible problems if the thread
// is canceled while it has the lock. Disable cancelibility while here.
Expand Down Expand Up @@ -411,7 +411,7 @@ bool JGeometryXML::GetMultiple(string xpath, vector<string> &vsval)

if(!valid_xmlfile){return false;}

#if HAVE_XERCES
#if JANA2_HAVE_XERCES

// XERCES locks its own mutex which causes horrible problems if the thread
// is canceled while it has the lock. Disable cancelibility while here.
Expand Down Expand Up @@ -452,7 +452,7 @@ bool JGeometryXML::GetMultiple(string xpath, vector<map<string, string> >&vsvals

if(!valid_xmlfile){return false;}

#if HAVE_XERCES
#if JANA2_HAVE_XERCES

// XERCES locks its own mutex which causes horrible problems if the thread
// is canceled while it has the lock. Disable cancelibility while here.
Expand Down Expand Up @@ -498,7 +498,7 @@ void JGeometryXML::GetXPaths(vector<string> &xpaths, ATTR_LEVEL_t level, const s

if(!valid_xmlfile){xpaths.clear(); return;}

#if HAVE_XERCES
#if JANA2_HAVE_XERCES
AddNodeToList((DOMNode*)doc->getDocumentElement(), "", xpaths, level);
#else
(void) level; // Suppress unused parameter warning
Expand Down Expand Up @@ -724,7 +724,7 @@ void JGeometryXML::ParseXPath(string xpath, vector<pair<string, map<string,strin

}

#if HAVE_XERCES
#if JANA2_HAVE_XERCES
//---------------------------------
// AddNodeToList
//---------------------------------
Expand Down
16 changes: 8 additions & 8 deletions src/libraries/JANA/Compatibility/JGeometryXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@



#if HAVE_XERCES
#if JANA2_HAVE_XERCES
#if !defined(__CINT__) && !defined(__CLING__)

#if XERCES3
Expand Down Expand Up @@ -54,7 +54,7 @@ class xercesc::DOMErrorHandler;
class xercesc::DOMError;
}
#endif // __CINT__ __CLING__
#endif // HAVE_XERCES
#endif // JANA2_HAVE_XERCES


class JGeometryXML:public JGeometry{
Expand All @@ -70,9 +70,9 @@ class JGeometryXML:public JGeometry{
virtual const char* className(void){return static_className();}
static const char* static_className(void){return "JGeometryXML";}

#if HAVE_XERCES
#if JANA2_HAVE_XERCES
void MapNodeNames(xercesc::DOMNode *current_node);
#endif // HAVE_XERCES
#endif // JANA2_HAVE_XERCES
bool Get(string xpath, string &sval);
bool Get(string xpath, map<string, string> &svals);
bool GetMultiple(string xpath, vector<string> &vsval);
Expand All @@ -94,11 +94,11 @@ class JGeometryXML:public JGeometry{
string md5_checksum;
map<string, string> found_xpaths; // used to store xpaths already found to speed up subsequent requests
pthread_mutex_t found_xpaths_mutex;
#if HAVE_XERCES
#if JANA2_HAVE_XERCES
map<xercesc::DOMNode*, string> node_names;
#endif // HAVE_XERCES
#endif // JANA2_HAVE_XERCES

#if HAVE_XERCES
#if JANA2_HAVE_XERCES

class SearchParameters{
public:
Expand Down Expand Up @@ -190,7 +190,7 @@ class JGeometryXML:public JGeometry{
JCalibration *jcalib;
bool PRINT_CHECKSUM_INPUT_FILES;
};
#endif // HAVE_XERCES
#endif // JANA2_HAVE_XERCES

};

Expand Down
Loading