diff --git a/generators/makefile/index.js b/generators/makefile/index.js deleted file mode 100644 index 2a7ffc8..0000000 --- a/generators/makefile/index.js +++ /dev/null @@ -1,111 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const chalk = require('chalk'); -const { pascalCase } = require('change-case'); -const { format } = require('../../lib/utils'); - -const sourceFileExt = ['.c', 'cpp']; -const cmakeFile = 'CMakeLists.txt'; -const xmakeFile = 'xmake.lua'; - -class Generator { - constructor(name, options) { - this.name = ['xmake', 'cmake'].includes(name) ? name : 'cmake'; - this.cwd = options.cwd; - this.templatesDir = path.join(__dirname, 'templates'); - this.sourceDir = path.join(this.cwd, 'src'); - } - - writeFile(file, content) { - console.log(chalk.green('writing'), path.relative(this.cwd, file)); - return fs.writeFileSync(file, content); - } - - readTemplateFile(name) { - const templateFile = path.join(this.templatesDir, name); - return fs.readFileSync(templateFile, { encoding: 'utf-8' }); - } - - generateFile(input, output) { - this.writeFile(output, this.readTemplateFile(input)); - } - - generateCMakeFileForDirectory(dir, moduleNames, addSource = true) { - let dirs = []; - const files = []; - const dirPath = path.resolve(this.cwd, dir); - - const id = dir.replace(/src[\\/]/, ''); - const moduleName = `App${pascalCase(id)}`; - const varName = `DIR_${id.replace(/[^a-zA-Z]/g, '_').toUpperCase()}_SRC`; - - fs.readdirSync(dirPath).forEach((name) => { - if (fs.statSync(path.join(dirPath, name)).isDirectory()) { - dirs.push(name); - } else if (sourceFileExt.includes(path.parse(name).ext)) { - files.push(name); - } - }); - - let total = files.length; - - if (dirs.length < 1 && total < 1) { - return 0; - } - - dirs = dirs.filter((subDir) => { - const count = this.generateCMakeFileForDirectory(path.join(dir, subDir), moduleNames); - total += count; - return count > 0; - }); - - if (total > 0) { - const lines = dirs.map((name) => `add_subdirectory(${name})`); - - if (addSource && files.length > 0) { - lines.push(`aux_source_directory(. ${varName})`); - lines.push(`add_library(${moduleName} \${${varName}})`); - } - if (dir !== 'src') { - moduleNames.push(moduleName); - } - this.writeFile(path.join(dirPath, cmakeFile), `${lines.join('\n')}\n`); - } - return total; - } - - generateCMakeFiles() { - const modules = []; - const file = `${cmakeFile}.in`; - - if (!fs.existsSync(this.sourceDir)) { - console.log(chalk.yellow('warning:'), '\'src\' directory does not exist'); - return; - } - - this.generateCMakeFileForDirectory('src', modules, false); - this.writeFile( - path.resolve(this.cwd, file), - format( - this.readTemplateFile(file), - { modules: modules.map((name) => ` ${name}`).reverse().join('\n') }, - ['\\[\\[', '\\]\\]'] - ) - ); - } - - generateXMakeFiles() { - const file = `${xmakeFile}.in`; - this.generateFile(file, path.resolve(this.cwd, file)); - } - - generate() { - if (this.name === 'xmake') { - this.generateXMakeFiles(); - } else { - this.generateCMakeFiles(); - } - } -} - -module.exports = Generator; diff --git a/generators/makefile/templates/CMakeLists.txt.in b/generators/makefile/templates/CMakeLists.txt.in deleted file mode 100644 index efa7fdb..0000000 --- a/generators/makefile/templates/CMakeLists.txt.in +++ /dev/null @@ -1,35 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(app) - -set(app_VERSION {{version}}) - -configure_file( - "${PROJECT_SOURCE_DIR}/include/config.h.in" - "${PROJECT_SOURCE_DIR}/include/config.h" -) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/app") - -if(WIN32) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS") - add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_UNICODE) -else() - set(CMAKE_C_FLAGS "-Wall") -endif(WIN32) - -link_directories("${PROJECT_SOURCE_DIR}/vendor/lib") -include_directories( - "${PROJECT_SOURCE_DIR}/include" - "${PROJECT_SOURCE_DIR}/src/lib" - "${PROJECT_SOURCE_DIR}/vendor/include" -) - -aux_source_directory(src DIR_SRC) -add_subdirectory(src) -add_executable(app ${DIR_SRC}) - -target_link_libraries( - app -[[modules]] - {{libs | join_with_space}} -) diff --git a/generators/makefile/templates/xmake.lua.in b/generators/makefile/templates/xmake.lua.in deleted file mode 100644 index dc20ca3..0000000 --- a/generators/makefile/templates/xmake.lua.in +++ /dev/null @@ -1,14 +0,0 @@ -set_project("app") -set_version("{{version}}") -set_warnings("all") -add_rules("mode.debug", "mode.release") -add_configfiles("include/config.h.in", { prefix = "APP" }) -add_linkdirs("vendor/lib") -add_includedirs("include", "src/lib", "vendor/include") -add_rpathdirs("./lib") -add_links({{libs | escape | join}}) - -target("app") - set_targetdir("app/") - set_kind("binary") - add_files("src/**.c") diff --git a/lib/compiler.js b/lib/compiler.js index 2d62da3..ce21711 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -1,10 +1,8 @@ const path = require("path"); -const I18nConfigCompiler = require("../compilers/i18n"); const ResourceCompiler = require("../compilers/resource"); const RouterConfigCompiler = require("../compilers/router"); const compilers = { - i18n: I18nConfigCompiler, router: RouterConfigCompiler, resource: ResourceCompiler, }; diff --git a/lib/generator.js b/lib/generator.js index 9b1b998..9f96837 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -1,11 +1,9 @@ const WidgetGenerator = require('../generators/widget'); const ViewGenerator = require('../generators/view'); -const MakefileGenerator = require('../generators/makefile'); const generators = { widget: WidgetGenerator, view: ViewGenerator, - makefile: MakefileGenerator, }; function generate(type, name) { diff --git a/lib/setup.js b/lib/setup.js index 4949200..ab37e67 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -25,7 +25,6 @@ function installDependencies() { function generateMakefiles() { logger.log(`\n${chalk.grey('[setup::makefiles]')}`); generate('makefile', 'xmake'); - generate('makefile', 'cmake'); } function setup() {