Make modules completely self-contained

parent 6b888f3c
Pipeline #16463 failed with stage
......@@ -30,9 +30,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
# Flags
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -pedantic -Werror")
include_directories("${CMAKE_SOURCE_DIR}/src")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-vexing-parse")
endif()
# Check C++14
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
......@@ -62,25 +59,28 @@ configure_file ("${PROJECT_SOURCE_DIR}/src/config.hpp.in" ${CONFIG_HEADER})
include_directories("${CMAKE_BINARY_DIR}/src")
#Melano modules
set(MELANOMODULES "")
set(MELANOMODULES_INIT "")
set_property(GLOBAL PROPERTY MELANOMODULES "")
set_property(GLOBAL PROPERTY MELANOMODULES_INIT "")
set_property(GLOBAL PROPERTY MELANOMODULES_DECLARE "")
macro(melanomodule name description default)
string(TOUPPER "MODULE_${name}" OPTION_NAME)
option (${OPTION_NAME} ${description} ${default})
set(MODULE_NAME "melanomodule_${name}")
if (${${OPTION_NAME}})
add_subdirectory(${name})
set(MELANOMODULES_ ${MELANOMODULES_} "melanomodule_${name}")
set(MELANOMODULES ${MELANOMODULES_} PARENT_SCOPE)
set(MELANOMODULES_INIT_ "${MELANOMODULES_INIT_} \\
Melanomodule melanomodule_${name}()\; \\
modules.push_back(melanomodule_${name}())\;")
set(MELANOMODULES_INIT ${MELANOMODULES_INIT_} PARENT_SCOPE)
set_property(GLOBAL APPEND PROPERTY MELANOMODULES ${MODULE_NAME})
set_property(GLOBAL APPEND_STRING PROPERTY MELANOMODULES_DECLARE "
Melanomodule ${MODULE_NAME}();")
set_property(GLOBAL APPEND_STRING PROPERTY MELANOMODULES_INIT "\\
modules.push_back(${MODULE_NAME}());")
message(STATUS "Enabled module ${name}: ${description}")
endif()
endmacro()
add_subdirectory(modules lib)
get_property(MELANOMODULES GLOBAL PROPERTY MELANOMODULES)
get_property(MELANOMODULES_INIT GLOBAL PROPERTY MELANOMODULES_INIT)
get_property(MELANOMODULES_DECLARE GLOBAL PROPERTY MELANOMODULES_DECLARE)
if (NOT MELANOMODULES)
message(STATUS "No modules enabled")
else()
......
......@@ -15,10 +15,9 @@
include_directories("${CMAKE_SOURCE_DIR}/modules")
#modules ID Desctiption Default
melanomodule(core "Core module, should always be enabled" ON)
melanomodule(irc "Internet Relay Chat support" ON)
melanomodule(xonotic "Xonotic integration" ON)
melanomodule(posix "Extra features for POSIX systems" OFF)
melanomodule(web "Web stuff (HTTP and friends)" ON)
melanomodule(fun "Possibly useless yet silly stuff" ON)
file(GLOB SUBDIRS RELATIVE "${CMAKE_SOURCE_DIR}/modules" ${CMAKE_SOURCE_DIR}/modules/*)
foreach(subdir ${SUBDIRS})
if(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/modules/${subdir}")
add_subdirectory(${subdir})
endif()
endforeach()
......@@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(MODULE_NAME melanomodule_core)
melanomodule(core "Core module, should always be enabled" ON)
file(GLOB_RECURSE SOURCES *.cpp)
......
......@@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(MODULE_NAME melanomodule_fun)
melanomodule(fun "Possibly useless yet silly stuff" ON)
file(GLOB_RECURSE SOURCES *.cpp)
......
......@@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(MODULE_NAME melanomodule_irc)
melanomodule(irc "Internet Relay Chat support" ON)
file(GLOB_RECURSE SOURCES *.cpp)
......
......@@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(MODULE_NAME melanomodule_posix)
melanomodule(posix "Extra features for POSIX systems" OFF)
file(GLOB_RECURSE SOURCES *.cpp)
......
......@@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(MODULE_NAME melanomodule_web)
melanomodule(web "Web stuff (HTTP and friends)" ON)
file(GLOB_RECURSE SOURCES *.cpp)
......
......@@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(MODULE_NAME melanomodule_xonotic)
melanomodule(xonotic "Xonotic integration" ON)
file(GLOB_RECURSE SOURCES *.cpp)
......
......@@ -18,7 +18,8 @@
*/
#ifndef MELANOMODULES_HPP
#define MELANOMODULES_HPP
@MELANOMODULES_DECLARE@
#define MELANOMODULES_INIT @MELANOMODULES_INIT@
#define MELANOMODULES_INIT @MELANOMODULES_INIT@
#endif // MELANOMODULES
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment