Skip to content

Commit

Permalink
Development/cmake enhancements (#1636)
Browse files Browse the repository at this point in the history
* cmake: set minimum required cmake to 3.15

* cmake: group binaries to components

* cmake: fix typo

* cmake: Introduce project metadata

* cmake: Export versions

* Core: Generate and use a version header

* Thunder: Generate and use a version header

* cmake: Use project version in binaries

* cmake: remove old versioning

* scripts: simplify init script generation

* cmake: introduce new build options

* COM: Prepare for versioned proxystub loading

* Plugin: Prepare for versioned proxystub loading

* cmake: Add Thunder config to runtime component

* cmake make human versioned libs optional

* cmake: remove arbitrary endif

---------

Co-authored-by: Pierre Wielders <pierre@wielders.net>
  • Loading branch information
bramoosterhuis and pwielders committed Jun 12, 2024
1 parent 2419474 commit be5d9c1
Show file tree
Hide file tree
Showing 43 changed files with 309 additions and 199 deletions.
27 changes: 17 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,38 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.15)

project(Thunder)
project(Thunder
VERSION 5.0.0
DESCRIPTION "Thunder framework"
HOMEPAGE_URL "https://rdkcentral.github.io/Thunder/")

set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
string(TIMESTAMP BUILD_TIMESTAMP UTC)

set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})

message(STATUS "Setting up ${PROJECT_NAME} v${VERSION}")
message(STATUS "Setting up ${PROJECT_NAME} v${Thunder_VERSION}")

