Skip to content

Commit 14ea42c

Browse files
committed
[install] Generate install targets + pkg-config files
1 parent 48a8e66 commit 14ea42c

File tree

6 files changed

+215
-75
lines changed

6 files changed

+215
-75
lines changed

CMakeLists.txt

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
cmake_minimum_required(VERSION 3.13)
66

7-
project(OpenOCPP)
7+
project(OpenOCPP DESCRIPTION "Open Source C++ implementation of the OCPP 1.6 protocol"
8+
VERSION 0.5.0
9+
)
810

911
# Build options
1012
include(CMakeLists_Options.txt)
@@ -22,7 +24,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2224
add_subdirectory(3rdparty)
2325

2426
# OpenSSL is mandatory
25-
find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
27+
find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
2628

2729
# Tests
2830
if(${BUILD_UNIT_TESTS})
@@ -39,6 +41,88 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BIN_DIR})
3941
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BIN_DIR})
4042
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR})
4143

42-
# Subdirectories
43-
add_subdirectory(examples)
44+
# Examples
45+
if(${BUILD_EXAMPLES})
46+
add_subdirectory(examples)
47+
endif()
48+
49+
# Open OCPP library sources
4450
add_subdirectory(src)
51+
52+
# Open OCPP static library
53+
add_library(open-ocpp-static STATIC
54+
src/version.cpp)
55+
target_link_libraries(open-ocpp-static
56+
centralsystem
57+
chargepoint
58+
config
59+
database
60+
messages
61+
rpc
62+
helpers
63+
log
64+
version
65+
x509
66+
json
67+
ws
68+
websockets
69+
70+
dl
71+
)
72+
set_target_properties(open-ocpp-static PROPERTIES OUTPUT_NAME "open-ocpp_static")
73+
74+
# Open OCPP dynamic library
75+
add_library(open-ocpp-dynamic SHARED
76+
src/version.cpp)
77+
target_link_libraries(open-ocpp-dynamic
78+
centralsystem
79+
chargepoint
80+
config
81+
database
82+
messages
83+
rpc
84+
helpers
85+
log
86+
version
87+
x509
88+
json
89+
ws
90+
websockets
91+
92+
dl
93+
)
94+
set_target_properties(open-ocpp-dynamic PROPERTIES OUTPUT_NAME "open-ocpp")
95+
96+
# Install commands
97+
include(GNUInstallDirs)
98+
99+
file(GLOB_RECURSE PUBLIC_HEADERS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.h")
100+
101+
install(TARGETS open-ocpp-static open-ocpp-dynamic
102+
EXPORT LibOpenOcppTargets
103+
104+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
105+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
106+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
107+
)
108+
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openocpp)
109+
110+
# Generate pkgconfig files
111+
set(PKG_CONFIG_LIBDIR "\${prefix}/lib")
112+
set(PKG_CONFIG_INCLUDEDIR "\${prefix}/openocpp")
113+
set(PKG_CONFIG_LIBS "-L\${libdir}")
114+
set(PKG_CONFIG_CFLAGS "-I\${includedir}")
115+
116+
set(LIB_NAME "open-ocpp")
117+
configure_file(
118+
"${CMAKE_CURRENT_SOURCE_DIR}/libopen-ocpp.pc.in"
119+
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp.pc"
120+
)
121+
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
122+
123+
set(LIB_NAME "open-ocpp_static")
124+
configure_file(
125+
"${CMAKE_CURRENT_SOURCE_DIR}/libopen-ocpp.pc.in"
126+
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp_static.pc"
127+
)
128+
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp_static.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

CMakeLists_Options.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
#################################################################################
44

55
# Log level (0 = All logs, 5 = No logs)
6-
add_compile_definitions(LOG_LEVEL=1)
6+
if(NOT DEFINED LOG_LEVEL)
7+
set(LOG_LEVEL 1)
8+
endif()
9+
add_compile_definitions(LOG_LEVEL=${LOG_LEVEL})
710

811
# Unit tests
9-
set(BUILD_UNIT_TESTS ON)
12+
if(NOT DEFINED BUILD_UNIT_TESTS)
13+
set(BUILD_UNIT_TESTS ON)
14+
endif()
15+
16+
# Examples
17+
if(NOT DEFINED BUILD_EXAMPLES)
18+
set(BUILD_EXAMPLES ON)
19+
endif()

README.md

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,41 @@ This implementation is based on the following libraries :
1212

1313
## Table of contents
1414

