Skip to content

Commit 1b944d0

Browse files
authored
Merge pull request #188 from thomas-brunel/dev/cmake_options
[cmake] Add options to not build as a shared library, not build sqlite3 and not install doctest headers
2 parents e0b0d5e + c6863c8 commit 1b944d0

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

3rdparty/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ endif()
88
target_include_directories(rapidjson INTERFACE rapidjson/include)
99

1010
# Doctest is an header only on library
11-
add_library(doctest INTERFACE)
12-
target_include_directories(doctest INTERFACE doctest/doctest)
11+
if(${INSTALL_DOCTEST})
12+
add_library(doctest INTERFACE)
13+
target_include_directories(doctest INTERFACE doctest/doctest)
14+
endif()
1315

1416
# SQLite 3
15-
add_subdirectory(sqlite3)
17+
if(${BUILD_SQLITE})
18+
add_subdirectory(sqlite3)
19+
endif()
1620

1721
# libwebsockets
1822
if(${BUILD_LWS_LIBRARY})

CMakeLists.txt

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,32 @@ if(${BUILD_STATIC_LIBRARY})
8989
endif()
9090

9191
# Open OCPP dynamic library
92-
add_library(open-ocpp-dynamic SHARED
93-
src/version.cpp)
94-
target_link_libraries(open-ocpp-dynamic
95-
centralsystem
96-
chargepoint
97-
localcontroller
98-
config
99-
database
100-
messages
101-
rpc
102-
helpers
103-
log
104-
version
105-
x509
106-
json
107-
ws
108-
websockets
109-
)
110-
set_target_properties(open-ocpp-dynamic PROPERTIES
111-
OUTPUT_NAME "open-ocpp"
112-
VERSION ${PROJECT_VERSION}
113-
SOVERSION ${PROJECT_VERSION_MAJOR}
114-
)
92+
if (${BUILD_SHARED_LIBRARY})
93+
add_library(open-ocpp-dynamic SHARED
94+
src/version.cpp)
95+
target_link_libraries(open-ocpp-dynamic
96+
centralsystem
97+
chargepoint
98+
localcontroller
99+
config
100+
database
101+
messages
102+
rpc
103+
helpers
104+
log
105+
version
106+
x509
107+
json
108+
ws
109+
websockets
110+
)
111+
set_target_properties(open-ocpp-dynamic PROPERTIES
112+
OUTPUT_NAME "open-ocpp"
113+
VERSION ${PROJECT_VERSION}
114+
SOVERSION ${PROJECT_VERSION_MAJOR}
115+
)
116+
set(OPEN_OCPP_SHARED_TARGET open-ocpp-dynamic)
117+
endif()
115118

116119
# Install commands
117120
include(GNUInstallDirs)
@@ -121,7 +124,7 @@ file(GLOB_RECURSE PUBLIC_HEADERS
121124
file(GLOB OCPP_SCHEMAS
122125
LIST_DIRECTORIES false RELATIVE ${CMAKE_SOURCE_DIR} "${CMAKE_SOURCE_DIR}/schemas/*.json")
123126

124-
install(TARGETS open-ocpp-dynamic ${OPEN_OCPP_STATIC_TARGET}
127+
install(TARGETS ${OPEN_OCPP_SHARED_TARGET} ${OPEN_OCPP_STATIC_TARGET}
125128
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
126129
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
127130
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -145,12 +148,14 @@ set(PKG_CONFIG_INCLUDEDIR "\${prefix}/include/openocpp")
145148
set(PKG_CONFIG_LIBS "-L\${libdir}")
146149
set(PKG_CONFIG_CFLAGS "-I\${includedir}")
147150

148-
set(LIB_NAME "open-ocpp")
149-
configure_file(
150-
"${CMAKE_CURRENT_SOURCE_DIR}/deploy/libopen-ocpp.pc.in"
151-
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp.pc"
152-
)
153-
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
151+
if(${BUILD_SHARED_LIBRARY})
152+
set(LIB_NAME "open-ocpp")
153+
configure_file(
154+
"${CMAKE_CURRENT_SOURCE_DIR}/deploy/libopen-ocpp.pc.in"
155+
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp.pc"
156+
)
157+
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
158+
endif()
154159

155160
if(${BUILD_STATIC_LIBRARY})
156161
set(LIB_NAME "open-ocpp_static")

CMakeLists_Options.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ if(EXTERNAL_LOGGER)
1414
add_compile_definitions(EXTERNAL_LOGGER=1)
1515
endif()
1616

17+
# Shared library
18+
option(BUILD_SHARED_LIBRARY "Build Open OCPP as a shared library" ON)
19+
1720
# Static library
1821
option(BUILD_STATIC_LIBRARY "Build Open OCPP as a static library" ON)
1922

@@ -26,6 +29,12 @@ option(BUILD_EXAMPLES "Build examples"
2629
# Build the libwebsocket library along with the Open OCPP library
2730
option(BUILD_LWS_LIBRARY "Build libwebsocket library" ON)
2831

32+
# Build the sqlite3 library along with the Open OCPP library
33+
option(BUILD_SQLITE "Build sqlite3 library" ON)
34+
35+
# Install the Doctest header
36+
option(INSTALL_DOCTEST "Install doctest headers" ON)
37+
2938
# Use only the CrtAllocator in Rapidjson, not the MemoryPoolAllocator
3039
option(USE_CRT_ALLOC_FOR_RAPIDJSON "Use the CrtAllocator for Rapidjson instead of the MemoryPoolAllocator" OFF)
3140
if(USE_CRT_ALLOC_FOR_RAPIDJSON)

0 commit comments

Comments
 (0)