What is the recommanded directory and install structure for a root lib?

Hi,

I have a piece of C++ code (several tens of files) linking with ROOT to create a library that can be then loaded in root (gSystem->Load()) and be used, a rootlogon.C file that configure this and a few other things (adding the gSystem->AddIncludePath(), etc).
cmake is used for compilation.

Right now, the code and includes are in a few subdirectories, the rootlogon is just in the main directory, etc. and none of this can really be deployed easily by an end user.

Is there a recommended way to setup such a project directory structure and CMakeList.txt content? A way to have a working “make install” that would put things in a place root would find it easily (ideally under a user prefix some /home/<user>/something)?

What would be best would be a pointer to either some “hello world” (but full featured) example, or a working project having similar goals.

Thanks for any suggestion.
Regards,
Yannick


ROOT Version: Not Provided
Platform: Linux
Compiler: Not Provided


Welcome to the ROOT Forum!
The directory structure of the project is not really related to the install directory (set by CMAKE_INSTALL_PREFIX). in general, I use a directory for the project (project_name) with a source and a build directory. And here is an example of CMakeLists.txt:

# Check if cmake has the required version
CMAKE_MINIMUM_REQUIRED(VERSION 3.16.4 FATAL_ERROR)

set(PROJECT_NAME MyProject)
project(${PROJECT_NAME})

find_package(ROOT REQUIRED)

set(CMAKE_CXX_FLAGS "${ROOT_CXX_FLAGS}" )

include(${ROOT_USE_FILE})
include_directories(${ROOT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
link_directories(${ROOT_LIBRARY_DIR})

set(HEADERS
  header1.h
  header2.h
  header3.h
)

set(SOURCES
  source1.cxx
  source2.cxx
  source3.cxx
)

ROOT_GENERATE_DICTIONARY(${PROJECT_NAME}Dict.cxx ${HEADERS} LINKDEF LinkDef.h)

add_library(lib${PROJECT_NAME} SHARED ${SOURCES} ${PROJECT_NAME}Dict.cxx)
target_link_libraries(lib${PROJECT_NAME} ${ROOT_LIBRARIES})
if(MSVC)
  set_target_properties(lib${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${PROJECT_NAME} COMPONENT applications)
install(DIRECTORY data/  DESTINATION ${PROJECT_NAME}/data COMPONENT data)
install(DIRECTORY icons/  DESTINATION ${PROJECT_NAME}/icons COMPONENT icons)

See also How to use CMake to compile with ROOT libraries - #2 by bellenot

Hi,

Thanks for the help.

Here is a problem I have now:
In a CMakeFile.txt, I have:

ROOT_GENERATE_DICTIONARY(PrjDict ${HFILES} LINKDEF PRJClassesLinkDef.h )
add_library(PRJ SHARED ${SRCFILES} PrjDict.cxx)
target_link_libraries(PRJ ${ROOT_LIBRARIES} GSL::gsl GSL::gslcblas)

install(TARGETS PRJ DESTINATION lib)

When I cmake and make, I have both libPrj.so and libPrjDict_rdict.pcm
However, when I do a make install only the libPrj.so is copied to <installprefix>/lib.
I read there:
https://github.com root-project/root/issues/8308

And tried to put the ROOT_GENERATE_DICTIONARY below, but then I get tons of multiple definition of `ROOT::GenerateInitInstance()'…

Any suggestion?

Thanks.

Yannick

There should be exactly one GenerateInitInstance per #pragma link C++ entry in the linkdef file. Can you give a sample of the duplicate symbols and where they are from?