[Scummvm-git-logs] scummvm master -> c02abd29672bb23ebdb97a7df7233c9a6b059582

orgads noreply at scummvm.org
Sat Mar 5 19:39:10 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c02abd2967 CREATE_PROJECT: Simplify engines part


Commit: c02abd29672bb23ebdb97a7df7233c9a6b059582
    https://github.com/scummvm/scummvm/commit/c02abd29672bb23ebdb97a7df7233c9a6b059582
Author: Orgad Shaneh (orgads at gmail.com)
Date: 2022-03-05T21:39:08+02:00

Commit Message:
CREATE_PROJECT: Simplify engines part

Create a function add_engine which handles everything for the engine, and
remove redundant conditions all over the project file.

Changed paths:
    devtools/create_project/cmake.cpp
    devtools/create_project/cmake.h


diff --git a/devtools/create_project/cmake.cpp b/devtools/create_project/cmake.cpp
index cab4c51c6a6..88c98e5d594 100644
--- a/devtools/create_project/cmake.cpp
+++ b/devtools/create_project/cmake.cpp
@@ -114,6 +114,33 @@ macro(find_feature)
 	endif()
 endmacro()
 
+)";
+
+	workspace << R"EOS(function(add_engine engine_name)
+	string(TOUPPER ${engine_name} _engine_var)
+	set(_enable_engine_var "ENABLE_${_engine_var}")
+	if(NOT ${_enable_engine_var})
+		return()
+	endif()
+	add_library(${engine_name} ${ARGN})
+
+	# Generate definitions for the engine
+	add_definitions(-D${_enable_engine_var})
+	foreach(SUB_ENGINE IN LISTS SUB_ENGINES_${_engine_var})
+		add_definitions(-DENABLE_${SUB_ENGINE})
+	endforeach(SUB_ENGINE)
+	file(APPEND "engines/plugins_table.h" "#if PLUGIN_ENABLED_STATIC(${_engine_var})\n")
+	file(APPEND "engines/plugins_table.h" "LINK_PLUGIN(${_engine_var})\n")
+	file(APPEND "engines/plugins_table.h" "#endif\n")
+
+	# Enable C++11
+	set_property(TARGET ${engine_name} PROPERTY CXX_STANDARD 11)
+	set_property(TARGET ${engine_name} PROPERTY CXX_STANDARD_REQUIRED ON)
+
+	# Link against the engine
+	target_link_libraries()EOS" << setup.projectName << R"( ${engine_name})
+endfunction()
+
 )";
 
 	workspace << "# Define the engines and subengines\n";
@@ -152,11 +179,12 @@ include_directories(${SDL2_INCLUDE_DIRS})
 
 	writeWarnings(workspace);
 	writeDefines(setup, workspace);
-	workspace << "# Generate definitions for the engines\n";
-	writeEngineDefinitions(workspace);
 
