Files

56 lines
2.3 KiB
CMake
Raw Permalink Normal View History

2023-06-11 19:06:16 +02:00
# This file is part of the Flowee project
# Copyright (C) 2023-2024 Tom Zander <tom@flowee.org>
2023-06-11 19:06:16 +02:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#add_subdirectory(example)
#add_subdirectory(build-transaction)
# Find all modules to auto-invoke and write them to a file.
set(INCLUDES_LIST "")
set(CLASSES_LIST "")
file(GLOB sub_directories ${CMAKE_CURRENT_SOURCE_DIR}/*)
foreach (child ${sub_directories})
if (IS_DIRECTORY ${child})
file(GLOB subModule ${child}/*ModuleInfo.h)
if (EXISTS ${subModule})
file (RELATIVE_PATH module ${CMAKE_CURRENT_SOURCE_DIR} ${child})
get_filename_component(className ${subModule} NAME_WE)
if (NOT (${skip_example} AND ${className} STREQUAL "ExampleModuleInfo"))
add_subdirectory(${child})
list (APPEND CLASSES_LIST ${className})
file (RELATIVE_PATH include_file ${CMAKE_CURRENT_SOURCE_DIR} ${subModule})
list (APPEND INCLUDES_LIST ${include_file})
endif()
2023-06-11 19:06:16 +02:00
endif()
endif()
endforeach()
# After compiling them, generate a little cpp file that actually loads those modules
# into the ModulesManager
2023-06-12 17:11:29 +02:00
set (MODULES_LOAD_CPP "#include <ModuleManager.h>\n")
2023-06-11 19:06:16 +02:00
foreach (include ${INCLUDES_LIST})
set (MODULES_LOAD_CPP "${MODULES_LOAD_CPP}#include <${include}>\n")
endforeach()
2023-06-12 17:11:29 +02:00
set (MODULES_LOAD_CPP "${MODULES_LOAD_CPP}\nvoid load_all_modules(ModuleManager *m) {\n")
2023-06-11 19:06:16 +02:00
foreach (className ${CLASSES_LIST})
2023-06-12 17:11:29 +02:00
set (MODULES_LOAD_CPP
"${MODULES_LOAD_CPP} m->load(${className}::translationUnit(), &${className}::build);\n")
2023-06-11 19:06:16 +02:00
endforeach()
# finally, write out the cpp file.
file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/modules-load.cpp "${MODULES_LOAD_CPP}}")