Skip to content

Commit 91bc4dc

Browse files
grgjafingerhut
andauthored
Fix #1325 - Enable ENABLE_MODULES if dlopen is found (#1327)
Signed-off-by: Andy Fingerhut <[email protected]> Signed-off-by: Glen Gibb <[email protected]> Co-authored-by: Andy Fingerhut <[email protected]>
1 parent 85e54f4 commit 91bc4dc

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

CMakeLists.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ option(ENABLE_DEBUGGER "Enable bmv2 remote debugger" OFF)
4747
option(ENABLE_COVERAGE "Enable code coverage tracking" OFF)
4848
option(ENABLE_LOGGING_MACROS "Enable compile time debug and trace logging macros" ON)
4949
option(ENABLE_ELOGGER "Enable nanomsg event logger" ON)
50-
option(ENABLE_MODULES "Allow loading third-party modules at runtime" OFF)
50+
option(ENABLE_MODULES "Allow loading third-party modules at runtime" ON)
51+
option(REQUIRE_MODULES "Require support for loading third-party modules at runtime" OFF)
5152
option(ENABLE_UNDETERMINISTIC_TESTS "Run undeterministic tests (e.g. queueing) when running tests" ON)
5253
option(ENABLE_WERROR "Make all compiler warnings fatal" OFF)
5354
option(ENABLE_WP4_16_STACKS "Implement stacks strictly as per the P4_16 specification" ON)
@@ -167,15 +168,30 @@ if(WITH_PI)
167168
endif()
168169
endif()
169170

171+
if(REQUIRE_MODULES AND NOT ENABLE_MODULES)
172+
message(FATAL_ERROR
173+
"Incompatible settings for ENABLE_MODULES (OFF) and REQUIRE_MODULES (ON): "
174+
"REQUIRE_MODULES requires ENABLE_MODULES")
175+
endif()
176+
170177
if(ENABLE_MODULES)
171-
# Check for dlopen
178+
# Check if dlopen is available
179+
# Set ENABLE_MODULES to OFF if it's not available
172180
check_include_file(dlfcn.h HAVE_DLFCN_H)
173181
if(HAVE_DLFCN_H)
174182
include(CheckSymbolExists)
175-
add_definitions(-DHAVE_DLOPEN -DENABLE_MODULES)
183+
set(CMAKE_REQUIRED_LIBRARIES "dl")
176184
check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN)
177-
else()
178-
message(FATAL_ERROR "Cannot enable modules without dlfcn.h")
185+
unset(CMAKE_REQUIRED_LIBRARIES)
186+
if(HAVE_DLOPEN)
187+
add_definitions(-DHAVE_DLOPEN -DENABLE_MODULES)
188+
else()
189+
set(ENABLE_MODULES OFF)
190+
endif()
191+
endif()
192+
193+
if(REQUIRE_MODULES AND NOT HAVE_DLOPEN)
194+
message(FATAL_ERROR "Cannot enable modules without dlopen()")
179195
endif()
180196
endif()
181197

0 commit comments

Comments
 (0)