Skip to content

Commit

Permalink
Fix WebAssembly build
Browse files Browse the repository at this point in the history
WebAssembly build has been broken for a while. These changes fix that,
as well improve the build process itself as it adds more automation in
the process.
  • Loading branch information
RauliL committed Aug 1, 2018
1 parent 5d3abe5 commit 8359086
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 37 deletions.
17 changes: 9 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ OPTION(
OFF
)

ADD_SUBDIRECTORY(libplorth)
IF(PLORTH_ENABLE_CLI)
ADD_SUBDIRECTORY(cli)
ENDIF()
IF(PLORTH_ENABLE_GUI)
ADD_SUBDIRECTORY(gui)
ENDIF()
IF(PLORTH_ENABLE_WEBASSEMBLY)
IF(DEFINED ENV{EMSCRIPTEN})
ADD_SUBDIRECTORY(webassembly)
ELSE()
ADD_SUBDIRECTORY(libplorth)
IF(PLORTH_ENABLE_CLI)
ADD_SUBDIRECTORY(cli)
ENDIF()
IF(PLORTH_ENABLE_GUI)
ADD_SUBDIRECTORY(gui)
ENDIF()
ENDIF()
1 change: 1 addition & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/include/plorth/cli/config.hpp
14 changes: 14 additions & 0 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT(plorth-cli C CXX)

INCLUDE(CheckIncludeFile)
INCLUDE(CheckFunctionExists)

CHECK_INCLUDE_FILE(sysexits.h HAVE_SYSEXITS_H)

CHECK_FUNCTION_EXISTS(fork HAVE_FORK)
CHECK_FUNCTION_EXISTS(isatty HAVE_ISATTY)

CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/include/plorth/cli/config.hpp.in
${CMAKE_CURRENT_SOURCE_DIR}/include/plorth/cli/config.hpp
)

ADD_EXECUTABLE(
plorth-cli
ext/linenoise/linenoise.c
Expand All @@ -23,6 +36,7 @@ TARGET_COMPILE_FEATURES(
TARGET_INCLUDE_DIRECTORIES(
plorth-cli
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/ext/linenoise
)

Expand Down
36 changes: 36 additions & 0 deletions cli/include/plorth/cli/config.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2017-2018, Rauli Laine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. 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 OWNER 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.
*/
#ifndef PLORTH_CLI_CONFIG_HPP_GUARD
#define PLORTH_CLI_CONFIG_HPP_GUARD

// Optional headers.
#cmakedefine HAVE_SYSEXITS_H 1

// Optional functions.
#cmakedefine HAVE_FORK 1
#cmakedefine HAVE_ISATTY 1

#endif /* !PLORTH_CLI_CONFIG_HPP_GUARD */
1 change: 1 addition & 0 deletions cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <plorth/plorth.hpp>
#include <plorth/cli/config.hpp>

#include <cstring>
#include <fstream>
Expand Down
12 changes: 5 additions & 7 deletions libplorth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ PROJECT(libplorth C CXX)
INCLUDE(CheckIncludeFile)
INCLUDE(CheckFunctionExists)

CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILE(sysexits.h HAVE_SYSEXITS_H)
CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)

CHECK_FUNCTION_EXISTS(fork HAVE_FORK)
CHECK_FUNCTION_EXISTS(isatty HAVE_ISATTY)
CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
CHECK_FUNCTION_EXISTS(realpath HAVE_REALPATH)

IF(PLORTH_ENABLE_MODULES)
IF(NOT ${HAVE_STAT})
MESSAGE(FATAL_ERROR "Required function stat() is missing.")
ELSEIF(NOT ${HAVE_REALPATH})
ENDIF()
IF(NOT ${HAVE_REALPATH})
MESSAGE(FATAL_ERROR "Required function realpath() is missing.")
ENDIF()
ENDIF()
Expand Down Expand Up @@ -65,8 +63,8 @@ OPTION(
)

CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/include/plorth/config.hpp.in"
"${CMAKE_CURRENT_SOURCE_DIR}/include/plorth/config.hpp"
${CMAKE_CURRENT_SOURCE_DIR}/include/plorth/config.hpp.in
${CMAKE_CURRENT_SOURCE_DIR}/include/plorth/config.hpp
)

