publish
This commit is contained in:
commit
32cb557470
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
dist/*
|
155
.vscode/PythonImportHelper-v2-Completion.json
vendored
Normal file
155
.vscode/PythonImportHelper-v2-Completion.json
vendored
Normal file
@ -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": {}
|
||||
}
|
||||
]
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"python.analysis.extraPaths": [
|
||||
"./pymake"
|
||||
]
|
||||
}
|
70
README.md
Normal file
70
README.md
Normal file
@ -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)
|
||||
|
||||
```
|
195
pymake/.vscode/PythonImportHelper-v2-Completion.json
vendored
Normal file
195
pymake/.vscode/PythonImportHelper-v2-Completion.json
vendored
Normal file
@ -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": {}
|
||||
}
|
||||
]
|
3
pymake/__init__.py
Normal file
3
pymake/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .lib.values import *
|
||||
from .lib.cmake import *
|
||||
from .lib.tools import *
|
59
pymake/lib/cmake.py
Normal file
59
pymake/lib/cmake.py
Normal file
@ -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
|
8
pymake/lib/tools.py
Normal file
8
pymake/lib/tools.py
Normal file
@ -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
|
16
pymake/lib/values.py
Normal file
16
pymake/lib/values.py
Normal file
@ -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"
|
15
pyproject.toml
Normal file
15
pyproject.toml
Normal file
@ -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"
|
Loading…
Reference in New Issue
Block a user