option(HIDE_NON_EXTERNAL_SYMBOLS
"Hide all non EXTERNAL tagged symbols" ON)
option(ENABLE_STRICT_COMPILER_SETTINGS
"Enable compiler flags to get the warnings/errors due to improper condition in the code" OFF)
option(LEGACY_CONFIG_GENERATOR
"Use the legacy config generator and all its needed CMake sub-components.
If switched OFF, plugins need to use the new python-based templates. (*.conf.in)" OFF)
If switched OFF, plugins need to use the new python-based templates. (*.conf.in)" OFF)
option(HUMAN_VERSIONED_BINARIES
"Create binaries with a human readeable version suffix" ON)
option(VERSIONED_LIBRARY_LOADING
"Uses the major version (*.so.<major>) to load libraries rather then *.so" OFF)


if (BUILD_REFERENCE)
add_definitions (-DBUILD_REFERENCE=${BUILD_REFERENCE})
endif()

if(VERSIONED_LIBRARY_LOADING)
add_definitions(-DVERSIONED_LIBRARY_LOADING)
endif()

list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/common"
Expand Down Expand Up @@ -138,4 +146,3 @@ endif()
add_subdirectory(Source)

add_subdirectory(Tests)

29 changes: 15 additions & 14 deletions Source/Thunder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ find_package(Threads REQUIRED)
get_filename_component(TARGET ${CMAKE_CURRENT_SOURCE_DIR} NAME)

set(THREADPOOL_COUNT "4" CACHE STRING "The number of threads in the thread pool")
set(ENABLE_INITSCRIPT_SUPPORT ON CACHE STRING "Enable init script(systemd/initd) install support from the thunder source tree")
set(ENABLE_TRACING_MODULES "" CACHE STRING "A space separated list of specific tracing modules to be enabled at start.")

add_executable(${TARGET}
Expand All @@ -41,19 +40,23 @@ target_compile_definitions(${TARGET}

target_compile_options (${TARGET} PRIVATE -Wno-psabi)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/generated/version/version.h" @ONLY)
message(STATUS "Generated ${CMAKE_CURRENT_BINARY_DIR}/generated/version/version.h")

if (TREE_REFERENCE)
target_compile_definitions(${TARGET}
PRIVATE
PRIVATE
-DTREE_REFERENCE=${TREE_REFERENCE}
)
endif()

target_include_directories( ${TARGET}
target_include_directories(${TARGET}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../plugins/generated/jsonrpc>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated>
)


if (EXCEPTION_CATCHING)
set_source_files_properties( PluginServer.cpp PROPERTIES COMPILE_FLAGS "-fexceptions" )
endif()
Expand Down Expand Up @@ -95,24 +98,22 @@ set_target_properties(${TARGET} PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
FRAMEWORK FALSE
VERSION ${VERSION}
VERSION ${Thunder_VERSION}
)

install(
TARGETS ${TARGET} EXPORT ${TARGET}Targets # for downstream dependencies
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # static lib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # shared lib
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libs # binaries
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libs # for mac
TARGETS ${TARGET} EXPORT ${TARGET}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${NAMESPACE}_Development
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${NAMESPACE}_Runtime NAMELINK_COMPONENT ${NAMESPACE}_Development
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${NAMESPACE}_Runtime
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${NAMESPACE}_Runtime
)

install(DIRECTORY
DESTINATION ${CMAKE_INSTALL_PREFIX}/../${PERSISTENT_PATH/${NAMESPACE}}
DESTINATION ${CMAKE_INSTALL_PREFIX}/../${PERSISTENT_PATH}/${NAMESPACE}}
DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE
)

if (ENABLE_INITSCRIPT_SUPPORT)
add_subdirectory(scripts)
endif()
add_subdirectory(scripts)

include(GenericConfig.cmake)
4 changes: 2 additions & 2 deletions Source/Thunder/GenericConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ map()
key(tracing)
endif()
key(version)
val(${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION})
val(${Thunder_VERSION_MAJOR}.${Thunder_VERSION_MINOR}.${Thunder_VERSION_PATCH})
end()
ans(CONFIG)

Expand Down Expand Up @@ -286,7 +286,7 @@ install(
FILES ${CMAKE_BINARY_DIR}/Config.json
DESTINATION ../${CMAKE_INSTALL_SYSCONFDIR}/${NAMESPACE}/
RENAME config.json
COMPONENT ${MODULE_NAME})
COMPONENT ${NAMESPACE}_Runtime)
else()
find_package(ConfigGenerator REQUIRED)

Expand Down
8 changes: 1 addition & 7 deletions Source/Thunder/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@
#define TREE_REFERENCE engineering_build_for_debug_purpose_only
#endif

namespace Thunder {
namespace PluginHost {
static constexpr uint8_t Major = 4;
static constexpr uint8_t Minor = 0;
static constexpr uint8_t Patch = 0;
}
}
#include <version/version.h>

#undef EXTERNAL
#define EXTERNAL
2 changes: 1 addition & 1 deletion Source/Thunder/Thunder.conf.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = '@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_REVISION@'
version = '@Thunder_VERSION_MAJOR@.@Thunder_VERSION_MINOR@.@Thunder_VERSION_PATCH@'
port = '@PORT@'
binding = '@BINDING@'
ipv6 = '@IPV6_SUPPORT@'
Expand Down
14 changes: 14 additions & 0 deletions Source/Thunder/Version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/***
* DO NOT EDIT, THIS FILE IS GENERATED @ @BUILD_TIMESTAMP@
*/

#pragma once

namespace Thunder
{
namespace PluginHost {
static constexpr uint8_t Major = @Thunder_VERSION_MAJOR@;
static constexpr uint8_t Minor = @Thunder_VERSION_MINOR@;
static constexpr uint8_t Patch = @Thunder_VERSION_PATCH@;
}
}
41 changes: 21 additions & 20 deletions Source/Thunder/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,36 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set(SYSTEMD_SERVICE "false" CACHE STRING "Select systemd service scripts, by default it install initv scripts")
set(SYSTEM_ROOT_PATH "root" CACHE STRING "System root directory location")
option(SYSTEMD_SERVICE "Install the systemd service" OFF)
option(INITV_SCRIPT "Install the initv script" ON)

if (SYSTEMD_SERVICE)
file(READ thunder.service.in THUNDER_SYSTEMD_SERVICE)
string(
REGEX REPLACE "EXTRA_DEPENDS" "${SYSTEMD_EXTRA_DEPENDS}"
MOD_THUNDER_SYSTEMD_SERVICE "${THUNDER_SYSTEMD_SERVICE}"
)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/thunder.service "${MOD_THUNDER_SYSTEMD_SERVICE}")
set(SYSTEMD_EXTRA_DEPENDS "" CACHE STRING "Adds extra dependecies to the systemd service")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/thunder.service.in" "${CMAKE_CURRENT_BINARY_DIR}/generated/thunder.service" @ONLY)

install(DIRECTORY DESTINATION ${CMAKE_INSTALL_PREFIX}/../${CMAKE_INSTALL_LIBDIR})
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/thunder.service
FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/thunder.service
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION ${CMAKE_INSTALL_PREFIX}/../${SYSTEMD_INSTALL_PATH}/system/
)
else()
file(READ thunder.in THUNDER_INITD)
string(
REGEX REPLACE "ROOT_PATH" "${SYSTEM_ROOT_PATH}/${NAMESPACE}"
MOD_THUNDER_INITD "${THUNDER_INITD}"
DESTINATION ${CMAKE_INSTALL_PREFIX}/../${SYSTEMD_INSTALL_PATH}/system/
COMPONENT ${NAMESPACE}_Runtime
)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/thunder "${MOD_THUNDER_INITD}")

