Skip to content

Commit 2a2a3b2

Browse files
authored
Conditional compilation of plugins (#527)
* Conditional compilation of plugins. WITH_PLUGINS side is working. * Conditional compilation of plugins according to specified cmake options. * Refactoring to reduce redundancy.
1 parent 3e547c1 commit 2a2a3b2

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

doc/deps.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,4 @@ relevant during compilation.
303303
| `DATABASE` | Database type. Possible values are **sqlite**, **pgsql**. The default value is `sqlite`. |
304304
| `TEST_DB` | The connection string for the database that will be used when executing tests with `make test`. Optional. |
305305
| `CODECOMPASS_LINKER` | The path of the linker, if the system's default linker is to be overridden. |
306+
| `WITH_PLUGIN`/`WITHOUT_PLUGIN` | The names of the plugins to be built/skipped at build. Possible values are **cpp**, **cpp_reparse**, **dummy**, **git**, **metrics**, **search**. The `metrics` and `search` plugins are fundamental, they will be compiled even if not included. `WITH_PLUGIN` **cannot** be used together with `WITHOUT_PLUGIN`. Example: `-DWITH_PLUGIN="cpp;git"` This will compile the cpp, git, metrics and search plugins. |

plugins/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,35 @@
22
include_directories(SYSTEM
33
${ODB_INCLUDE_DIRS})
44

5+
# Throw error if WITH_PLUGIN and WITHOUT_PLUGIN are used together
6+
if(WITH_PLUGIN AND WITHOUT_PLUGIN)
7+
message(FATAL_ERROR "The WITH_PLUGIN and WITHOUT_PLUGIN options cannot be used together.")
8+
endif()
9+
510
# Add all subdirectories to the build
611
file(GLOB plugins RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/*")
712

13+
# Remove subdirectories according to the provided WITH_PLUGIN or WITHOUT_PLUGIN variables
14+
set(baseline "search")
15+
if(WITH_PLUGIN OR WITHOUT_PLUGIN)
16+
foreach(_base ${baseline})
17+
if((WITH_PLUGIN AND NOT ("${_base}" IN_LIST WITH_PLUGIN))
18+
OR (WITHOUT_PLUGIN AND "${_base}" IN_LIST WITHOUT_PLUGIN))
19+
message(WARNING "The ${_base} plugin cannot be left out, "
20+
"it will be compiled anyway.")
21+
endif()
22+
endforeach()
23+
24+
foreach(_plugin ${plugins})
25+
if(((WITH_PLUGIN AND NOT ("${_plugin}" IN_LIST WITH_PLUGIN))
26+
OR (WITHOUT_PLUGIN AND ("${_plugin}" IN_LIST WITHOUT_PLUGIN)))
27+
AND NOT ("${_plugin}" IN_LIST baseline)
28+
AND IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_plugin}")
29+
list(REMOVE_ITEM plugins ${_plugin})
30+
endif()
31+
endforeach()
32+
endif()
33+
834
# Set unique plugin directory variable for each plugin
935
message(STATUS "Found the following CodeCompass plugins:")
1036
foreach(_plugin ${plugins})

0 commit comments

Comments
 (0)