ADD_LIBRARY(
Expand Down
6 changes: 2 additions & 4 deletions libplorth/include/plorth/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#ifndef PLORTH_CONFIG_HPP_GUARD
#define PLORTH_CONFIG_HPP_GUARD

#define PLORTH_VERSION U"1.0.0-alpha.8"
#include <plorth/version.hpp>

#define PLORTH_RUNTIME_LIBRARY_PATH U"${CMAKE_INSTALL_PREFIX}/lib/plorth"

// Optional features.
Expand All @@ -40,13 +41,10 @@

// Optional headers.
#cmakedefine HAVE_UNISTD_H 1
#cmakedefine HAVE_SYSEXITS_H 1
#cmakedefine HAVE_SYS_TYPES_H 1
#cmakedefine HAVE_SYS_STAT_H 1

// Optional functions.
#cmakedefine HAVE_FORK 1
#cmakedefine HAVE_ISATTY 1
#cmakedefine HAVE_STAT 1
#cmakedefine HAVE_REALPATH 1

Expand Down
31 changes: 31 additions & 0 deletions libplorth/include/plorth/version.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2017-2018, Rauli Laine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. 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 OWNER 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.
*/
#ifndef PLORTH_VERSION_HPP_GUARD
#define PLORTH_VERSION_HPP_GUARD

#define PLORTH_VERSION U"1.0.0-alpha.8"

#endif /* !PLORTH_VERSION_HPP_GUARD */
44 changes: 26 additions & 18 deletions webassembly/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,41 @@ SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${EMSCRIPTEN_CXX_FLAGS}"

ADD_EXECUTABLE(
plorth-webassembly
../plorth/src/repl.cpp
../libplorth/src/compiler.cpp
../libplorth/src/context.cpp
../libplorth/src/dictionary.cpp
../libplorth/src/exec.cpp
../libplorth/src/eval.cpp
../libplorth/src/globals.cpp
../libplorth/src/io-input.cpp
../libplorth/src/io-output.cpp
../libplorth/src/memory.cpp
../libplorth/src/module.cpp
../libplorth/src/position.cpp
../libplorth/src/runtime.cpp
../libplorth/src/unicode.cpp
../libplorth/src/utils.cpp
../libplorth/src/value.cpp
../libplorth/src/value-array.cpp
../libplorth/src/value-boolean.cpp
../libplorth/src/value-error.cpp
../libplorth/src/value-number.cpp
../libplorth/src/value-object.cpp
../libplorth/src/value-quote.cpp
../libplorth/src/value-string.cpp
../libplorth/src/value-symbol.cpp
../libplorth/src/value-word.cpp
../cli/src/repl.cpp
src/main.cpp
)

TARGET_COMPILE_OPTIONS(
plorth-webassembly
PRIVATE
-Wall -Werror
)

TARGET_COMPILE_FEATURES(
plorth-webassembly
PRIVATE
cxx_std_11
)

TARGET_INCLUDE_DIRECTORIES(
plorth-webassembly
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../libplorth/include
)

TARGET_LINK_LIBRARIES(
plorth-webassembly
plorth
)

SET_TARGET_PROPERTIES(
plorth-webassembly
PROPERTIES OUTPUT_NAME plorth
Expand Down
34 changes: 34 additions & 0 deletions webassembly/include/plorth/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2017-2018, Rauli Laine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. 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 OWNER 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.
*/
#ifndef PLORTH_CONFIG_HPP_GUARD
#define PLORTH_CONFIG_HPP_GUARD

#include <plorth/version.hpp>

// Optional features.
#define PLORTH_ENABLE_32BIT_INT 1

#endif /* !PLORTH_CONFIG_HPP_GUARD */

0 comments on commit 8359086

Please sign in to comment.