Hi,
I’m trying to learn to use cmake in order to build shared libraries of ROOT-based classes.
I have tried to copy & mix & match what I see in test/CMakeLists.txt and in the main ROOT
cmake build structure, e.g. hist/hist/CMakeLists.txt.
I am using the git branch v5-34-00-patches on Ubuntu 14.10 (gcc 4.9.1) with cmake v2.8.12.2
I have two simple classes, one derived from TObject, the other derives from the first,
in the following structure:
rootLib/
rootLib/CMakeLists.txt
rootLib/inc
rootLib/inc/LinkDef.h
rootLib/inc/RootClass2.h
rootLib/inc/RootClass1.h
rootLib/src
rootLib/src/RootClass1.cpp
rootLib/src/RootClass2.cpp
Here is the CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(rootLib)
find_package(ROOT REQUIRED)
set(CMAKE_MODULE_PATH ${ROOT_DIR}/modules)
include(RootNewMacros)
include_directories(${ROOT_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
ROOT_GENERATE_DICTIONARY(RootLibDict *.h LINKDEF LinkDef.h)
ROOT_LINKER_LIBRARY(RootLib *.cpp RootLibDict.cxx LIBRARIES Core)
This works fine:
ganp115:~/software/CMake/rootLib% mkdir build
ganp115:~/software/CMake/rootLib% cd build
ganp115:~/software/CMake/rootLib/build% mkdir destdir
ganp115:~/software/CMake/rootLib/build% cmake -DCMAKE_INSTALL_PREFIX=$PWD/destdir ..
-- The C compiler identification is GNU 4.9.1
-- The CXX compiler identification is GNU 4.9.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/john/software/CMake/rootLib/build
ganp115:~/software/CMake/rootLib/build% make
[ 25%] Generating RootLibDict.cxx, RootLibDict.h
Scanning dependencies of target RootLib
[ 50%] Building CXX object CMakeFiles/RootLib.dir/src/RootClass1.cpp.o
[ 75%] Building CXX object CMakeFiles/RootLib.dir/src/RootClass2.cpp.o
[100%] Building CXX object CMakeFiles/RootLib.dir/RootLibDict.cxx.o
Linking CXX shared library libRootLib.so
[100%] Built target RootLib
and produces the expected libRootLib.so in the build directory which I can load in ROOT and
play with my new classes. However, if I try to install:
ganp115:~/software/CMake/rootLib/build% make install
make: *** No rule to make target 'install'. Stop.
Clearly I have missed something. Looking at e.g. hist/hist/CMakeLists.txt, it seems that I should
add ROOT_INSTALL_HEADERS() to the end of CMakeLists.txt, but when I do this I get an error that
I can’t understand:
CMake Error at /home/john/software/build/root-v5-34-00/cmake/modules/RootNewMacros.cmake:456 (install):
install DIRECTORY given no DESTINATION!
Call Stack (most recent call first):
CMakeLists.txt:14 (ROOT_INSTALL_HEADERS)
Also inspired by hist/hist/CMakeLists.txt, it seems that generating the rootmap file should be a piece of
cake too, so I modified in the following way:
ROOT_GENERATE_DICTIONARY(RootLibDict *.h LINKDEF LinkDef.h)
ROOT_GENERATE_ROOTMAP(RootLib LINKDEF LinkDef.h DEPENDENCIES Core)
ROOT_LINKER_LIBRARY(RootLib *.cpp RootLibDict.cxx LIBRARIES Core)
But again I clearly haven’t understood how to use the ROOT cmake modules (if they had explanatory comments in their source code it might be easier…) because I now get:
CMake Error at /home/john/software/build/root-v5-34-00/cmake/modules/RootNewMacros.cmake:443 (install):
install FILES given no DESTINATION!
Call Stack (most recent call first):
CMakeLists.txt:12 (ROOT_GENERATE_ROOTMAP)
I am sure I have missed something obvious, any help would be greatly appreciated.
Cheers
John