diff options
author | 杨宇千 <crupest@outlook.com> | 2019-07-11 00:43:27 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-07-11 00:43:27 +0800 |
commit | cafcbde7529f7c1e4219344df9a404ecdb411aa5 (patch) | |
tree | a4b515131bb026d12db92eaa1d3f9f32a7a65505 | |
parent | d163bafa461779a3795818aa8c8b5238880ede24 (diff) | |
download | cru-cafcbde7529f7c1e4219344df9a404ecdb411aa5.tar.gz cru-cafcbde7529f7c1e4219344df9a404ecdb411aa5.tar.bz2 cru-cafcbde7529f7c1e4219344df9a404ecdb411aa5.zip |
...
-rw-r--r-- | include/cru/platform/heap_debug.hpp | 6 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/main.cpp | 8 | ||||
-rw-r--r-- | src/win/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/win/heap_debug.cpp | 11 | ||||
-rw-r--r-- | tools/generate_clang_complete.py | 18 |
6 files changed, 35 insertions, 10 deletions
diff --git a/include/cru/platform/heap_debug.hpp b/include/cru/platform/heap_debug.hpp new file mode 100644 index 00000000..e305be31 --- /dev/null +++ b/include/cru/platform/heap_debug.hpp @@ -0,0 +1,6 @@ +#pragma once +#include "cru/common/pre_config.hpp" + +namespace cru::platform { +void SetupHeapDebug(); +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f0010345..50092e1c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources(cru_platform_base INTERFACE ${CRU_PLATFORM_BASE_INCLUDE_DIR}/debug.hpp ${CRU_PLATFORM_BASE_INCLUDE_DIR}/exception.hpp ${CRU_PLATFORM_BASE_INCLUDE_DIR}/graphic_base.hpp + ${CRU_PLATFORM_BASE_INCLUDE_DIR}/heap_debug.hpp ${CRU_PLATFORM_BASE_INCLUDE_DIR}/matrix.hpp ${CRU_PLATFORM_BASE_INCLUDE_DIR}/native_resource.hpp ${CRU_PLATFORM_BASE_INCLUDE_DIR}/string_util.hpp diff --git a/src/main.cpp b/src/main.cpp index f9c0e56b..9336dda7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include "cru/platform/heap_debug.hpp" #include "cru/platform/native/native_window.hpp" #include "cru/platform/native/ui_applicaition.hpp" #include "cru/ui/controls/button.hpp" @@ -12,16 +13,11 @@ using cru::ui::Window; using cru::ui::controls::Button; using cru::ui::controls::FlexLayout; using cru::ui::controls::TextBlock; -/* -int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPWSTR lpCmdLine, int nCmdShow) { -*/ int main() { - #ifdef CRU_DEBUG - _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); + cru::platform::SetupHeapDebug(); #endif std::unique_ptr<UiApplication> application(UiApplication::CreateInstance()); diff --git a/src/win/CMakeLists.txt b/src/win/CMakeLists.txt index 0076b3b2..d7d4ba96 100644 --- a/src/win/CMakeLists.txt +++ b/src/win/CMakeLists.txt @@ -3,6 +3,7 @@ set(CRU_WIN_BASE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/win/) add_library(cru_win_base STATIC debug.cpp exception.cpp + heap_debug.cpp string_util.cpp ) target_sources(cru_win_base PUBLIC diff --git a/src/win/heap_debug.cpp b/src/win/heap_debug.cpp new file mode 100644 index 00000000..33ebae7c --- /dev/null +++ b/src/win/heap_debug.cpp @@ -0,0 +1,11 @@ +#include "cru/win/win_pre_config.hpp" + +#include "cru/platform/heap_debug.hpp" + +#include <crtdbg.h> + +namespace cru::platform { +void SetupHeapDebug() { + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +} +} diff --git a/tools/generate_clang_complete.py b/tools/generate_clang_complete.py index 44da60f3..9b650b9c 100644 --- a/tools/generate_clang_complete.py +++ b/tools/generate_clang_complete.py @@ -1,6 +1,12 @@ +import argparse import os import os.path +parser = argparse.ArgumentParser() +parser.add_argument('-d', '--debug', action='store_true', + default='Debug', help='specify build configuration') +args = parser.parse_args() + clang_complete_file_name = '.clang_complete' # project root dir @@ -8,7 +14,7 @@ project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) os.chdir(project_root) global_std_standard = 'c++17' # change this to change standard -global_std_standard_arg = '-std={}'.format(global_std_standard) +global_std_standard_arg = '--std={}'.format(global_std_standard) global_include_paths = [ os.path.abspath('include') @@ -16,6 +22,9 @@ global_include_paths = [ global_definitions = [] +if args.debug: + global_definitions.append('_DEBUG') + def generate_clang_complete_content(additional_include_paths=[], additional_definitions=[]): include_args = [ @@ -27,7 +36,7 @@ def generate_clang_complete_content(additional_include_paths=[], additional_defi def generate_root_clang_complete(): - with open(os.path.join('src/', clang_complete_file_name), 'w') as f: + with open(clang_complete_file_name, 'w') as f: print(generate_clang_complete_content(), file=f) @@ -36,8 +45,9 @@ def generate_win_clang_complete_content(): def generate_win_clang_complete(): - with open(os.path.join('src/win/', clang_complete_file_name), 'w') as f: - print(generate_win_clang_complete_content(), file=f) + for path in ['src/win/', 'include/cru/win/']: + with open(os.path.join(path, clang_complete_file_name), 'w') as f: + print(generate_win_clang_complete_content(), file=f) generate_root_clang_complete() generate_win_clang_complete() |