15-
* [Features](#features)
16-
+ [Key features](#key-features)
17-
+ [Supported OCPP feature profiles](#supported-ocpp-feature-profiles)
18-
+ [Supported OCPP configuration keys](#supported-ocpp-configuration-keys)
19-
+ [OCPP security extensions](#ocpp-security-extensions)
20-
* [Internal configuration keys](#internal-configuration-keys)
21-
* [Build](#build)
22-
* [Quick start](#quick-start)
23-
+ [Charge Point role](#charge-point-role)
24-
+ [Central System role](#central-system-role)
25-
* [Contributing](#contributing)
26-
* [Examples](./examples/README.md)
15+
- [Open OCPP](#open-ocpp)
16+
- [Table of contents](#table-of-contents)
17+
- [Features](#features)
18+
- [Key features](#key-features)
19+
- [Supported OCPP feature profiles](#supported-ocpp-feature-profiles)
20+
- [Supported OCPP configuration keys](#supported-ocpp-configuration-keys)
21+
- [OCPP security extensions](#ocpp-security-extensions)
22+
- [Security profiles](#security-profiles)
23+
- [Security events](#security-events)
24+
- [Extended trigger messages](#extended-trigger-messages)
25+
- [Certificate management](#certificate-management)
26+
- [Signed firmware update](#signed-firmware-update)
27+
- [Internal configuration keys](#internal-configuration-keys)
28+
- [Common keys](#common-keys)
29+
- [Charge Point keys](#charge-point-keys)
30+
- [Central System keys](#central-system-keys)
31+
- [Build](#build)
32+
- [Pre-requisites](#pre-requisites)
33+
- [Build options](#build-options)
34+
- [Install and use](#install-and-use)
35+
- [Installation](#installation)
36+
- [Use with CMake](#use-with-cmake)
37+
- [Quick start](#quick-start)
38+
- [Charge Point role](#charge-point-role)
39+
- [Configuration interface](#configuration-interface)
40+
- [Event handler interface](#event-handler-interface)
41+
- [Charge Point object](#charge-point-object)
42+
- [Central System role](#central-system-role)
43+
- [Configuration interface](#configuration-interface-1)
44+
- [Event handler interfaces](#event-handler-interfaces)
45+
- [Central System object](#central-system-object)
46+
- [Contributing](#contributing)
47+
- [Coding rules](#coding-rules)
48+
- [Issues](#issues)
49+
- [Workflow](#workflow)
2750

2851
## Features
2952

@@ -142,15 +165,15 @@ In the "Owner" column, "S" means that the configuration key behavior is handled
142165
* 2 : TLS with HTTP Basic Authentication
143166
* 3 : TLS with Client Side Certificates
144167

145-
In Charge Point role, the stack will automatically disconnect and then reconnect using the new parameters to the Central System after one of the following parameters has been modified :
168+
In Charge Point role, the stack will automatically disconnect and then reconnect using the new parameters to the Central System after one of the following parameters has been modified :
146169
* **AuthorizationKey**
147170
* **Security Profile**
148171

149172
**Restriction** : The automatic fallback to old connection parameters if the connection fails after switching to a new security is not implemented yet.
150173

151174
#### Security events
152175

153-
**Open OCPP** support the whole use cases of security events and logging.
176+
**Open OCPP** support the whole use cases of security events and logging.
154177

155178
In Charge Point role, it can optionnaly handle the storage of the security event log and the generation of the security log export when the Central System asks it. To enable/disable this feature, you have to modify the **SecurityLogMaxEntriesCount** charge point configuration key :
156179

@@ -167,7 +190,7 @@ In Charge Point role, the notification of security events can be enabled or disa
167190

168191
#### Certificate management
169192

170-
**Open OCPP** support this feature for both Charge Point and Central System roles.
193+
**Open OCPP** support this feature for both Charge Point and Central System roles.
171194

172195
The behavior of this feature is controlled by the **InternalCertificateManagementEnabled** configuration key.
173196

@@ -302,6 +325,45 @@ And to run the unit tests :
302325

303326
```make tests-gcc-native``` or ```make tests-clang-native```
304327

328+
The build generates 2 flavors of the **Open OCPP** librairies depending on the needs of your project :
329+
* Shared : libopen-ocpp.so
330+
* Static : libopen-ocpp_static.a
331+
332+
**Note**: When using **Open OCPP** in a non GNU LGPL project, the shared library must be used in order to not contaminate your project with the LGPL licence.
333+
334+
## Install and use
335+
### Installation
336+
337+
**Open OCPP** generated libraries and their includes can be installed in the standard system directories using the CMake command :
338+
339+
```cmake --install [build_dir] --strip```
340+
341+
The makefile contains helper targets which can be called if the installation needs to be done in a non standard directory using the variable INSTALL_PREFIX :
342+
343+
```make install-gcc-native INSTALL_PREFIX=/your/directory``` or ```make install-clang-native INSTALL_PREFIX=/your/directory```
344+
345+
If run without the INSTALL_PREFIX variable, it will install in the standard system directories.
346+
347+
**Note**: If INSTALL_PREFIX is used, it must also be defined when building the project with the makefile helper targets.
348+
349+
### Use with CMake
350+
351+
**Open OCPP** installs 2 pkg-config configurations files to ease the use of the library when compiling a CMake project.
352+
353+
To import the library in a CMake project, use the following commands in your CMakeLists.txt file :
354+
355+
```
356+
find_package(PkgConfig)
357+
pkg_search_module(PKG_OPEN_OCPP REQUIRED IMPORTED_TARGET libopen-ocpp)
358+
pkg_search_module(PKG_OPEN_OCPP_STATIC REQUIRED IMPORTED_TARGET libopen-ocpp_static)
359+
```
360+
361+
Then you wil be able to use the following targets as dependencies for your project :
362+
363+
```target_link_libraries(my_proj PRIVATE PkgConfig::PKG_OPEN_OCPP)``` or ```target_link_libraries(my_proj PRIVATE PkgConfig::PKG_OPEN_OCPP_STATIC)```
364+
365+
**Note**: If **Open OCPP** has been installed in a non standard directory, the search path for the ```pkg_search_module``` command must be specified using the following command => ```set(ENV{PKG_CONFIG_PATH} "/your/directory/containing/the/.pc/files")```
366+
305367
## Quick start
306368

307369
The best way to start is to take a look at the [examples](./examples/README.md) and more specifically at the [quick start Charge Point example](./examples/quick_start_chargepoint/README.md) and the [quick start Central System example](./examples/quick_start_centralsystem/README.md).

libopen-ocpp.pc.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Name: lib${LIB_NAME}
2+
Description: ${PROJECT_DESCRIPTION}
3+
Version: ${PROJECT_VERSION}
4+
prefix=${CMAKE_INSTALL_PREFIX}
5+
includedir=${PKG_CONFIG_INCLUDEDIR}
6+
libdir=${PKG_CONFIG_LIBDIR} -l${LIB_NAME}
7+
Libs: ${PKG_CONFIG_LIBS}
8+
Cflags: ${PKG_CONFIG_CFLAGS}

makefile

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,36 @@
33
######################################################
44

55
# Root directory containing the top level CMakeLists.txt file
6-
ROOT_DIR=$(PWD)
6+
ROOT_DIR:=$(PWD)
77

88
# Generated binary directory
9-
BIN_DIR=$(ROOT_DIR)/bin
9+
BIN_DIR:=$(ROOT_DIR)/bin
1010

1111
# Make options
1212
#VERBOSE="VERBOSE=1"
13-
PARALLEL_BUILD=-j 4
14-
DEBUG=ON
13+
PARALLEL_BUILD:=-j 4
14+
DEBUG:=ON
15+
16+
# Default target
17+
default: gcc-native
18+
19+
# Silent makefile if not verbose mode
20+
$(VERBOSE).SILENT:
21+
22+
# Install prefix
23+
ifneq ($(strip $(INSTALL_PREFIX)),)
24+
CMAKE_INSTALL_PREFIX:=-D CMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX)
25+
CMAKE_INSTALL_PREFIX_CMD:=--prefix $(INSTALL_PREFIX)
26+
endif
1527

1628
# Build/clean all targets
1729
all: gcc-native clang-native
1830
clean: clean-gcc-native clean-clang-native
1931
@-rm -rf $(BIN_DIR)
2032

2133
# Targets for gcc-native build
22-
GCC_NATIVE_BUILD_DIR=$(ROOT_DIR)/build_gcc_native
23-
GCC_NATIVE_BIN_DIR=$(BIN_DIR)/gcc_native
34+
GCC_NATIVE_BUILD_DIR:=$(ROOT_DIR)/build_gcc_native
35+
GCC_NATIVE_BIN_DIR:=$(BIN_DIR)/gcc_native
2436
gcc-native: $(GCC_NATIVE_BUILD_DIR)/Makefile
2537
@echo "Starting gcc-native build..."
2638
@mkdir -p $(GCC_NATIVE_BIN_DIR)
@@ -37,16 +49,20 @@ clean-gcc-native:
3749
@-rm -rf $(GCC_NATIVE_BIN_DIR)
3850
@echo "gcc-native build cleaned!"
3951

52+
install-gcc-native: gcc-native
53+
@echo "Installing Open OCPP library compiled with gcc-native..."
54+
@cmake --install $(GCC_NATIVE_BUILD_DIR) $(CMAKE_INSTALL_PREFIX_CMD) --strip
55+
4056
$(GCC_NATIVE_BUILD_DIR)/Makefile:
4157
@echo "Generating gcc-native makefiles..."
4258
@mkdir -p $(GCC_NATIVE_BUILD_DIR)
4359
@mkdir -p $(GCC_NATIVE_BIN_DIR)
44-
@cd $(GCC_NATIVE_BUILD_DIR) && export CC=gcc && export CXX=g++ && cmake -D TARGET=native -D BIN_DIR=$(GCC_NATIVE_BIN_DIR) -D DEBUG=$(DEBUG) $(ROOT_DIR)
60+
@cd $(GCC_NATIVE_BUILD_DIR) && export CC=gcc && export CXX=g++ && cmake -D TARGET=native -D BIN_DIR=$(GCC_NATIVE_BIN_DIR) -D DEBUG=$(DEBUG) $(CMAKE_INSTALL_PREFIX) $(ROOT_DIR)
4561

4662

4763
# Targets for clang-native build
48-
CLANG_NATIVE_BUILD_DIR=$(ROOT_DIR)/build_clang_native
49-
CLANG_NATIVE_BIN_DIR=$(BIN_DIR)/clang_native
64+
CLANG_NATIVE_BUILD_DIR:=$(ROOT_DIR)/build_clang_native
65+
CLANG_NATIVE_BIN_DIR:=$(BIN_DIR)/clang_native
5066
clang-native: $(CLANG_NATIVE_BUILD_DIR)/Makefile
5167
@echo "Starting clang native build..."
5268
@mkdir -p $(CLANG_NATIVE_BIN_DIR)
@@ -63,8 +79,12 @@ clean-clang-native:
6379
@-rm -rf $(CLANG_NATIVE_BIN_DIR)
6480
@echo "clang native build cleaned!"
6581

82+
install-clang-native: clang-native
83+
@echo "Installing Open OCPP library compiled with clang-native..."
84+
@cmake --install $(GCC_NATIVE_BUILD_DIR) $(CMAKE_INSTALL_PREFIX_CMD) --strip
85+
6686
$(CLANG_NATIVE_BUILD_DIR)/Makefile:
6787
@echo "Generating clang-native makefiles..."
6888
@mkdir -p $(CLANG_NATIVE_BUILD_DIR)
6989
@mkdir -p $(CLANG_NATIVE_BIN_DIR)
70-
@cd $(CLANG_NATIVE_BUILD_DIR) && export CC=clang && export CXX=clang++ && cmake -D TARGET=native -D _CMAKE_TOOLCHAIN_PREFIX=llvm- -D BIN_DIR=$(CLANG_NATIVE_BIN_DIR) -D DEBUG=$(DEBUG) $(ROOT_DIR)
90+
@cd $(CLANG_NATIVE_BUILD_DIR) && export CC=clang && export CXX=clang++ && cmake -D TARGET=native -D _CMAKE_TOOLCHAIN_PREFIX=llvm- -D BIN_DIR=$(CLANG_NATIVE_BIN_DIR) -D DEBUG=$(DEBUG) $(CMAKE_INSTALL_PREFIX) $(ROOT_DIR)

src/CMakeLists.txt

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,3 @@ add_subdirectory(tools)
99
add_subdirectory(types)
1010
add_subdirectory(version)
1111
add_subdirectory(websockets)
12-
13-
# Open OCPP static library
14-
add_library(open-ocpp-static STATIC
15-
version.cpp)
16-
target_link_libraries(open-ocpp-static
17-
centralsystem
18-
chargepoint
19-
config
20-
database
21-
messages
22-
rpc
23-
helpers
24-
log
25-
version
26-
x509
27-
json
28-
ws
29-
websockets
30-
31-
dl
32-
)
33-
set_target_properties(open-ocpp-static PROPERTIES OUTPUT_NAME "open-ocpp")
34-
35-
# Open OCPP dynamic library
36-
add_library(open-ocpp-dynamic SHARED
37-
version.cpp)
38-
target_link_libraries(open-ocpp-dynamic
39-
centralsystem
40-
chargepoint
41-
config
42-
database
43-
messages
44-
rpc
45-
helpers
46-
log
47-
version
48-
x509
49-
json
50-
ws
51-
websockets
52-
53-
dl
54-
)
55-
set_target_properties(open-ocpp-dynamic PROPERTIES OUTPUT_NAME "open-ocpp")

0 commit comments

Comments
 (0)