Skip to content

Commit 6c1e374

Browse files
authored
Merge pull request #47 from c-jimenez/dev/build_dynamic_lib
Dev/build dynamic lib
2 parents 16324be + fbd2b2a commit 6c1e374

File tree

40 files changed

+1281
-140
lines changed

40 files changed

+1281
-140
lines changed

.github/workflows/c-cpp.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/install-test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Install test
2+
3+
on:
4+
push:
5+
branches: [ develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: make gcc install
17+
run: make BUILD_TYPE=Release INSTALL_PREFIX=/tmp/install-gcc tests-install-gcc-native
18+
- name: make clang install
19+
run: make BUILD_TYPE=Release INSTALL_PREFIX=/tmp/install-clang tests-install-clang-native
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Unit test in Debug build
2+
3+
on:
4+
push:
5+
branches: [ develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: make gcc Debug
17+
run: make gcc-native BUILD_TYPE=Debug
18+
- name: unit tests gcc Debug
19+
run: make tests-gcc-native BUILD_TYPE=Debug
20+
- name: make clang Debug
21+
run: make clang-native BUILD_TYPE=Debug
22+
- name: unit tests clang
23+
run: make tests-clang-native BUILD_TYPE=Debug
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Unit test in Release build
2+
3+
on:
4+
push:
5+
branches: [ develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: make gcc Release
17+
run: make gcc-native BUILD_TYPE=Release
18+
- name: unit tests gcc Release
19+
run: make tests-gcc-native BUILD_TYPE=Release
20+
- name: make clang Release
21+
run: make clang-native BUILD_TYPE=Release
22+
- name: unit tests clang
23+
run: make tests-clang-native BUILD_TYPE=Release

3rdparty/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ add_library(doctest INTERFACE)
88
target_include_directories(doctest INTERFACE doctest/doctest)
99

1010
# Use default flags for the libwebsockets library
11-
set(CMAKE_C_FLAGS "-g -ggdb")
12-
set(CMAKE_CXX_FLAGS "-g -ggdb")
11+
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3 -ggdb3")
12+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3")
13+
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
14+
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
1315

1416
add_subdirectory(libwebsockets)

3rdparty/libwebsockets/lib/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ if (LWS_WITH_STATIC)
169169
target_include_directories(websockets PRIVATE ${LWS_LIB_BUILD_INC_PATHS})
170170
target_compile_definitions(websockets PRIVATE LWS_BUILDING_STATIC)
171171

172-
if (WIN32)
172+
#if (WIN32)
173173
# Windows uses the same .lib ending for static libraries and shared
174174
# library linker files, so rename the static library.
175175
set_target_properties(websockets
176176
PROPERTIES
177177
OUTPUT_NAME websockets_static)
178-
endif()
178+
#endif()
179179

180180
endif()
181181

@@ -375,4 +375,3 @@ set(LIB_LIST_AT_END ${LIB_LIST_AT_END} PARENT_SCOPE)
375375
endif()
376376
set(USE_WOLFSSL ${USE_WOLFSSL} PARENT_SCOPE)
377377
set(LWS_DEPS_LIB_PATHS ${LWS_DEPS_LIB_PATHS} PARENT_SCOPE)
378-

CMakeLists.txt

Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
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+
)
10+
11+
# Definitions for Version.h file
12+
add_definitions(-DLIBOPENOCPP_MAJOR="${PROJECT_VERSION_MAJOR}")
13+
add_definitions(-DLIBOPENOCPP_MINOR="${PROJECT_VERSION_MINOR}")
14+
add_definitions(-DLIBOPENOCPP_FIX="${PROJECT_VERSION_PATCH}")
815

916
# Build options
1017
include(CMakeLists_Options.txt)
@@ -15,18 +22,124 @@ if(NOT DEFINED TARGET)
1522
endif()
1623
include(CMakeLists_${TARGET}.txt)
1724

25+
# Enable position independant code for dynamic library generation
26+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
27+
1828
# 3rd party
1929
add_subdirectory(3rdparty)
2030

2131
# OpenSSL is mandatory
22-
find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
23-
24-
# Subdirectories
25-
add_subdirectory(examples)
26-
add_subdirectory(src)
32+
find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
2733

2834
# Tests
2935
if(${BUILD_UNIT_TESTS})
3036
enable_testing()
3137
add_subdirectory(tests)
3238
endif()
39+
40+
41+
# Default output directories
42+
if(NOT DEFINED BIN_DIR)
43+
set(BIN_DIR ${CMAKE_SOURCE_DIR}/bin/${TARGET})
44+
endif()
45+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BIN_DIR})
46+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BIN_DIR})
47+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR})
48+
49+
# Examples
50+
if(${BUILD_EXAMPLES})
51+
add_subdirectory(examples)
52+
endif()
53+
54+
# Open OCPP library sources
55+
add_subdirectory(src)
56+
57+
# Open OCPP static library
58+
if(${BUILD_STATIC_LIBRARY})
59+
add_library(open-ocpp-static STATIC
60+
src/version.cpp)
61+
target_link_libraries(open-ocpp-static
62+
centralsystem
63+
chargepoint
64+
config
65+
database
66+
messages
67+
rpc
68+
helpers
69+
log
70+
version
71+
x509
72+
json
73+
ws
74+
websockets
75+
)
76+
set_target_properties(open-ocpp-static PROPERTIES OUTPUT_NAME "open-ocpp_static")
77+
set(OPEN_OCPP_STATIC_TARGET open-ocpp-static)
78+
endif()
79+
80+
# Open OCPP dynamic library
81+
add_library(open-ocpp-dynamic SHARED
82+
src/version.cpp)
83+
target_link_libraries(open-ocpp-dynamic
84+
centralsystem
85+
chargepoint
86+
config
87+
database
88+
messages
89+
rpc
90+
helpers
91+
log
92+
version
93+
x509
94+
json
95+
ws
96+
websockets
97+
98+
stdc++fs
99+
)
100+
set_target_properties(open-ocpp-dynamic PROPERTIES OUTPUT_NAME "open-ocpp")
101+
102+
# Install commands
103+
include(GNUInstallDirs)
104+
105+
file(GLOB_RECURSE PUBLIC_HEADERS
106+
LIST_DIRECTORIES false RELATIVE ${CMAKE_SOURCE_DIR} "${CMAKE_SOURCE_DIR}/src/*.h")
107+
108+
install(TARGETS open-ocpp-dynamic ${OPEN_OCPP_STATIC_TARGET}
109+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
110+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
111+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
112+
)
113+
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openocpp)
114+
115+
file(GLOB RAPIDJSON_HEADERS
116+
LIST_DIRECTORIES false RELATIVE ${CMAKE_SOURCE_DIR} "${CMAKE_SOURCE_DIR}/3rdparty/rapidjson/include/rapidjson/*.h")
117+
file(GLOB RAPIDJSON_INTERNAL_HEADERS
118+
LIST_DIRECTORIES false RELATIVE ${CMAKE_SOURCE_DIR} "${CMAKE_SOURCE_DIR}/3rdparty/rapidjson/include/rapidjson/internal/*.h")
119+
file(GLOB RAPIDJSON_ERROR_HEADERS
120+
LIST_DIRECTORIES false RELATIVE ${CMAKE_SOURCE_DIR} "${CMAKE_SOURCE_DIR}/3rdparty/rapidjson/include/rapidjson/error/*.h")
121+
install(FILES ${RAPIDJSON_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openocpp/rapidjson)
122+
install(FILES ${RAPIDJSON_INTERNAL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openocpp/rapidjson/internal)
123+
install(FILES ${RAPIDJSON_ERROR_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openocpp/rapidjson/error)
124+
125+
# Generate pkgconfig files
126+
set(PKG_CONFIG_LIBDIR "\${prefix}/lib")
127+
set(PKG_CONFIG_INCLUDEDIR "\${prefix}/include/openocpp")
128+
set(PKG_CONFIG_LIBS "-L\${libdir}")
129+
set(PKG_CONFIG_CFLAGS "-I\${includedir}")
130+
131+
set(LIB_NAME "open-ocpp")
132+
configure_file(
133+
"${CMAKE_CURRENT_SOURCE_DIR}/deploy/libopen-ocpp.pc.in"
134+
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp.pc"
135+
)
136+
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
137+
138+
if(${BUILD_STATIC_LIBRARY})
139+
set(LIB_NAME "open-ocpp_static")
140+
configure_file(
141+
"${CMAKE_CURRENT_SOURCE_DIR}/deploy/libopen-ocpp.pc.in"
142+
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp_static.pc"
143+
)
144+
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp_static.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
145+
endif()

CMakeLists_Options.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
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})
10+
11+
# Static library
12+
option(BUILD_STATIC_LIBRARY "Build Open OCPP as a static library" OFF)
713

814
# Unit tests
9-
set(BUILD_UNIT_TESTS ON)
15+
option(BUILD_UNIT_TESTS "Build unit tests" ON)
16+
17+
# Examples
18+
option(BUILD_EXAMPLES "Build examples" ON)

CMakeLists_native.txt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
# Native target toolchain definition and specific compiler flags #
33
#################################################################################
44

5-
# Optimization flags
6-
if (DEBUG)
7-
set(OPTIMIZATION_FLAGS "-O0 -g -ggdb")
8-
else()
9-
set(OPTIMIZATION_FLAGS "-O2")
10-
endif()
11-
125
# Warnings
136
set(WARNING_FLAGS "-Wall -Wextra -Werror")
147

@@ -17,5 +10,7 @@ set(C_FLAGS "-std=c11")
1710
set(CXX_FLAGS "-std=c++17")
1811

1912
# Set compiler flags
20-
set(CMAKE_C_FLAGS "${C_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
21-
set(CMAKE_CXX_FLAGS "${CXX_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
13+
set(CMAKE_C_FLAGS_DEBUG "${C_FLAGS} ${WARNING_FLAGS} -O0 -g3 -ggdb3")
14+
set(CMAKE_CXX_FLAGS_DEBUG "${CXX_FLAGS} ${WARNING_FLAGS} -O0 -g3 -ggdb3")
15+
set(CMAKE_C_FLAGS_RELEASE "${C_FLAGS} ${WARNING_FLAGS} -O2 -DNDEBUG")
16+
set(CMAKE_CXX_FLAGS_RELEASE "${CXX_FLAGS} ${WARNING_FLAGS} -O2 -DNDEBUG")

0 commit comments

Comments
 (0)