@@ -47,7 +47,8 @@ option(ENABLE_DEBUGGER "Enable bmv2 remote debugger" OFF)
4747option (ENABLE_COVERAGE "Enable code coverage tracking" OFF )
4848option (ENABLE_LOGGING_MACROS "Enable compile time debug and trace logging macros" ON )
4949option (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 )
5152option (ENABLE_UNDETERMINISTIC_TESTS "Run undeterministic tests (e.g. queueing) when running tests" ON )
5253option (ENABLE_WERROR "Make all compiler warnings fatal" OFF )
5354option (ENABLE_WP4_16_STACKS "Implement stacks strictly as per the P4_16 specification" ON )
@@ -167,15 +168,30 @@ if(WITH_PI)
167168 endif ()
168169endif ()
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+
170177if (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 ()
180196endif ()
181197
0 commit comments