Skip to content

Commit 5edc25c

Browse files
committed
[build] Make static library build conditional and desactived by default
1 parent 14ea42c commit 5edc25c

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

CMakeLists.txt

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,29 @@ endif()
5050
add_subdirectory(src)
5151

5252
# 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")
53+
if(${BUILD_STATIC_LIBRARY})
54+
add_library(open-ocpp-static STATIC
55+
src/version.cpp)
56+
target_link_libraries(open-ocpp-static
57+
centralsystem
58+
chargepoint
59+
config
60+
database
61+
messages
62+
rpc
63+
helpers
64+
log
65+
version
66+
x509
67+
json
68+
ws
69+
websockets
70+
71+
dl
72+
)
73+
set_target_properties(open-ocpp-static PROPERTIES OUTPUT_NAME "open-ocpp_static")
74+
set(OPEN_OCPP_STATIC_TARGET open-ocpp-static)
75+
endif()
7376

7477
# Open OCPP dynamic library
7578
add_library(open-ocpp-dynamic SHARED
@@ -98,7 +101,7 @@ include(GNUInstallDirs)
98101

99102
file(GLOB_RECURSE PUBLIC_HEADERS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.h")
100103

101-
install(TARGETS open-ocpp-static open-ocpp-dynamic
104+
install(TARGETS open-ocpp-dynamic ${OPEN_OCPP_STATIC_TARGET}
102105
EXPORT LibOpenOcppTargets
103106

104107
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
@@ -120,9 +123,11 @@ configure_file(
120123
)
121124
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
122125

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)
126+
if(${BUILD_STATIC_LIBRARY})
127+
set(LIB_NAME "open-ocpp_static")
128+
configure_file(
129+
"${CMAKE_CURRENT_SOURCE_DIR}/libopen-ocpp.pc.in"
130+
"${CMAKE_CURRENT_BINARY_DIR}/libopen-ocpp_static.pc"
131+
)
132+
install(FILES "${CMAKE_BINARY_DIR}/libopen-ocpp_static.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
133+
endif()

CMakeLists_Options.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44

55
# Log level (0 = All logs, 5 = No logs)
66
if(NOT DEFINED LOG_LEVEL)
7-
set(LOG_LEVEL 1)
7+
set(LOG_LEVEL 1)
88
endif()
99
add_compile_definitions(LOG_LEVEL=${LOG_LEVEL})
1010

11+
# Static library
12+
if(NOT DEFINED BUILD_STATIC_LIBRARY)
13+
set(BUILD_STATIC_LIBRARY OFF)
14+
endif()
15+
1116
# Unit tests
1217
if(NOT DEFINED BUILD_UNIT_TESTS)
13-
set(BUILD_UNIT_TESTS ON)
18+
set(BUILD_UNIT_TESTS ON)
1419
endif()
1520

1621
# Examples
1722
if(NOT DEFINED BUILD_EXAMPLES)
18-
set(BUILD_EXAMPLES ON)
23+
set(BUILD_EXAMPLES ON)
1924
endif()

0 commit comments

Comments
 (0)