cmake: add cmake support (#92)
authorPhil Burk <philburk@mobileer.com>
Sun, 31 Oct 2021 23:13:08 +0000 (16:13 -0700)
committerGitHub <noreply@github.com>
Sun, 31 Oct 2021 23:13:08 +0000 (16:13 -0700)
Support builds on Linux and MacOS.
Needs testing on Windows.
See CMakeLists.txt for instructions.

Builds:
* fth/pforth
* fth/pforth.dic
* fth/pforth_standalone

Based on a contribution from Robin Rowe.

    cmake .
    make

.gitignore
CMakeLists.txt [new file with mode: 0644]
csrc/CMakeLists.txt [new file with mode: 0644]
csrc/sources.cmake [new file with mode: 0644]
fth/mkdicdat.fth [new file with mode: 0644]

index 0ea33dcd8a75e5f55a2f57402de736037913b766..a9d811a32c0d796a6d1a5bc751bcc99e19214b44 100644 (file)
@@ -1,13 +1,29 @@
-platforms/unix/*.eo
-platforms/unix/*.o
-platforms/unix/pfdicdat.h
-platforms/unix/pforth
-platforms/unix/pforth.dic
-platforms/unix/pforth_standalone
-platforms/win32/**/.vs
-platforms/win32/**/Debug
-platforms/win32/**/Release
+platform/unix/*.eo
+platform/unix/*.o
+platform/unix/pfdicdat.h
+platform/unix/pforth
+platform/unix/pforth.dic
+platform/unix/pforth_standalone
+platform/win32/**/.vs
+platform/win32/**/Debug
+platform/win32/**/Release
 fth/fatest1.txt
 fth/pforth.dic
 **/.DS_Store
+build/
+
+CMakeCache.txt
+CMakeFiles/
+CTestTestfile.cmake
+Makefile
+cmake_install.cmake
+csrc/CMakeFiles/
+csrc/CTestTestfile.cmake
+csrc/Makefile
+csrc/cmake_install.cmake
+csrc/libPforth_lib.a
+csrc/libPforth_lib_sd.a
+csrc/pfdicdat.h
+pforth
+pforth_standalone
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1723ee2
--- /dev/null
@@ -0,0 +1,91 @@
+# NAME/CMakeLists.txt
+# Original file by Robin Rowe 2020-05-01
+# Extended by Phil Burk 2021-10-31
+# License: BSD Zero
+
+# To build pforth:
+#
+#    cmake .
+#    make
+#
+# That will create the following files:
+#    fth/pforth   # executable that loads pforth.dic
+#    fth/pforth.dic
+#    fth/pforth_standalone # executable that does not need a .dic file
+#
+# The build has several steps
+# 1. Build pforth executable
+# 2. Build pforth.dic by compiling system.fth
+# 3. Create a pfdicdat.h header containing a precompiled dictionary
+#    as C source code.
+# 4.  Build pforth_standalone using the precompiled dictionary.
+
+cmake_minimum_required(VERSION 3.6)
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+# Put pforth in the fth folder so we can load the Forth code more easily.
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/fth)
+
+project(PForth)
+message("Configuring ${PROJECT_NAME}...")
+enable_testing()
+
+if(WIN32)
+    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+    message("Warning: _CRT_SECURE_NO_WARNINGS")
+endif(WIN32)
+
+add_subdirectory(csrc)
+if(NOT WIN32 AND NOT APPLE)
+       link_libraries(rt pthread)
+endif(NOT WIN32 AND NOT APPLE)
+
+option(UNISTD "Enable libunistd" false)
+if(UNISTD)
+       set(LIBUNISTD_PATH /code/github/libunistd)
+       if(WIN32)
+               include_directories(${LIBUNISTD_PATH}/unistd)
+               link_directories(${LIBUNISTD_PATH}/build/unistd/Release)
+               link_libraries(libunistd)
+       endif(WIN32)
+endif(UNISTD)
+
+# 1. Build pforth executable
+add_executable(pforth csrc/pf_main.c)
+target_link_libraries(pforth ${PROJECT_NAME}_lib)
+
+# 2. Build pforth.dic by compiling system.fth
+set(PFORTH_DIC "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pforth.dic")
+add_custom_command(OUTPUT ${PFORTH_DIC}
+  COMMAND ./pforth -i system.fth
+  WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+  DEPENDS pforth
+  COMMENT Building pforth.dic
+  VERBATIM
+  )
+add_custom_target(pforth_dic DEPENDS ${PFORTH_DIC})
+
+# 3. Create a pfdicdat.h header containing a precompiled dictionary
+#    as C source code.
+set(PFORTH_DIC_HEADER "csrc/pfdicdat.h")
+add_custom_command(OUTPUT ${PFORTH_DIC_HEADER}
+  COMMAND ./pforth mkdicdat.fth
+  COMMAND mv pfdicdat.h ../csrc/.
+  WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+  DEPENDS pforth_dic
+  COMMENT Building pfdicdat.h
+  VERBATIM
+  )
+add_custom_target(pforth_dic_header DEPENDS ${PFORTH_DIC_HEADER})
+add_dependencies(${PROJECT_NAME}_lib_sd pforth_dic_header)
+
+# 4. Build pforth_standalone using the precompiled dictionary.
+add_executable(pforth_standalone csrc/pf_main.c)
+target_link_libraries(pforth_standalone ${PROJECT_NAME}_lib_sd)
+target_compile_definitions(pforth_standalone PRIVATE PF_STATIC_DIC)
+add_dependencies(pforth_standalone pforth_dic_header)
+
+
+
diff --git a/csrc/CMakeLists.txt b/csrc/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6cacd16
--- /dev/null
@@ -0,0 +1,40 @@
+# pforth/csrc/CMakeLists.txt
+# Extended by Phil Burk 2021-10-31
+# License: BSD Zero
+
+file(STRINGS sources.cmake SOURCES)
+
+if(WIN32)
+set(PLATFORM stdio/pf_fileio_stdio.c win32_console/pf_io_win32_console.c )
+endif(WIN32)
+
+if(UNIX OR APPLE)
+set(PLATFORM posix/pf_io_posix.c stdio/pf_fileio_stdio.c)
+endif(UNIX OR APPLE)
+
+if (MSVC)
+    # warning level 4 and all warnings as errors
+    add_compile_options(/W4 /WX)
+else()
+    # lots of warnings and all warnings as errors
+    add_compile_options(
+#        --std=c89
+        -fsigned-char
+        -fno-builtin
+        -fno-unroll-loops
+        -pedantic
+        -Wcast-qual
+        -Wall
+        -Werror
+        -Wwrite-strings
+        -Winline
+        -Wmissing-prototypes
+        -Wmissing-declarations
+        )
+endif()
+
+add_library(${PROJECT_NAME}_lib ${SOURCES} ${PLATFORM})
+
+# Compile the same library but with an option for the static dictionary.
+add_library(${PROJECT_NAME}_lib_sd STATIC ${SOURCES} ${PLATFORM})
+target_compile_definitions(${PROJECT_NAME}_lib_sd PRIVATE PF_STATIC_DIC)
diff --git a/csrc/sources.cmake b/csrc/sources.cmake
new file mode 100644 (file)
index 0000000..500c329
--- /dev/null
@@ -0,0 +1,34 @@
+sources.cmake
+pf_all.h
+pf_cglue.h
+pf_clib.h
+pf_core.h
+pf_float.h
+pf_guts.h
+pf_host.h
+pf_inc1.h
+pf_io.h
+pf_mem.h
+pf_save.h
+pf_text.h
+pf_types.h
+pf_win32.h
+pf_words.h
+pfcompfp.h
+pfcompil.h
+pfdicdat_arm.h
+pfinnrfp.h
+pforth.h
+pf_cglue.c
+pf_clib.c
+pf_core.c
+pf_inner.c
+pf_io.c
+pf_io_none.c
+pf_mem.c
+pf_save.c
+pf_text.c
+pf_words.c
+pfcompil.c
+pfcustom.c
+
diff --git a/fth/mkdicdat.fth b/fth/mkdicdat.fth
new file mode 100644 (file)
index 0000000..f739fab
--- /dev/null
@@ -0,0 +1,5 @@
+\ Generate the pfdicdat.h header file.
+include savedicd.fth
+." Generate a static embedded dictionary" cr
+sdad
+." pfdicdat.h created" cr