[waffle] [PATCH v2] waffle: make gl_basic to work with nacl
Tapani Pälli
tapani.palli at intel.com
Tue Jan 20 22:56:56 PST 2015
v2: fixes in cmake (Emil Velikov, Chad Versace)
Changed also nmf file content and generation, moved
nacl example content to separate output path.
Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
.gitignore | 1 +
cmake/Modules/WaffleDefineCompilerFlags.cmake | 10 ++++--
examples/CMakeLists.txt | 46 +++++++++++++++++++++++++++
examples/gl_basic.c | 21 ++++++++++++
examples/index.html | 43 +++++++++++++++++++++++++
5 files changed, 118 insertions(+), 3 deletions(-)
create mode 100644 examples/index.html
diff --git a/.gitignore b/.gitignore
index 6981cd7..99b8e09 100644
--- a/.gitignore
+++ b/.gitignore
@@ -59,6 +59,7 @@ Makefile
/doc/html/man/wflinfo.1.html
/examples/gl_basic
/examples/simple-x11-egl
+/html/
/lib/
/libcmocka.a
/src/waffle/libwaffle_static.a
diff --git a/cmake/Modules/WaffleDefineCompilerFlags.cmake b/cmake/Modules/WaffleDefineCompilerFlags.cmake
index 7532a91..679d09c 100644
--- a/cmake/Modules/WaffleDefineCompilerFlags.cmake
+++ b/cmake/Modules/WaffleDefineCompilerFlags.cmake
@@ -45,12 +45,16 @@ if (NOT MSVC)
# enough for single-stepping.
set(CMAKE_C_FLAGS_RELEASE "-g1 -O2 -DNDEBUG")
- waffle_add_c_flag("-Werror=implicit-function-declaration" WERROR_IMPLICIT_FUNCTION_DECLARATION)
+ # These are disabled for NaCl because compilation against ppapi_simple would fail.
+ if(NOT waffle_has_nacl)
+ waffle_add_c_flag("-Werror=implicit-function-declaration" WERROR_IMPLICIT_FUNCTION_DECLARATION)
+ waffle_add_c_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
+ endif()
+
waffle_add_c_flag("-Werror=incompatible-pointer-types" WERROR_INCOMPATIBLE_POINTER_TYPES)
waffle_add_c_flag("-Werror=int-conversion" WERROR_INT_CONVERSION)
- waffle_add_c_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
- if(waffle_on_linux)
+ if(waffle_on_linux AND NOT waffle_has_nacl)
# On MacOS, the SSE2 headers trigger this error.
waffle_add_c_flag("-Werror=missing-prototypes" WERROR_MISSING_PROTOTYPES)
endif()
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index fc0bda2..31a909b 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -17,6 +17,52 @@ if(waffle_on_linux AND waffle_has_x11_egl)
endif()
# ----------------------------------------------------------------------------
+# Target: gl_basic_nacl (executable + JSON manifest file)
+# ----------------------------------------------------------------------------
+if (waffle_has_nacl)
+ add_executable(gl_basic_nacl.nexe gl_basic.c)
+ include_directories(${nacl_INCLUDE_DIRS})
+
+ # Set path where to create and copy required files.
+ set(nacl_example_path ${PROJECT_SOURCE_DIR}/html/gl_basic_nacl)
+
+ file(MAKE_DIRECTORY ${nacl_example_path})
+
+ set_target_properties(gl_basic_nacl.nexe
+ PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY ${nacl_example_path}
+ )
+
+ target_link_libraries(gl_basic_nacl.nexe
+ ${waffle_libname}
+ ${nacl_LDFLAGS}
+ -lppapi_simple
+ -lnacl_io
+ )
+
+ # Create .nmf file that contains JSON manifest for the .nexe required by NaCl
+ # NOTE, this serves as example only and user might need to recreate nmf file
+ # suitable for the used environment. Extra entry for libppapi_gles2.so is added
+ # because we are not linking with it but require its presence during execution.
+ # --no-arch-prefix is used because '-x' has no option to set architecture for
+ # the extra entry.
+ add_custom_command(
+ OUTPUT gl_basic_nacl.nmf
+ COMMAND ${nacl_root}/tools/create_nmf.py --no-arch-prefix -x libppapi_gles2.so:libppapi_gles2.so -L${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${nacl_example_path}/gl_basic_nacl.nexe -o ${nacl_example_path}/gl_basic_nacl.nmf
+ DEPENDS gl_basic_nacl.nexe
+ COMMENT "Create JSON manifest"
+ VERBATIM
+ )
+
+ add_custom_target(gl_basic_create_json_manifest ALL
+ DEPENDS gl_basic_nacl.nmf)
+
+ # install index.html that loads gl_basic_nacl.nmf
+ file(INSTALL index.html DESTINATION ${nacl_example_path})
+
+endif()
+
+# ----------------------------------------------------------------------------
# Target: gl_basic (executable)
# ----------------------------------------------------------------------------
diff --git a/examples/gl_basic.c b/examples/gl_basic.c
index 69418c8..311593a 100644
--- a/examples/gl_basic.c
+++ b/examples/gl_basic.c
@@ -520,8 +520,20 @@ removeXcodeArgs(int *argc, char **argv)
#endif // __APPLE__
+#ifdef __native_client__
+#include "ppapi_simple/ps_main.h"
+//
+// We need to rename main() for native client
+// because ppapi_simple already defines main().
+//
+int basic_test_main(int argc, char **argv);
+PPAPI_SIMPLE_REGISTER_MAIN(basic_test_main)
+int
+basic_test_main(int argc, char **argv)
+#else
int
main(int argc, char **argv)
+#endif
{
bool ok;
int i;
@@ -542,9 +554,18 @@ main(int argc, char **argv)
cocoa_init();
#endif
+ #ifdef __native_client__
+ // Fixed arguments for native client.
+ opts.context_api = WAFFLE_CONTEXT_OPENGL_ES2;
+ opts.platform = WAFFLE_PLATFORM_NACL;
+ opts.dl = WAFFLE_DL_OPENGL_ES2;
+ opts.context_profile = WAFFLE_NONE;
+ opts.context_version = -1;
+ #else
ok = parse_args(argc, argv, &opts);
if (!ok)
exit(EXIT_FAILURE);
+ #endif
i = 0;
init_attrib_list[i++] = WAFFLE_PLATFORM;
diff --git a/examples/index.html b/examples/index.html
new file mode 100644
index 0000000..ee57fef
--- /dev/null
+++ b/examples/index.html
@@ -0,0 +1,43 @@
+<!--
+// Copyright 2014 Intel Corporation
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// - Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Waffle NaCl example</title>
+</head>
+
+<body>
+ <!--
+ NOTE - The example .nmf file makes assumption that required
+ libraries exist within same directory as the executable. If
+ this is not the case please recreate .nmf file suitable for
+ your environment.
+ -->
+ <embed id="waffle" src="gl_basic_nacl.nmf" type="application/x-nacl"/>
+</body>
+</html>
--
2.1.0
More information about the waffle
mailing list