From 32cb557470e0a81a956ba8e49dc045c694ba0477 Mon Sep 17 00:00:00 2001 From: ZtRXR Date: Thu, 11 Apr 2024 23:38:08 +0800 Subject: [PATCH] publish --- .gitignore | 1 + .vscode/PythonImportHelper-v2-Completion.json | 155 ++++++++++++++ .vscode/settings.json | 5 + README.md | 70 +++++++ .../PythonImportHelper-v2-Completion.json | 195 ++++++++++++++++++ pymake/__init__.py | 3 + pymake/lib/cmake.py | 59 ++++++ pymake/lib/tools.py | 8 + pymake/lib/values.py | 16 ++ pyproject.toml | 15 ++ 10 files changed, 527 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/PythonImportHelper-v2-Completion.json create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 pymake/.vscode/PythonImportHelper-v2-Completion.json create mode 100644 pymake/__init__.py create mode 100644 pymake/lib/cmake.py create mode 100644 pymake/lib/tools.py create mode 100644 pymake/lib/values.py create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4be6e16 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist/* \ No newline at end of file diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json new file mode 100644 index 0000000..4bf216a --- /dev/null +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -0,0 +1,155 @@ +[ + { + "label": "cmake", + "kind": 6, + "importPath": "pymake.lib.cmake", + "description": "pymake.lib.cmake", + "peekOfCode": "class cmake:\n __write_stack:\"list[str]\" = []\n __file_name = \"\"\n def __init__(self,version_min:\"str\",file_name:\"str\"=\"CMakeLists.txt\") -> None:\n self.__file_name = file_name\n self.__write_stack.append(f\"cmake_minimum_required(VERSION {version_min})\")\n def write(self)->None:\n with open(file=self.__file_name,mode=\"+w\",encoding=\"utf8\") as f:\n for i in self.__write_stack:\n f.write(i)", + "detail": "pymake.lib.cmake", + "documentation": {} + }, + { + "label": "var", + "kind": 2, + "importPath": "pymake.lib.tools", + "description": "pymake.lib.tools", + "peekOfCode": "def var(name:\"str\")->\"str\":\n return f\"${{{name}}}\"\ndef args_to_str(args:\"list[str]\")->str:\n vars_str = \"\"\n for i in args:\n vars_str=f\"{vars_str} {i}\"\n return vars_str", + "detail": "pymake.lib.tools", + "documentation": {} + }, + { + "label": "args_to_str", + "kind": 2, + "importPath": "pymake.lib.tools", + "description": "pymake.lib.tools", + "peekOfCode": "def args_to_str(args:\"list[str]\")->str:\n vars_str = \"\"\n for i in args:\n vars_str=f\"{vars_str} {i}\"\n return vars_str", + "detail": "pymake.lib.tools", + "documentation": {} + }, + { + "label": "cmake_export_compile_cmmands", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "cmake_export_compile_cmmands = \"CMAKE_EXPORT_COMPILE_COMMANDS\"\nproject_name=\"PROJECT_NAME\"\npublic = \"PUBLIC\"\nstatic = \"STATIC\"\nshared = \"SHARED\"\nmodule = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "public", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "public = \"PUBLIC\"\nstatic = \"STATIC\"\nshared = \"SHARED\"\nmodule = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "static", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "static = \"STATIC\"\nshared = \"SHARED\"\nmodule = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "shared", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "shared = \"SHARED\"\nmodule = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "module", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "module = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "private", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "private = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "interface", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "interface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "glob_recurse", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "glob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "cmake_cxx_standard", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "cmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "cmake_cxx_flags", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "cmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "o3", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "o3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "o2", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "o2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "cmake_cxx_flags_release", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "cmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "pymake.lib.values", + "documentation": {} + }, + { + "label": "cmake_cxx_flags_debug", + "kind": 5, + "importPath": "pymake.lib.values", + "description": "pymake.lib.values", + "peekOfCode": "cmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "pymake.lib.values", + "documentation": {} + } +] \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..679b479 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "python.analysis.extraPaths": [ + "./pymake" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..79eea9d --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# 介绍 + +>一个用python脚本的方式书写cmake的python库 + +# 如何安装 + +用.pth文件自行定位到本项目的文件夹中 + +# 如何使用 +>生成一个用于GLFW编程的CMakeLists +```python +from pymake import * + +( + cmake("3.20") + .set(cmake_cxx_standard,"20") + .set(cmake_cxx_flags,o3) + .set(cmake_export_compile_cmmands,on) + .project("test_glfw") + .file("SRC",glob_recurse,"source/*.cpp","source/*.c") + .add_executable(var(project_name),var("SRC")) + .target_link_libraries("glfw3",var(project_name),public) + .target_link_libraries("GL",var(project_name),public) + .write() +) +``` +>自动生成如下 +```cmake +cmake_minimum_required(VERSION 3.20) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_FLAGS -O3) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +project(test_glfw VERSION 1.0 DESCRIPTION "a default project" LANGUAGES CXX) +file(GLOB_RECURSE SRC source/*.cpp source/*.c) +add_executable(${PROJECT_NAME} ${SRC}) +target_link_libraries(${PROJECT_NAME} PUBLIC glfw3) +target_link_libraries(${PROJECT_NAME} PUBLIC GL) + +``` +>生成一个库文件 + +```python +from pymake import * + +( + cmake("3.20") + .set(cmake_export_compile_cmmands,"ON") + .set(cmake_cxx_flags,o3) + .set(cmake_cxx_standard,"17") + .project(name="say_hello") + .add_library(var(project_name),static,"main.cpp") + .target_include_directories(var(project_name),public,"include") + .write() +) +``` + +```bash +python make.py +``` +将会生成CMakeLists.txt如下 +```cmake +cmake_minimum_required(VERSION 3.20) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_CXX_FLAGS -O3) +set(CMAKE_CXX_STANDARD 17) +project(say_hello VERSION 1.0 DESCRIPTION "a default project" LANGUAGES CXX) +add_library(${PROJECT_NAME} STATIC main.cpp) +target_include_directories(${PROJECT_NAME} PUBLIC include) + +``` \ No newline at end of file diff --git a/pymake/.vscode/PythonImportHelper-v2-Completion.json b/pymake/.vscode/PythonImportHelper-v2-Completion.json new file mode 100644 index 0000000..79faa80 --- /dev/null +++ b/pymake/.vscode/PythonImportHelper-v2-Completion.json @@ -0,0 +1,195 @@ +[ + { + "label": "*", + "importPath": "lib.tools", + "description": "lib.tools", + "isExtraImport": true, + "detail": "lib.tools", + "documentation": {} + }, + { + "label": "*", + "importPath": "lib.tools", + "description": "lib.tools", + "isExtraImport": true, + "detail": "lib.tools", + "documentation": {} + }, + { + "label": "*", + "importPath": "lib.values", + "description": "lib.values", + "isExtraImport": true, + "detail": "lib.values", + "documentation": {} + }, + { + "label": "*", + "importPath": "lib.values", + "description": "lib.values", + "isExtraImport": true, + "detail": "lib.values", + "documentation": {} + }, + { + "label": "*", + "importPath": "lib.cmake", + "description": "lib.cmake", + "isExtraImport": true, + "detail": "lib.cmake", + "documentation": {} + }, + { + "label": "cmake", + "kind": 6, + "importPath": "lib.cmake", + "description": "lib.cmake", + "peekOfCode": "class cmake:\n __write_stack:\"list[str]\" = []\n __file_name = \"\"\n def __init__(self,version_min:\"str\",file_name:\"str\"=\"CMakeLists.txt\") -> None:\n self.__file_name = file_name\n self.__write_stack.append(f\"cmake_minimum_required(VERSION {version_min})\")\n def write(self)->None:\n with open(file=self.__file_name,mode=\"+w\",encoding=\"utf8\") as f:\n for i in self.__write_stack:\n f.write(i)", + "detail": "lib.cmake", + "documentation": {} + }, + { + "label": "var", + "kind": 2, + "importPath": "lib.tools", + "description": "lib.tools", + "peekOfCode": "def var(name:\"str\")->\"str\":\n return f\"${{{name}}}\"\ndef args_to_str(args:\"list[str]\")->str:\n vars_str = \"\"\n for i in args:\n vars_str=f\"{vars_str} {i}\"\n return vars_str", + "detail": "lib.tools", + "documentation": {} + }, + { + "label": "args_to_str", + "kind": 2, + "importPath": "lib.tools", + "description": "lib.tools", + "peekOfCode": "def args_to_str(args:\"list[str]\")->str:\n vars_str = \"\"\n for i in args:\n vars_str=f\"{vars_str} {i}\"\n return vars_str", + "detail": "lib.tools", + "documentation": {} + }, + { + "label": "cmake_export_compile_cmmands", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "cmake_export_compile_cmmands = \"CMAKE_EXPORT_COMPILE_COMMANDS\"\nproject_name=\"PROJECT_NAME\"\npublic = \"PUBLIC\"\nstatic = \"STATIC\"\nshared = \"SHARED\"\nmodule = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "public", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "public = \"PUBLIC\"\nstatic = \"STATIC\"\nshared = \"SHARED\"\nmodule = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "static", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "static = \"STATIC\"\nshared = \"SHARED\"\nmodule = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "shared", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "shared = \"SHARED\"\nmodule = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "module", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "module = \"MODULE\"\nprivate = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "private", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "private = \"PRIVATE\"\ninterface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "interface", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "interface = \"INTERFACE\"\nglob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "glob_recurse", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "glob_recurse = \"GLOB_RECURSE\"\ncmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "cmake_cxx_standard", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "cmake_cxx_standard = \"CMAKE_CXX_STANDARD\"\ncmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "cmake_cxx_flags", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "cmake_cxx_flags = \"CMAKE_CXX_FLAGS\"\no3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "o3", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "o3 = \"-O3\"\no2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "o2", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "o2 = \"-O2\"\ncmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "cmake_cxx_flags_release", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "cmake_cxx_flags_release = \"CMAKE_CXX_FLAGS_RELEASE\"\ncmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "lib.values", + "documentation": {} + }, + { + "label": "cmake_cxx_flags_debug", + "kind": 5, + "importPath": "lib.values", + "description": "lib.values", + "peekOfCode": "cmake_cxx_flags_debug = \"CMAKE_CXX_FLAGS_DEBUG\"\non=\"ON\"", + "detail": "lib.values", + "documentation": {} + } +] \ No newline at end of file diff --git a/pymake/__init__.py b/pymake/__init__.py new file mode 100644 index 0000000..c887689 --- /dev/null +++ b/pymake/__init__.py @@ -0,0 +1,3 @@ +from .lib.values import * +from .lib.cmake import * +from .lib.tools import * \ No newline at end of file diff --git a/pymake/lib/cmake.py b/pymake/lib/cmake.py new file mode 100644 index 0000000..6644455 --- /dev/null +++ b/pymake/lib/cmake.py @@ -0,0 +1,59 @@ +from .tools import * +from .values import * + +class cmake: + __write_stack:"list[str]" = [] + __file_name = "" + def __init__(self,version_min:"str",file_name:"str"="CMakeLists.txt") -> None: + self.__file_name = file_name + self.__write_stack.append(f"cmake_minimum_required(VERSION {version_min})") + + def write(self)->None: + with open(file=self.__file_name,mode="+w",encoding="utf8") as f: + for i in self.__write_stack: + f.write(i) + f.write("\n") + + def project(self,name:"str"="default",version:"str"="1.0",description:"str"="a default project",languages:"str"="CXX")->"cmake": + self.__write_stack.append(f"project({name} VERSION {version} DESCRIPTION \"{description}\" LANGUAGES {languages})") + return self + + def add_executable(self,name:"str"=var(project_name),*source:"str")->"cmake": + self.__write_stack.append(f"add_executable({name} {args_to_str(source)})") + return self + + def add_library(self,name:"str"=var(project_name),mode:"str"=static,*source:"str")->"cmake": + """ + ARGS: + mode: mode can be STATIC , SHARED or MODULE + """ + self.__write_stack.append(f"add_library({name} {mode} {args_to_str(source)})") + return self + + def target_include_directories(self,for_project:"str"=var(project_name),mode:"str"=public,*directories:"str")->"cmake": + """ + ARGS: + mode : mode can be PUBLIC PRIVATE INTERFACE + """ + self.__write_stack.append(f"target_include_directories({for_project} {mode} {args_to_str(directories)})") + return self + + def set(self,name:"str",value:"str")->"cmake": + self.__write_stack.append(f"set({name} {value})") + return self + + def target_link_libraries(self,lib_name:"str",name:"str"=var(project_name),mode:"str"=public)->"cmake": + self.__write_stack.append(f"target_link_libraries({name} {mode} {lib_name})") + return self + + def target_link_directories(self,name:"str"=var(project_name),mode:"str"=public,*directories:"str")->"cmake": + self.__write_stack.append(f"target_link_directories({name} {mode} {args_to_str(directories)})") + return self + + def just_add(self,sentence:"str")->"cmake": + self.__write_stack.append(sentence) + return self + + def file(self,new_var_name:"str",mode:"str"=glob_recurse,*search_str:"str")->"cmake": + self.__write_stack.append(f"file({mode} {new_var_name} {args_to_str(search_str)})") + return self \ No newline at end of file diff --git a/pymake/lib/tools.py b/pymake/lib/tools.py new file mode 100644 index 0000000..5704240 --- /dev/null +++ b/pymake/lib/tools.py @@ -0,0 +1,8 @@ +def var(name:"str")->"str": + return f"${{{name}}}" + +def args_to_str(args:"list[str]")->str: + vars_str = "" + for i in args: + vars_str=f"{vars_str} {i}" + return vars_str diff --git a/pymake/lib/values.py b/pymake/lib/values.py new file mode 100644 index 0000000..15e6cf8 --- /dev/null +++ b/pymake/lib/values.py @@ -0,0 +1,16 @@ +cmake_export_compile_cmmands = "CMAKE_EXPORT_COMPILE_COMMANDS" +project_name="PROJECT_NAME" +public = "PUBLIC" +static = "STATIC" +shared = "SHARED" +module = "MODULE" +private = "PRIVATE" +interface = "INTERFACE" +glob_recurse = "GLOB_RECURSE" +cmake_cxx_standard = "CMAKE_CXX_STANDARD" +cmake_cxx_flags = "CMAKE_CXX_FLAGS" +o3 = "-O3" +o2 = "-O2" +cmake_cxx_flags_release = "CMAKE_CXX_FLAGS_RELEASE" +cmake_cxx_flags_debug = "CMAKE_CXX_FLAGS_DEBUG" +on="ON" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8c949dc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "pymake" +version = "0.1.0" +description = "一个基于函数式编程用于生成cmake文件的python库" +authors = ["Zengtudor"] +license = "MIT" +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.10" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"