Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interoperability between CMAKE_BUILD_TYPE and PSP_DEBUG #381

Merged
merged 3 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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")


Expand Down Expand Up @@ -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 \
Expand All @@ -123,7 +145,7 @@ else()
#####################
# VANILLA CPP BUILD #
#####################
if(DEFINED ENV{PSP_DEBUG})
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
set(OPT_FLAGS " \
-O1 \
-g3 \
Expand Down Expand Up @@ -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}")
Expand Down
7 changes: 6 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -140,5 +144,6 @@ try {
}
lerna();
} catch (e) {
console.log(e);
process.exit(1);
}
20 changes: 18 additions & 2 deletions scripts/build_cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions scripts/build_python.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ try {
execute(cmd);
}
} catch (e) {
console.log(e);
process.exit(1);
}
1 change: 1 addition & 0 deletions scripts/lint_python.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ try {
execute(cmd);
}
} catch (e) {
console.log(e);
process.exit(1);
}
1 change: 1 addition & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ try {
}
}
} catch (e) {
console.log(e);
process.exit(1);
}
3 changes: 2 additions & 1 deletion scripts/test_cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions scripts/test_python.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ try {
execute(cmd);
}
} catch (e) {
console.log(e);
process.exit(1);
}