endif()

if (INITV_SCRIPT)
set(SYSV_INIT_LEVEL "80" CACHE STRING "Level of the initv start script")
set(SYSTEM_ROOT_PATH "/root" CACHE STRING "System root directory location")
set(ROOT_PATH "${SYSTEM_ROOT_PATH}/${NAMESPACE}" CACHE STRING "Thunders root path")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/thunder.in" "${CMAKE_CURRENT_BINARY_DIR}/generated/thunder" @ONLY)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/thunder
FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/thunder
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION ../${CMAKE_INSTALL_SYSCONFDIR}/init.d/
RENAME S${SYSV_INIT_LEVEL}thunder
DESTINATION ../${CMAKE_INSTALL_SYSCONFDIR}/init.d/
COMPONENT ${NAMESPACE}_Runtime
)
endif()

10 changes: 5 additions & 5 deletions Source/Thunder/scripts/thunder.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ start() {
# Core dumps
#echo 1 > /proc/sys/kernel/core_uses_pid
#echo 2 > /proc/sys/fs/suid_dumpable
#echo "/ROOT_PATH/cores/core-pid_%p--process%E" > /proc/sys/kernel/core_pattern
#mkdir -p /ROOT_PATH/cores
#echo "@ROOT_PATH@/cores/core-pid_%p--process%E" > /proc/sys/kernel/core_pattern
#mkdir -p @ROOT_PATH@/cores
#ulimit -c unlimited

if [ ! -d /ROOT_PATH/Netflix/dpi ]; then
mkdir -p /ROOT_PATH/Netflix/dpi
ln -sfn /etc/playready /ROOT_PATH/Netflix/dpi/playready
if [ ! -d @ROOT_PATH@/Netflix/dpi ]; then
mkdir -p @ROOT_PATH@/Netflix/dpi
ln -sfn /etc/playready @ROOT_PATH@/Netflix/dpi/playready
fi

# needed for wayland/westeros/weston
Expand Down
2 changes: 1 addition & 1 deletion Source/Thunder/scripts/thunder.service.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=thunder
Wants=multi-user.target
After=multi-user.target EXTRA_DEPENDS
After=multi-user.target @EXTRA_DEPENDS@

[Service]
PIDFile=/var/run/Thunder.pid
Expand Down
19 changes: 12 additions & 7 deletions Source/ThunderPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,19 @@ set_target_properties(${TARGET} PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
FRAMEWORK FALSE
VERSION ${VERSION}
SOVERSION ${VERSION_MAJOR}
SOVERSION ${Thunder_VERSION_MAJOR}
)

if(HUMAN_VERSIONED_BINARIES)
set_target_properties(${TARGET} PROPERTIES
VERSION ${Thunder_VERSION}
)
endif()

install(
TARGETS COMProcess ${TARGET} EXPORT ${TARGET}Targets # for downstream dependencies
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # static lib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # shared lib
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libs # binaries
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libs # for mac
TARGETS COMProcess ${TARGET} EXPORT ${TARGET}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${NAMESPACE}_Development
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${NAMESPACE}_Runtime NAMELINK_COMPONENT ${NAMESPACE}_Development
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${NAMESPACE}_Runtime
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${NAMESPACE}_Runtime
)
8 changes: 7 additions & 1 deletion Source/ThunderPlugin/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,16 @@ class ProcessFlow {
uint32_t result;
uint32_t waitTime (RPC::CommunicationTimeOut != Core::infinite ? 2 * RPC::CommunicationTimeOut : RPC::CommunicationTimeOut);

#ifdef VERSIONED_LIBRARY_LOADING
static const std::string suffixFilter = "*.so." + std::to_string(THUNDER_VERSION);
#else
static const std::string suffixFilter = ".so";
#endif

TRACE_L1("Loading ProxyStubs from %s", (pathName.empty() == false ? pathName.c_str() : _T("<< No Proxy Stubs Loaded >>")));

if (pathName.empty() == false) {
Core::Directory index(pathName.c_str(), _T("*.so"));
Core::Directory index(pathName.c_str(), _T(suffixFilter.c_str()));

while (index.Next() == true) {
Core::Library library(index.Current().c_str());
Expand Down
22 changes: 13 additions & 9 deletions Source/com/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,23 @@ set_target_properties(${TARGET} PROPERTIES
CXX_STANDARD_REQUIRED YES
FRAMEWORK FALSE
PUBLIC_HEADER "${PUBLIC_HEADERS}" # specify the public headers
VERSION ${VERSION}
SOVERSION ${VERSION_MAJOR}
SOVERSION ${Thunder_VERSION_MAJOR}
)

if(HUMAN_VERSIONED_BINARIES)
set_target_properties(${TARGET} PROPERTIES
VERSION ${Thunder_VERSION}
)
endif()

install(
TARGETS ${TARGET} EXPORT ${TARGET}Targets # for downstream dependencies
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # static lib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libs # shared lib
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libs # binaries
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libs # for mac
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${NAMESPACE}/com COMPONENT devel # headers for mac (note the different component -> different package)
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${NAMESPACE} # default include path
TARGETS ${TARGET} EXPORT ${TARGET}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${NAMESPACE}_Development
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${NAMESPACE}_Runtime NAMELINK_COMPONENT ${NAMESPACE}_Development
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${NAMESPACE}_Runtime
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${NAMESPACE}_Runtime
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${NAMESPACE}/com COMPONENT ${NAMESPACE}_Development
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${NAMESPACE}
)

InstallCMakeConfig(TARGETS ${TARGET})
8 changes: 7 additions & 1 deletion Source/com/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,14 @@ namespace RPC {

Core::TextSegmentIterator places(Core::TextFragment(pathName), false, '|');

#ifdef VERSIONED_LIBRARY_LOADING
static const std::string suffixFilter = "*.so." + std::to_string(THUNDER_VERSION);
#else
static const std::string suffixFilter = ".so";
#endif

while (places.Next() == true) {
Core::Directory index(places.Current().Text().c_str(), _T("*.so"));
Core::Directory index(places.Current().Text().c_str(), _T(suffixFilter.c_str()));

while (index.Next() == true) {
// Check if this ProxySTub file is already loaded in this process space..
Expand Down
Loading

0 comments on commit be5d9c1

Please sign in to comment.