-	workspace << "# Generate \"engines/plugins_table.h\"\n";
-	writeGeneratePluginsTable(workspace);
+	workspace << R"(# Generate "engines/plugins_table.h"
+file(REMOVE "engines/plugins_table.h")
+file(APPEND "engines/plugins_table.h" "/* This file is automatically generated by CMake */\n")
+
+)";
 }
 
 void CMakeProvider::writeFeatureLibSearch(const BuildSetup &setup, std::ofstream &workspace, const char *feature) const {
@@ -230,6 +258,16 @@ void CMakeProvider::writeSubEngines(const BuildSetup &setup, std::ofstream &work
 	workspace << "\n";
 }
 
+static std::string filePrefix(const BuildSetup &setup, const std::string &moduleDir) {
+	std::string modulePath;
+	if (!moduleDir.compare(0, setup.srcDir.size(), setup.srcDir)) {
+		modulePath = moduleDir.substr(setup.srcDir.size());
+		if (!modulePath.empty() && modulePath.at(0) == '/')
+			modulePath.erase(0, 1);
+	}
+	return modulePath.empty() ? setup.filePrefix : setup.filePrefix + '/' + modulePath;
+}
+
 void CMakeProvider::createProjectFile(const std::string &name, const std::string &, const BuildSetup &setup, const std::string &moduleDir,
 										   const StringList &includeList, const StringList &excludeList) {
 
@@ -238,38 +276,21 @@ void CMakeProvider::createProjectFile(const std::string &name, const std::string
 	if (!project)
 		error("Could not open \"" + projectFile + "\" for writing");
 
-	bool addEnableCheck = true;
 	if (name == setup.projectName) {
 		project << "add_executable(" << name << "\n";
-		addEnableCheck = false;
 	} else if (name == setup.projectName + "-detection") {
 		project << "list(APPEND SCUMMVM_LIBS " << name << ")\n";
 		project << "add_library(" << name << "\n";
-		addEnableCheck = false;
 	} else {
-		std::string engineName;
-		std::transform(name.begin(), name.end(), std::back_inserter(engineName), toupper);
-
-		project << "if (ENABLE_" << engineName << ")\n";
-		project << "add_library(" << name << "\n";
-	}
-
-	std::string modulePath;
-	if (!moduleDir.compare(0, setup.srcDir.size(), setup.srcDir)) {
-		modulePath = moduleDir.substr(setup.srcDir.size());
-		if (!modulePath.empty() && modulePath.at(0) == '/')
-			modulePath.erase(0, 1);
+		enginesStr << "add_engine(" << name << "\n";
+		addFilesToProject(moduleDir, enginesStr, includeList, excludeList, {});
+		enginesStr << ")\n\n";
+		return;
 	}
 
-	if (!modulePath.empty())
-		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix + '/' + modulePath);
-	else
-		addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix);
+	addFilesToProject(moduleDir, project, includeList, excludeList, filePrefix(setup, moduleDir));
 
 	project << ")\n";
-	if (addEnableCheck) {
-		project << "endif()\n";
-	}
 	project << "\n";
 
 	if (name == setup.projectName) {
@@ -360,40 +381,9 @@ void CMakeProvider::writeEngineOptions(std::ofstream &workspace) const {
 	workspace << "endforeach(ENGINE)\n\n";
 }
 
-void CMakeProvider::writeGeneratePluginsTable(std::ofstream &workspace) const {
-	workspace << "file(REMOVE \"engines/plugins_table.h\")\n";
-	workspace << "file(APPEND \"engines/plugins_table.h\" \"/* This file is automatically generated by CMake */\\n\")\n";
-	workspace << "foreach(ENGINE IN LISTS ENGINES)\n";
-	workspace << "\tif (ENABLE_${ENGINE})\n";
-	workspace << "\t\tfile(APPEND \"engines/plugins_table.h\" \"#if PLUGIN_ENABLED_STATIC(${ENGINE})\\n\")\n";
-	workspace << "\t\tfile(APPEND \"engines/plugins_table.h\" \"LINK_PLUGIN(${ENGINE})\\n\")\n";
-	workspace << "\t\tfile(APPEND \"engines/plugins_table.h\" \"#endif\\n\")\n";
-	workspace << "\tendif()\n";
-	workspace << "endforeach()\n\n";
-}
-
 void CMakeProvider::writeEnginesLibrariesHandling(const BuildSetup &setup, std::ofstream &workspace) const {
-	workspace << "foreach(ENGINE IN LISTS ENGINES)\n";
-	workspace << "\tif (ENABLE_${ENGINE})\n";
-	workspace << "\t\tstring(TOLOWER ${ENGINE} ENGINE_LIB)\n\n";
-	workspace << "\t\t# Enable C++11\n";
-	workspace << "\t\tset_property(TARGET ${ENGINE_LIB} PROPERTY CXX_STANDARD 11)\n";
-	workspace << "\t\tset_property(TARGET ${ENGINE_LIB} PROPERTY CXX_STANDARD_REQUIRED ON)\n\n";
-	workspace << "\t\t# Link against the engine\n";
-	workspace << "\t\ttarget_link_libraries("<< setup.projectName <<" ${ENGINE_LIB})\n";
-	workspace << "\tendif()\n";
-	workspace << "endforeach()\n\n";
-}
+	workspace << enginesStr.str();
 
-void CMakeProvider::writeEngineDefinitions(std::ofstream &workspace) const {
-	workspace << "foreach(ENGINE IN LISTS ENGINES)\n";
-	workspace << "\tif (ENABLE_${ENGINE})\n";
-	workspace << "\t\tadd_definitions(-DENABLE_${ENGINE})\n";
-	workspace << "\t\tforeach(SUB_ENGINE IN LISTS SUB_ENGINES_${ENGINE})\n";
-	workspace << "\t\t\tadd_definitions(-DENABLE_${SUB_ENGINE})\n";
-	workspace << "\t\tendforeach(SUB_ENGINE)\n";
-	workspace << "\tendif()\n";
-	workspace << "endforeach()\n\n";
 }
 
 bool CMakeProvider::featureExcluded(const char *name) const {
diff --git a/devtools/create_project/cmake.h b/devtools/create_project/cmake.h
index 8f62e22b573..b678f23bfae 100644
--- a/devtools/create_project/cmake.h
+++ b/devtools/create_project/cmake.h
@@ -23,6 +23,7 @@
 #define TOOLS_CREATE_PROJECT_CMAKE_H
 
 #include "create_project.h"
+#include <sstream>
 
 namespace CreateProjectTool {
 
@@ -52,6 +53,8 @@ protected:
 	const char *getProjectExtension() final;
 
 private:
+	std::stringstream enginesStr;
+
 	enum SDLVersion {
 		kSDLVersionAny,
 		kSDLVersion1,
@@ -79,9 +82,7 @@ private:
 	void writeEngines(const BuildSetup &setup, std::ofstream &workspace) const;
 	void writeSubEngines(const BuildSetup &setup, std::ofstream &workspace) const;
 	void writeEngineOptions(std::ofstream &workspace) const;
-	void writeGeneratePluginsTable(std::ofstream &workspace) const;
 	void writeEnginesLibrariesHandling(const BuildSetup &setup, std::ofstream &workspace) const;
-	void writeEngineDefinitions(std::ofstream &workspace) const;
 	void writeFeatureLibSearch(const BuildSetup &setup, std::ofstream &workspace, const char *feature) const;
 	bool featureExcluded(const char *name) const;
 	const EngineDesc &findEngineDesc(const std::string &name, const EngineDescList &engines) const;




More information about the Scummvm-git-logs mailing list