Updated README with better build info
[debian/pforth] / CMakeLists.txt
1 # NAME/CMakeLists.txt
2 # Original file by Robin Rowe 2020-05-01
3 # Extended by Phil Burk 2021-10-31
4 # License: BSD Zero
5
6 # To build pforth:
7 #
8 #    cmake .
9 #    make
10 #
11 # That will create the following files:
12 #    fth/pforth   # executable that loads pforth.dic
13 #    fth/pforth.dic
14 #    fth/pforth_standalone # executable that does not need a .dic file
15 #
16 # The build has several steps
17 # 1. Build pforth executable
18 # 2. Build pforth.dic by compiling system.fth
19 # 3. Create a pfdicdat.h header containing a precompiled dictionary
20 #    as C source code.
21 # 4.  Build pforth_standalone using the precompiled dictionary.
22
23 cmake_minimum_required(VERSION 3.6)
24 set(CMAKE_CXX_STANDARD 17)
25 set(CMAKE_CXX_STANDARD_REQUIRED ON)
26 set(CMAKE_CXX_EXTENSIONS OFF)
27
28 # Put pforth in the fth folder so we can load the Forth code more easily.
29 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/fth)
30
31 project(PForth)
32 message("Configuring ${PROJECT_NAME}...")
33 enable_testing()
34
35 if(WIN32)
36     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
37     message("Warning: _CRT_SECURE_NO_WARNINGS")
38 endif(WIN32)
39
40 add_subdirectory(csrc)
41 if(NOT WIN32 AND NOT APPLE)
42         link_libraries(rt pthread)
43 endif(NOT WIN32 AND NOT APPLE)
44
45 option(UNISTD "Enable libunistd" false)
46 if(UNISTD)
47         set(LIBUNISTD_PATH /code/github/libunistd)
48         if(WIN32)
49                 include_directories(${LIBUNISTD_PATH}/unistd)
50                 link_directories(${LIBUNISTD_PATH}/build/unistd/Release)
51                 link_libraries(libunistd)
52         endif(WIN32)
53 endif(UNISTD)
54
55 # 1. Build pforth executable
56 add_executable(pforth csrc/pf_main.c)
57 target_link_libraries(pforth ${PROJECT_NAME}_lib m)
58
59 # 2. Build pforth.dic by compiling system.fth
60 set(PFORTH_DIC "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/pforth.dic")
61 add_custom_command(OUTPUT ${PFORTH_DIC}
62   COMMAND ./pforth -i system.fth
63   WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
64   DEPENDS pforth
65   COMMENT Building pforth.dic
66   VERBATIM
67   )
68 add_custom_target(pforth_dic DEPENDS ${PFORTH_DIC})
69
70 # 3. Create a pfdicdat.h header containing a precompiled dictionary
71 #    as C source code.
72 set(PFORTH_DIC_HEADER "csrc/pfdicdat.h")
73 add_custom_command(OUTPUT ${PFORTH_DIC_HEADER}
74   COMMAND ./pforth mkdicdat.fth
75   COMMAND mv pfdicdat.h ../csrc/.
76   WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
77   DEPENDS pforth_dic
78   COMMENT Building pfdicdat.h
79   VERBATIM
80   )
81 add_custom_target(pforth_dic_header DEPENDS ${PFORTH_DIC_HEADER})
82 add_dependencies(${PROJECT_NAME}_lib_sd pforth_dic_header)
83
84 # 4. Build pforth_standalone using the precompiled dictionary.
85 add_executable(pforth_standalone csrc/pf_main.c)
86 target_link_libraries(pforth_standalone ${PROJECT_NAME}_lib_sd m)
87 target_compile_definitions(pforth_standalone PRIVATE PF_STATIC_DIC)
88 add_dependencies(pforth_standalone pforth_dic_header)
89
90
91