Adding improvements to ROOT
This commit is contained in:
parent
49f3b682b2
commit
6a52473afb
@ -1,29 +1,36 @@
|
||||
|
||||
## [main]
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
cmake_minimum_required(VERSION 3.4)
|
||||
|
||||
project(RootDictExample LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_PLATFORM_INDEPENDENT_CODE ON)
|
||||
|
||||
find_package(Threads)
|
||||
|
||||
find_package(ROOT CONFIG REQUIRED)
|
||||
include("${ROOT_DIR}/modules/RootNewMacros.cmake")
|
||||
|
||||
message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}")
|
||||
|
||||
separate_arguments(ROOT_CXX_FLAGS)
|
||||
|
||||
# We will set the flags ourselves
|
||||
set_target_properties(ROOT::Core PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}"
|
||||
INTERFACE_COMPILE_OPTIONS "${ROOT_CXX_FLAGS}"
|
||||
)
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${ROOT_INCLUDE_DIRS}")
|
||||
|
||||
include_directories(ROOT_BUG)
|
||||
root_generate_dictionary(G__DictExample DictExample.h LINKDEF DictLinkDef.h)
|
||||
|
||||
add_library(DictExample SHARED DictExample.cxx DictExample.h G__DictExample.cxx)
|
||||
target_link_libraries(DictExample PUBLIC ROOT::Core)
|
||||
target_link_libraries(DictExample PUBLIC ROOT::Core Threads::Threads)
|
||||
|
||||
## [main]
|
||||
|
||||
message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}")
|
||||
message(STATUS "Original flags: ${ROOT_CXX_FLAGS}")
|
||||
message(STATUS "Original definitions: ${ROOT_DEFINITIONS}")
|
||||
message(STATUS "Original exe flags: ${ROOT_EXE_LINKER_FLAGS}")
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME RootDictExample
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
|
@ -1,6 +1,8 @@
|
||||
# Dictionary Example
|
||||
|
||||
This is an example of building a module that includes a dictionary in CMake.
|
||||
This is an example of building a module that includes a dictionary in CMake. Instead of using the
|
||||
ROOT suggested flags, we will manually add threading via `find_package`, which is the only
|
||||
important flag in the list on most systems.
|
||||
|
||||
#### examples/root-dict/CMakeLists.txt
|
||||
[import:'main', lang:'cmake'](CMakeLists.txt)
|
||||
|
@ -5,23 +5,23 @@ cmake_minimum_required(VERSION 3.11)
|
||||
project(RootSimpleExample311 LANGUAGES CXX)
|
||||
|
||||
find_package(ROOT CONFIG REQUIRED)
|
||||
message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}")
|
||||
|
||||
separate_arguments(ROOT_CXX_FLAGS)
|
||||
separate_arguments(ROOT_DEFINITIONS)
|
||||
message(STATUS "ROOT_DEFINITIONS ${ROOT_DEFINITIONS}")
|
||||
|
||||
# This is required on if there is more than one flag (like on macOS)
|
||||
# and this also fixes a bug in the linker flags
|
||||
string(REPLACE "-L " "-L" ROOT_EXE_LINKER_FLAGS "${ROOT_EXE_LINKER_FLAGS}")
|
||||
separate_arguments(ROOT_EXE_LINKER_FLAGS)
|
||||
|
||||
## [modern_fix]
|
||||
target_include_directories(ROOT::Core INTERFACE "${ROOT_INCLUDE_DIRS}")
|
||||
|
||||
add_library(ROOT::Flags_CXX IMPORTED INTERFACE)
|
||||
|
||||
separate_arguments(ROOT_CXX_FLAGS)
|
||||
target_compile_options(ROOT::Flags_CXX INTERFACE ${ROOT_CXX_FLAGS})
|
||||
|
||||
separate_arguments(ROOT_DEFINITIONS)
|
||||
target_compile_definitions(ROOT::Flags_CXX INTERFACE ${ROOT_DEFINITIONS})
|
||||
|
||||
# This fixes a bug in the linker flags
|
||||
string(REPLACE "-L " "-L" ROOT_EXE_LINKER_FLAGS "${ROOT_EXE_LINKER_FLAGS}")
|
||||
separate_arguments(ROOT_EXE_LINKER_FLAGS)
|
||||
# Stuck into using old property method due to separate -L and -l arguments
|
||||
# (A full path to -l is better!)
|
||||
set_property(TARGET ROOT::Flags_CXX PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES ${ROOT_EXE_LINKER_FLAGS})
|
||||
## [modern_fix]
|
||||
|
@ -8,8 +8,6 @@ project(RootSimpleExample LANGUAGES CXX)
|
||||
find_package(ROOT CONFIG REQUIRED)
|
||||
## [find_package]
|
||||
|
||||
message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}")
|
||||
|
||||
# ROOT targets are missing includes and flags
|
||||
## [setup_includes]
|
||||
set_property(TARGET ROOT::Core PROPERTY
|
||||
@ -17,20 +15,24 @@ set_property(TARGET ROOT::Core PROPERTY
|
||||
## [setup_includes]
|
||||
|
||||
## [setup_flags]
|
||||
add_library(ROOT::Flags_CXX IMPORTED INTERFACE)
|
||||
|
||||
# Fix for ROOT_CXX_FLAGS not actually being a CMake list
|
||||
separate_arguments(ROOT_CXX_FLAGS)
|
||||
separate_arguments(ROOT_DEFINITIONS)
|
||||
|
||||
# This is required on if there is more than one flag (like on macOS)
|
||||
# and this also fixes a bug in the linker flags
|
||||
string(REPLACE "-L " "-L" ROOT_EXE_LINKER_FLAGS "${ROOT_EXE_LINKER_FLAGS}")
|
||||
separate_arguments(ROOT_EXE_LINKER_FLAGS)
|
||||
|
||||
add_library(ROOT::Flags_CXX IMPORTED INTERFACE)
|
||||
set_property(TARGET ROOT::Flags_CXX APPEND PROPERTY
|
||||
INTERFACE_COMPILE_OPTIONS ${ROOT_CXX_FLAGS})
|
||||
set_property(TARGET ROOT::Flags_CXX APPEND PROPERTY
|
||||
INTERFACE_COMPILE_DEFINITIONS ${ROOT_DEFINITIONS})
|
||||
|
||||
# Add definitions
|
||||
separate_arguments(ROOT_DEFINITIONS)
|
||||
foreach(_flag ${ROOT_EXE_LINKER_FLAG_LIST})
|
||||
# Remove -D or /D if present
|
||||
string(REGEX REPLACE [=[^[-//]D]=] "" _flag ${_flag})
|
||||
set_property(TARGET ROOT::Flags APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${_flag})
|
||||
endforeach()
|
||||
|
||||
# This also fixes a bug in the linker flags
|
||||
string(REPLACE "-L " "-L" ROOT_EXE_LINKER_FLAGS "${ROOT_EXE_LINKER_FLAGS}")
|
||||
separate_arguments(ROOT_EXE_LINKER_FLAGS)
|
||||
set_property(TARGET ROOT::Flags_CXX APPEND PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES ${ROOT_EXE_LINKER_FLAGS})
|
||||
## [setup_flags]
|
||||
|
@ -5,7 +5,6 @@ cmake_minimum_required(VERSION 3.1)
|
||||
project(RootUseFileExample LANGUAGES CXX)
|
||||
|
||||
find_package(ROOT CONFIG REQUIRED)
|
||||
message(STATUS "Found ROOT: ${ROOT_VERSION} at ${ROOT_DIR}")
|
||||
|
||||
include("${ROOT_USE_FILE}")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user