我使用CMake 来编译我的基于ROOT 的项目。
如果你有一个项目目录 proj/,它包含 src/ 和 bin/,你需要 3 个 CMakeList.txt 文件,每个目录一个。
主项目目录下的简单示例 CMakeList.txt:
cmake_minimum_required(VERSION 2.6)
project (SOME_PROJ_NAME)
add_subdirectory(src)
add_subdirectory(bin)
src/ 目录是您保存 .h 和 .cxx 项目的地方。库文件。示例 CMakeList.txt 文件:
# get all the *.cxx filenames, to compile them into a lib
file(GLOB SOME_PROJ_LIB_SRCS "${PROJECT_SOURCE_DIR}/src/*.cxx")
# include ROOT library and include files
include_directories(/path/to/root/dir/include/dir)
link_directories(/path/to/root/dir/lib/dir)
# and compile src into a library
add_library(Proj_lib_name ${SOME_PROJ_LIB_SRCS})
# here, list the ROOT libraries you require
target_link_libraries(Proj_lib_name dl Core Cint RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread Gui pthread m)
bin/ 目录是你保存应用程序 .cxx 文件的地方,它有一个 CMakeList.txt 文件:
include_directories(${PROJECT_SOURCE_DIR}/src)
link_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(/path/to/root/dir/include/dir)
link_directories(/path/to/root/dir/lib/dir)
add_executable(example_app.exe example_app.cxx)
target_link_libraries(example_app.exe Proj_lib_name dl Core Cint RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread Gui pthread m)
最后,要使用 CMake 编译基于 ROOT 的代码,在源代码之外,您在顶级项目目录中创建一个“构建”目录,以便您的目录结构如下所示:
proj/
bin/
build/
src/
然后
cd build
cmake ..
您的二进制文件将位于 build/bin/ 目录中
希望这会有所帮助。