diff --git a/CMakeLists.txt b/CMakeLists.txt index f062a2008c..c2a0a4b1c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,14 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/" ${CMAKE_MODULE_PATH} ####################### find_package(Color) +option(CMAKE_BUILD_TYPE "Release/Debug build" RELEASE) +option(PSP_WASM_BUILD "Build the WebAssembly Project" ON) +option(PSP_CPP_BUILD "Build the C++ Project" OFF) +option(PSP_CPP_BUILD_TESTS "Build the C++ Tests" OFF) +option(PSP_PYTHON_BUILD "Build the Python Bindings" OFF) +option(PSP_CPP_BUILD_STRICT "Build the C++ with strict warnings" OFF) + + if (NOT DEFINED PSP_WASM_BUILD) set(PSP_WASM_BUILD ON) set(PSP_CPP_BUILD OFF) @@ -20,6 +28,14 @@ if (PSP_WASM_BUILD AND PSP_CPP_BUILD) message(FATAL_ERROR "${Red}CPP and Emscripten builds must be done separately${ColorReset}") endif() +if (NOT DEFINED CMAKE_BUILD_TYPE) + if(DEFINED ENV{PSP_DEBUG}) + set(CMAKE_BUILD_TYPE DEBUG) + else() + set(CMAKE_BUILD_TYPE RELEASE) + endif() +endif() + if (NOT DEFINED PSP_CPP_BUILD) set(PSP_CPP_BUILD ON) endif() @@ -62,12 +78,18 @@ else() message(WARNING "${Cyan}Skipping C++ tests${ColorReset}") endif() -if (NOT PSP_CPP_BUILD_STRICT) +if (PSP_CPP_BUILD AND NOT PSP_CPP_BUILD_STRICT) message(WARNING "${Cyan}Building C++ without strict warnings${ColorReset}") endif() +string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER ) +if(CMAKE_BUILD_TYPE_LOWER STREQUAL debug) + message(WARNING "${Red}Building DEBUG${ColorReset}") + add_definitions(-DPSP_DEBUG) +else() + message(WARNING "${Cyan}Building RELEASE${ColorReset}") +endif() ####################### - include_directories("${CMAKE_SOURCE_DIR}/src/include") @@ -98,7 +120,7 @@ if (PSP_WASM_BUILD) -s EXPORTED_FUNCTIONS=\"['_main']\" \ ") - if(DEFINED ENV{PSP_DEBUG}) + if(CMAKE_BUILD_TYPE MATCHES DEBUG) set(OPT_FLAGS " \ -O0 \ -g4 \ @@ -123,7 +145,7 @@ else() ##################### # VANILLA CPP BUILD # ##################### - if(DEFINED ENV{PSP_DEBUG}) + if(CMAKE_BUILD_TYPE MATCHES DEBUG) set(OPT_FLAGS " \ -O1 \ -g3 \ @@ -278,7 +300,7 @@ if (PSP_WASM_BUILD) set_target_properties(perspective.sync PROPERTIES OUTPUT_NAME "psp.sync") add_dependencies(perspective.sync perspective.async) - if (NOT DEFINED ENV{PSP_DEBUG}) + if (NOT CMAKE_BUILD_TYPE_LOWER STREQUAL debug) add_executable(perspective.asm src/cpp/main.cpp) target_link_libraries(perspective.asm psp "${ASMJS_MODE_FLAGS}") set_target_properties(perspective.asm PROPERTIES COMPILE_FLAGS "${ASMJS_MODE_FLAGS}") diff --git a/scripts/build.js b/scripts/build.js index bb3ae326fd..94dcbb3899 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -115,7 +115,11 @@ function docker(image = "emsdk") { } function compileCPP() { - let cmd = `emcmake cmake ../ && emmake make -j${process.env.PSP_CPU_COUNT || os.cpus().length}`; + let cmd = `emcmake cmake ../ `; + if(process.env.PSP_DEBUG){ + cmd += `-DCMAKE_BUILD_TYPE=debug`; + } + cmd += `&& emmake make -j${process.env.PSP_CPU_COUNT || os.cpus().length}`; if (process.env.PSP_DOCKER) { cmd = `${docker()} bash -c 'cd obj && ${cmd}'`; } else { @@ -140,5 +144,6 @@ try { } lerna(); } catch (e) { + console.log(e); process.exit(1); } diff --git a/scripts/build_cpp.js b/scripts/build_cpp.js index 1db1c5fc32..ca1b522ce9 100644 --- a/scripts/build_cpp.js +++ b/scripts/build_cpp.js @@ -23,13 +23,29 @@ function docker(image = "emsdk") { try { execute("mkdir -p cppbuild"); + + let cmd; + + if (process.env.PSP_DOCKER) { + cmd = " "; + } else { + cmd = "cd cppbuild && "; + } + + cmd += " cmake ../ -DPSP_WASM_BUILD=0 -DPSP_CPP_BUILD=1 -DPSP_CPP_BUILD_TESTS=1"; + + if(process.env.PSP_DEBUG){ + cmd += `-DCMAKE_BUILD_TYPE=debug`; + } + if (process.env.PSP_DOCKER) { - execute(docker("cpp") + " cmake ../ -DPSP_WASM_BUILD=0 -DPSP_CPP_BUILD=1 -DPSP_CPP_BUILD_TESTS=1"); + execute(docker("cpp") + cmd); execute(docker("cpp") + " make -j${PSP_CPU_COUNT-8}"); } else { - execute("cd cppbuild && cmake ../ -DPSP_WASM_BUILD=0 -DPSP_CPP_BUILD=1 -DPSP_CPP_BUILD_TESTS=1"); + execute(cmd); execute("cd cppbuild && make -j${PSP_CPU_COUNT-8}"); } } catch (e) { + console.log(e); process.exit(1); } diff --git a/scripts/build_python.js b/scripts/build_python.js index 88faae7cee..01621113d5 100644 --- a/scripts/build_python.js +++ b/scripts/build_python.js @@ -29,5 +29,6 @@ try { execute(cmd); } } catch (e) { + console.log(e); process.exit(1); } diff --git a/scripts/lint_python.js b/scripts/lint_python.js index 0d20dc9d77..4be2108c81 100644 --- a/scripts/lint_python.js +++ b/scripts/lint_python.js @@ -29,5 +29,6 @@ try { execute(cmd); } } catch (e) { + console.log(e); process.exit(1); } diff --git a/scripts/test.js b/scripts/test.js index d348be5201..f44997a837 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -108,5 +108,6 @@ try { } } } catch (e) { + console.log(e); process.exit(1); } diff --git a/scripts/test_cpp.js b/scripts/test_cpp.js index 0fbdb7d52e..fdd5c65283 100644 --- a/scripts/test_cpp.js +++ b/scripts/test_cpp.js @@ -26,8 +26,9 @@ try { if (process.env.PSP_DOCKER) { execute(docker("cpp") + " ./test/psp_test"); } else { - execute("./test/psp_test"); + execute("./cppbuild/test/psp_test"); } } catch (e) { + console.log(e); process.exit(1); } diff --git a/scripts/test_python.js b/scripts/test_python.js index 9c7e7edf2f..17546ac6d7 100644 --- a/scripts/test_python.js +++ b/scripts/test_python.js @@ -45,5 +45,6 @@ try { execute(cmd); } } catch (e) { + console.log(e); process.exit(1); }