Skip to content

Commit

Permalink
Development/static libraries (#1397)
Browse files Browse the repository at this point in the history
* CMake: rely on "BUILD_SHARED_LIBS" to control lib type

* CMake: limit dependency lookup

* PrivilegedRequest: fix mktemp warning

* CMake: add communicator option

* COM: Typo's in comments

* Core: fix multiple definition of kContextMaxLength

* cmake: move to CMAKE_CURRENT_SOURCE_DIR

* Core: Forgot to delete something

* cmake:  always build shared objects by default

* testing: explicitly define we want shared objects

* docs: explicitly define to build shared objects

* workflows: add flow to build archives

* workflows: humans need to read this..

* cmake: set define if shared objects are build

* cmake: return Module.cpp back into the build, archive ready

* PrivilegedRequest: fix example

* workflows: seems like workflows are smarter then I thought.

* cmake: move find_packages back to there initial location

* workflow: only save artifacts if shared libs is on

* workflow: add expression for shared_lib flag

* workflow: add expression for shared_lib flag

* tests: add independent test lib for Core::Library

* tests: fix `empty parentheses were disambiguated`

* cmake: remove redundant code

---------

Co-authored-by: Pierre Wielders <[email protected]>
  • Loading branch information
bramoosterhuis and pwielders authored Sep 5, 2023
1 parent 0e7cc56 commit fc31390
Show file tree
Hide file tree
Showing 29 changed files with 143 additions and 101 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/Build Thunder on Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:
strategy:
matrix:
build_type: [Debug, Release, MinSizeRel]
shared_libs: [ON, OFF]

name: Build type - ${{matrix.build_type}}
name: Build type - ${{matrix.shared_libs == 'OFF' && 'Static ' || ''}}${{matrix.build_type}}
steps:
# ----- Thunder -----
- name: Checkout Thunder - default
Expand Down Expand Up @@ -100,6 +101,7 @@ jobs:
run: |
cmake -G Ninja -S Thunder -B ${{matrix.build_type}}/build/Thunder \
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror" \
-DBUILD_SHARED_LIBS=${{matrix.shared_libs}} \
-DBINDING="127.0.0.1" \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_INSTALL_PREFIX="${{matrix.build_type}}/install/usr" \
Expand All @@ -116,9 +118,11 @@ jobs:
cmake --build ${{matrix.build_type}}/build/Thunder --target install
- name: Tar files
if: matrix.shared_libs == 'ON'
run: tar -czvf ${{matrix.build_type}}.tar.gz ${{matrix.build_type}}

- name: Upload
if: matrix.shared_libs == 'ON'
uses: actions/upload-artifact@v3
with:
name: Thunder-${{matrix.build_type}}-artifact
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/Test Thunder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ jobs:
strategy:
matrix:
build_type: [Debug, Release, MinSizeRel]
shared_libs: [ON, OFF]

env:
lib: LD_LIBRARY_PATH=${{github.workspace}}/${{matrix.build_type}}/install/usr/lib:$LD_LIBRARY_PATH
path: PATH=${{github.workspace}}/${{matrix.build_type}}/install/usr/bin:$PATH

name: Testing - ${{matrix.build_type}}
name: Testing - ${{matrix.shared_libs == 'OFF' && 'Static ' || ''}}${{matrix.build_type}}
steps:
# ----- Thunder -----
- name: Checkout Thunder - default
Expand Down Expand Up @@ -95,6 +96,7 @@ jobs:
cmake -G Ninja -S Thunder -B ${{matrix.build_type}}/build/Thunder \
-DBINDING="127.0.0.1" \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DBUILD_SHARED_LIBS=${{matrix.shared_libs}} \
-DCMAKE_INSTALL_PREFIX="${{matrix.build_type}}/install/usr" \
-DCMAKE_MODULE_PATH="${PWD}/${{matrix.build_type}}/install/usr/include/WPEFramework/Modules" \
-DDATA_PATH="${PWD}/${{matrix.build_type}}/install/usr/share/WPEFramework" \
Expand All @@ -113,10 +115,10 @@ jobs:
run: ${{env.path}} ${{env.lib}} WPEFramework_test_core

- name: Tar files
run: tar -czvf ${{matrix.build_type}}.tar.gz ${{matrix.build_type}}
run: tar -czvf ${{matrix.shared_libs == 'OFF' && 'Static-' || ''}}${{matrix.build_type}}.tar.gz ${{matrix.build_type}}

- name: Upload
uses: actions/upload-artifact@v3
with:
name: Thunder-${{matrix.build_type}}-artifact
path: ${{matrix.build_type}}.tar.gz
name: Thunder-${{matrix.shared_libs == 'OFF' && 'Static-' || ''}}${{matrix.build_type}}-artifact
path: ${{matrix.shared_libs == 'OFF' && 'Static-' || ''}}${{matrix.build_type}}.tar.gz
31 changes: 12 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,16 @@ option(LEGACY_CONFIG_GENERATOR
If switched OFF, plugins need to use the new python-based templates. (*.conf.in)" ON)
option(BUILD_PLUGIN_ACTIVATOR
"Build the standalone plugin activator utility to activate plugins using systemd" OFF)
option(BUILD_LIB_AS_STATIC "Create thunder libraries Core, WebSocket and Cryptalgo as static library" OFF)

if (BUILD_LIB_AS_STATIC)
set(THUNDER_LIBRARY_TYPE STATIC)
else ()
set(THUNDER_LIBRARY_TYPE SHARED)
endif()

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

list(APPEND CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/cmake"
"${CMAKE_SOURCE_DIR}/cmake/common"
"${CMAKE_SOURCE_DIR}/cmake/modules"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/common"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
"${CMAKE_SYSROOT}${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}/Modules")

if (TOOLS_SYSROOT)
Expand All @@ -71,6 +65,11 @@ find_package(ProxyStubGenerator REQUIRED)
find_package(JsonGenerator REQUIRED)
find_package(ConfigGenerator REQUIRED)

if(NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON CACHE INTERNAL "Enable shared objects by default")
message(STATUS "BUILD_SHARED_LIBS was not set, assuming ${BUILD_SHARED_LIBS}")
endif()

#
# Build type specific options
#
Expand Down Expand Up @@ -103,7 +102,7 @@ string(REGEX REPLACE "-D_FORTIFY_SOURCE=[0-3]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_F
string(REGEX REPLACE "-D_FORTIFY_SOURCE=[0-3]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

# make sure others can make use of the JSON creation tools as well!!!
configure_file( "${CMAKE_SOURCE_DIR}/cmake/project.cmake.in"
configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/project.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${NAMESPACE}.cmake"
@ONLY)

Expand All @@ -113,20 +112,14 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${NAMESPACE}.cmake"

if(CMAKE_VERSION VERSION_LESS 3.20.0 AND LEGACY_CONFIG_GENERATOR)
install(DIRECTORY
"${CMAKE_SOURCE_DIR}/cmake/config"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/config"
DESTINATION lib/cmake/${NAMESPACE})
endif(CMAKE_VERSION VERSION_LESS 3.20.0 AND LEGACY_CONFIG_GENERATOR)

install(DIRECTORY
"${CMAKE_SOURCE_DIR}/cmake/common"
"${CMAKE_SOURCE_DIR}/cmake/templates"
DESTINATION lib/cmake/${NAMESPACE})

if (BUILD_LIB_AS_STATIC)
install(DIRECTORY
"${CMAKE_SOURCE_DIR}/cmake/modules"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/common"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates"
DESTINATION lib/cmake/${NAMESPACE})
endif ()

if(APPLE)
# Mac needed variables
Expand Down
5 changes: 0 additions & 5 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ set(EXTERN_EVENTS ${EXTERN_EVENTS} CACHE INTERNAL
string(REPLACE " " ";" EXTERN_EVENT_LIST "${EXTERN_EVENTS}")
message(STATUS "Assuming external events: ${EXTERN_EVENT_LIST}")

find_package(ZLIB REQUIRED)
find_package(Threads REQUIRED)
find_package(ExecInfo)
find_package(LIBRT)

if(CORE)
add_subdirectory(core)
endif()
Expand Down
3 changes: 2 additions & 1 deletion Source/WPEFramework/GenericConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set(EXIT_REASONS "Failure;MemoryExceeded;WatchdogExpired" CACHE STRING "Process
set(ETHERNETCARD_NAME "eth0" CACHE STRING "Ethernet Card name which has to be associated for the Raw Device Id creation")
set(GROUP "" CACHE STRING "Define which system group will be used")
set(UMASK "" CACHE STRING "Set the permission mask for the creation of new files. e.g. 0760")
set(COMMUNICATOR "" CACHE STRING "Define the ComRPC socket e.g. 127.0.0.1:62000 or /tmp/communicator|750")

# Controller Plugin Settings.
set(PLUGIN_CONTROLLER_UI_ENABLED "true" CACHE STRING "Enable the Controller's UI")
Expand Down Expand Up @@ -80,7 +81,7 @@ map_set(${CONFIG} proxystubpath ${PROXYSTUB_PATH})
map_set(${CONFIG} postmortempath ${POSTMORTEM_PATH})
map_set(${CONFIG} redirect "/Service/Controller/UI")
map_set(${CONFIG} ethernetcard ${ETHERNETCARD_NAME})
if(COMMUNICATOR)
if(NOT COMMUNICATOR STREQUAL "")
map_set(${CONFIG} communicator ${COMMUNICATOR})
endif()

Expand Down
6 changes: 3 additions & 3 deletions Source/com/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ set(TARGET ${NAMESPACE}COM)

ProxyStubGenerator(NAMESPACE "WPEFramework::RPC" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/ICOM.h" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated")

add_library(${TARGET} SHARED
add_library(${TARGET}
Module.cpp
Administrator.cpp
Communicator.cpp
IUnknown.cpp
ConnectorType.cpp
Module.cpp
${CMAKE_CURRENT_BINARY_DIR}/generated/ProxyStubs_COM.cpp
)

set(PUBLIC_HEADERS
Administrator.h
com.h
Expand Down
8 changes: 4 additions & 4 deletions Source/com/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ namespace RPC {
{
string value;

uint16_t length = sizeof(Core::instance_id) + sizeof(uint32_t) + sizeof(Output::mode); // skip implentation and sequencenumber
uint16_t length = sizeof(Core::instance_id) + sizeof(uint32_t) + sizeof(Output::mode); // skip implementation and sequence number

_data.GetText(length, value);

Expand All @@ -420,7 +420,7 @@ namespace RPC {
{
string value;

uint16_t length = sizeof(Core::instance_id) + sizeof(uint32_t) + sizeof(Output::mode); // skip implentation and sequencenumber
uint16_t length = sizeof(Core::instance_id) + sizeof(uint32_t) + sizeof(Output::mode); // skip implementation and sequence number
length += _data.GetText(length, value); // skip proxyStub path

_data.GetText(length, value);
Expand All @@ -431,9 +431,9 @@ namespace RPC {
{
string value;

uint16_t length = sizeof(Core::instance_id) + sizeof(uint32_t) + sizeof(Output::mode); // skip implentation and sequencenumber
uint16_t length = sizeof(Core::instance_id) + sizeof(uint32_t) + sizeof(Output::mode); // skip implementation and sequence number
length += _data.GetText(length, value); // skip proxyStub path
length += _data.GetText(length, value); // skip messagingcategories
length += _data.GetText(length, value); // skip messaging categories

_data.GetText(length, value);

Expand Down
4 changes: 4 additions & 0 deletions Source/com/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
*/
#include "Module.h"

#ifdef BUILD_SHARED_LIBS
MODULE_NAME_DECLARATION(BUILD_REFERENCE)
#else
MODULE_NAME_ARCHIVE_DECLARATION
#endif
16 changes: 9 additions & 7 deletions Source/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
set(TARGET ${NAMESPACE}Core)
include(CompileSettings)

add_library(${TARGET} ${THUNDER_LIBRARY_TYPE}
DoorBell.cpp
find_package(Threads REQUIRED)
find_package(ExecInfo)
find_package(LIBRT)

add_library(${TARGET}
Module.cpp
DoorBell.cpp
CyclicBuffer.cpp
DataElement.cpp
DataElementFile.cpp
Expand Down Expand Up @@ -53,9 +58,6 @@ add_library(${TARGET} ${THUNDER_LIBRARY_TYPE}
ResourceMonitor.cpp
)

if (NOT BUILD_LIB_AS_STATIC)
target_sources(${TARGET} PRIVATE Module.cpp)
endif()

#TODO: Remove all non public headers from this list,
# All the interface headers are here, these will be installed to staging
Expand Down Expand Up @@ -228,10 +230,10 @@ set_target_properties(${TARGET} PROPERTIES
SOVERSION ${VERSION_MAJOR}
)

if (BUILD_LIB_AS_STATIC)
if (NOT BUILD_SHARED_LIBS)
set_property(TARGET ${TARGET}
APPEND PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE ON
)
)
endif()


Expand Down
1 change: 0 additions & 1 deletion Source/core/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace Core {
return msg;
}

/* static */ constexpr size_t Error::kContextMaxLength;

/* static */ char IElement::NullTag[5] = { 'n', 'u', 'l', 'l', '\0' };
/* static */ char IElement::TrueTag[5] = { 't', 'r', 'u', 'e', '\0' };
Expand Down
5 changes: 2 additions & 3 deletions Source/core/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace WPEFramework {
namespace Core {

namespace JSON {

constexpr size_t kContextMaxLength = 80;

struct EXTERNAL Error {
explicit Error(string&& message)
: _message(std::move(message))
Expand Down Expand Up @@ -74,8 +75,6 @@ namespace Core {
{
}

static constexpr size_t kContextMaxLength = 80;

string _message;
string _context;
size_t _pos;
Expand Down
4 changes: 4 additions & 0 deletions Source/core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
#include "Module.h"
#include "SystemInfo.h"

#ifdef BUILD_SHARED_LIBS
MODULE_NAME_DECLARATION(BUILD_REFERENCE)
#else
MODULE_NAME_ARCHIVE_DECLARATION
#endif
8 changes: 2 additions & 6 deletions Source/cryptalgo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@

set(TARGET ${NAMESPACE}Cryptalgo)

add_library(${TARGET} ${THUNDER_LIBRARY_TYPE}
add_library(${TARGET}
Module.cpp
AES.cpp
AESImplementation.cpp
Hash.cpp
Module.cpp
Random.cpp
)

if (NOT BUILD_LIB_AS_STATIC)
target_sources(${TARGET} PRIVATE Module.cpp)
endif()

set(PUBLIC_HEADERS
AES.h
AESImplementation.h
Expand Down
8 changes: 6 additions & 2 deletions Source/cryptalgo/Module.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
Expand All @@ -16,7 +16,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "Module.h"

#ifdef BUILD_SHARED_LIBS
MODULE_NAME_DECLARATION(BUILD_REFERENCE)
#else
MODULE_NAME_ARCHIVE_DECLARATION
#endif
25 changes: 17 additions & 8 deletions Source/extensions/privilegedrequest/example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "privilegedrequest/PrivilegedRequest.h"

MODULE_NAME_DECLARATION(BUILD_REFERENCE)

using namespace WPEFramework;

constexpr char fileNameTemplate[] = "/tmp/shared_file_test_XXXXXX";
Expand Down Expand Up @@ -61,20 +63,27 @@ class Server : public Core::PrivilegedRequest {
char tmpfile[sizeof(fileNameTemplate) + 1];
strcpy(tmpfile, fileNameTemplate);

_sharedFiles.emplace_back(mktemp(tmpfile));
int fd = mkstemp(tmpfile); // creates a temp file and the generated filename is written in tmpfile

Core::File& newFile = _sharedFiles.back();
_sharedFiles.emplace_back(tmpfile);

newFile.Create();
newFile.Open(false);
if (fd > 0) {
close(fd);

printf("Server opened shared file [%d] %s\n", int(newFile), newFile.FileName().c_str());
Core::File& newFile = _sharedFiles.back();

std::stringstream line;
newFile.Open(false);

printf("Server opened shared file [%d] %s\n", int(newFile), newFile.FileName().c_str());

line << "(" << Core::Time::Now().Ticks() << ") opened from PID=" << getpid() << "!" << std::endl;
std::stringstream line;

newFile.Write(reinterpret_cast<const uint8_t*>(line.str().c_str()), line.str().size());
line << "(" << Core::Time::Now().Ticks() << ") opened from PID=" << getpid() << "!" << std::endl;

newFile.Write(reinterpret_cast<const uint8_t*>(line.str().c_str()), line.str().size());
} else {
printf("Failed to create shared file: %s\n", strerror(errno));
}
}

printf("Server for %d file%s\n", nFiles, (nFiles == 1) ? "" : "s");
Expand Down
Loading

0 comments on commit fc31390

Please sign in to comment.