From a2e784666229207c2a4ce2f436b7941fa693ac52 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 29 Feb 2024 10:57:15 +0800 Subject: [PATCH] enable rtti --- CMakeLists.txt | 4 ++-- README.md | 1 + amalgamate.py | 2 +- build.sh | 2 +- build_web.sh | 2 +- build_with_warnings.sh | 2 +- docs/quick-start/installation.md | 1 + 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbb92eb5..71ef3419 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,11 +8,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /utf-8 /O2") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -O2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -frtti -O2") # disable -Wshorten-64-to-32 for apple if(APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-shorten-64-to-32") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -frtti -Wno-shorten-64-to-32") endif() endif() diff --git a/README.md b/README.md index 0721da5e..c26ec0c8 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ It is safe to use `main` branch in production. To compile it with your project, these flags must be set: + `--std=c++17` flag must be set ++ RTTI must be enabled + Exception must be enabled + For MSVC, `/utf-8` flag must be set diff --git a/amalgamate.py b/amalgamate.py index bd22679f..e70b76c4 100644 --- a/amalgamate.py +++ b/amalgamate.py @@ -82,7 +82,7 @@ with open("amalgamated/main.cpp", "wt", encoding='utf-8', newline='\n') as f: f.write(text) if sys.platform in ['linux', 'darwin']: - ok = os.system("clang++ -o main amalgamated/main.cpp -O1 --std=c++17 -stdlib=libc++") + ok = os.system("clang++ -o main amalgamated/main.cpp -O1 --std=c++17 -frtti -stdlib=libc++") if ok == 0: print("Test build success!") diff --git a/build.sh b/build.sh index c9309202..a474d17f 100644 --- a/build.sh +++ b/build.sh @@ -22,7 +22,7 @@ SRC=$(find src/ -name "*.cpp") echo "> Compiling and linking source files... " -FLAGS="-std=c++17 -O1 -stdlib=libc++ -Wfatal-errors -Iinclude" +FLAGS="-std=c++17 -O1 -stdlib=libc++ -frtti -Wfatal-errors -Iinclude" if [[ "$OSTYPE" == "darwin"* ]]; then LIB_EXTENSION=".dylib" diff --git a/build_web.sh b/build_web.sh index b6cc1929..8695f700 100644 --- a/build_web.sh +++ b/build_web.sh @@ -4,4 +4,4 @@ rm -rf web/lib mkdir web/lib SRC=$(find src/ -name "*.cpp") -em++ $SRC -Iinclude/ -fexceptions -s -Os -sEXPORTED_FUNCTIONS=_pkpy_new_repl,_pkpy_repl_input,_pkpy_new_vm -sEXPORTED_RUNTIME_METHODS=ccall -o web/lib/pocketpy.js +em++ $SRC -Iinclude/ -fexceptions -frtti -s -Os -sEXPORTED_FUNCTIONS=_pkpy_new_repl,_pkpy_repl_input,_pkpy_new_vm -sEXPORTED_RUNTIME_METHODS=ccall -o web/lib/pocketpy.js diff --git a/build_with_warnings.sh b/build_with_warnings.sh index 8febbaf0..a8181662 100644 --- a/build_with_warnings.sh +++ b/build_with_warnings.sh @@ -1,5 +1,5 @@ SRC=$(find src/ -name "*.cpp") -FLAGS="-std=c++17 -O1 -stdlib=libc++ -Iinclude -W -Wno-unused-parameter" +FLAGS="-std=c++17 -O1 -stdlib=libc++ -Iinclude -frtti -W -Wno-unused-parameter" clang++ $FLAGS -o main -O1 src2/main.cpp $SRC diff --git a/docs/quick-start/installation.md b/docs/quick-start/installation.md index b7d7ccff..fe702f78 100644 --- a/docs/quick-start/installation.md +++ b/docs/quick-start/installation.md @@ -43,6 +43,7 @@ It is safe to use `main` branch in production. To compile it with your project, these flags must be set: + `--std=c++17` flag must be set ++ RTTI must be enabled + Exception must be enabled + For MSVC, `/utf-8` flag must be set