-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
213 lines (179 loc) · 6.85 KB
/
CMakeLists.txt
File metadata and controls
213 lines (179 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#####################################################################################################################
#
# CMake and System Settings
#
#####################################################################################################################
set(CMAKE_VERBOSE_MAKEFILE ON)
cmake_minimum_required(VERSION 3.24)
option(SAM_SKIP_TOOLS "Skips the lk sandbox" OFF)
if (APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "12" CACHE STRING "Minimum OS X deployment version")
endif ()
if (UNIX AND NOT CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
endif ()
#####################################################################################################################
#
# Project Sources
#
#####################################################################################################################
Project(lk)
set(LK_SRC
src/absyn.cpp
src/eval.cpp
src/parse.cpp
src/vm.cpp
src/codegen.cpp
src/invoke.cpp
src/env.cpp
src/lex.cpp
src/sqlite3.c
src/stdlib.cpp)
#####################################################################################################################
#
# Compile Options per Platform
#
#####################################################################################################################
set(CMAKE_CXX_STANDARD 20)
if (MSVC)
add_compile_options(/W3 /wd4996 /MP)
add_compile_definitions(WIN32 _CRT_SECURE_NO_DEPRECATE=1 _CRT_NON_CONFORMING_SWPRINTFS=1
_SCL_SECURE_NO_WARNINGS=1 __WXMSW__ _UNICODE NOPCH LK_USE_WXWIDGETS)
foreach (flag_var CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG)
set(${flag_var} "${${flag_var}} /D_DEBUG" CACHE STRING "compile flags" FORCE)
endforeach ()
else (MSVC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (APPLE)
add_compile_options( -fno-common)
add_definitions(-DWX_PRECOMP)
endif ()
add_compile_options(-Wall -O2 )
add_definitions(-DLK_USE_WXWIDGETS)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(_DEBUG)
else ()
add_compile_options(-O3)
endif ()
endif (MSVC)
#####################################################################################################################
#
# WxWidgets Package
#
#####################################################################################################################
if (UNIX)
if(EXISTS /usr/local/bin/wx-config-3)
set(wxWidgets_CONFIG_EXECUTABLE /usr/local/bin/wx-config-3)
find_package(wxWidgets QUIET REQUIRED xrc stc richtext ribbon propgrid aui gl html qa adv core xml net base)
else ()
set(wxWidgets_CONFIG_EXECUTABLE $ENV{WXMSW3}/bin/wx-config)
find_package(wxWidgets QUIET REQUIRED xrc stc richtext ribbon propgrid aui gl html qa adv core xml net base)
endif ()
else ()
# set(wxWidgets_ROOT_DIR $ENV{WXMSW3})
# find_package(wxWidgets REQUIRED xrc stc richtext ribbon propgrid aui gl html qa adv core xml net base scintilla)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Debug and Release Builds Configured" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20")
# for linking to Release build of ortools
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
# Get the current debug flags and remove the /D_DEBUG option.
string(REPLACE "/D_DEBUG" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
# following does not force release libraries for wxWidgets using find_package
#set(CMAKE_MAP_IMPORTED_CONFIG_DEBUG RELEASE)
set(wxWidgets_ROOT_DIR $ENV{WXMSW3})
find_package(wxWidgets QUIET REQUIRED xrc webview stc richtext ribbon propgrid aui gl html qa adv core xml net base scintilla)
# message("All wxWidgets: " ${wxWidgets_LIBRARIES})
set(FOUND "false")
foreach(lib ${wxWidgets_LIBRARIES})
string(FIND ${lib} "optimized" INDEX)
string(FIND ${lib} "debug" INDEX2)
string(FIND ${lib} "wxWidgets" INDEX3)
if (INDEX GREATER_EQUAL 0) # skip once
set(FOUND "true")
continue()
elseif((INDEX2 LESS 0) AND (INDEX3 LESS 0))
set(FOUND "true")
endif()
if (${FOUND} STREQUAL "true")
set(FOUND "false")
message("lib: ${lib}")
list(APPEND WX_LIBS_LIST ${lib})
endif()
endforeach()
list(JOIN WX_LIBS_LIST ";" wxWidgets_LIBRARIES)
# message("Link Libraries for wxWidgets: ${wxWidgets_LIBRARIES}")
endif ()
if (wxWidgets_FOUND)
include(${wxWidgets_USE_FILE})
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${wxWidgets_CXX_FLAGS}")
#####################################################################################################################
#
# CMake Targets
#
#####################################################################################################################
# lk library
add_library(lk STATIC ${LK_SRC})
set_target_properties(lk
PROPERTIES
DEBUG_POSTFIX "d"
PREFIX ""
)
if (MSVC)
set_target_properties(lk
PROPERTIES
LINK_FLAGS /SUBSYSTEM:CONSOLE)
endif ()
target_include_directories(lk PRIVATE include)
# sandbox executable
if (NOT SAM_SKIP_TOOLS)
add_executable(lk_sandbox ${LK_SRC} sandbox/sandbox.cpp)
set_target_properties(lk_sandbox
PROPERTIES
DEBUG_POSTFIX "d"
)
if (MSVC)
set_target_properties(lk_sandbox
PROPERTIES
LINK_FLAGS /SUBSYSTEM:WINDOWS)
endif ()
target_include_directories(lk_sandbox PUBLIC include)
endif()
#####################################################################################################################
#
# Link Libraries and Options
#
#####################################################################################################################
# lk library
if (${CMAKE_PROJECT_NAME} STREQUAL export_config)
target_compile_definitions(lk PUBLIC _export_config_)
endif ()
# sandbox executable
if (NOT SAM_SKIP_TOOLS)
if (UNIX)
target_link_libraries(lk_sandbox -ldl)
endif ()
# target_link_libraries(lk_sandbox ${wxWidgets_LIBRARIES})
# message("All wxWidgets: " ${wxWidgets_LIBRARIES})
set(FOUND "false")
foreach(lib ${wxWidgets_LIBRARIES})
string(FIND ${lib} "optimized" INDEX)
string(FIND ${lib} "debug" INDEX2)
string(FIND ${lib} "wxWidgets" INDEX3)
if (INDEX GREATER_EQUAL 0) # skip once
set(FOUND "true")
continue()
elseif((INDEX2 LESS 0) AND (INDEX3 LESS 0))
set(FOUND "true")
endif()
if (${FOUND} STREQUAL "true")
set(FOUND "false")
# message("lib: ${lib}")
list(APPEND WX_LIBS_LIST ${lib})
endif()
endforeach()
list(JOIN WX_LIBS_LIST ";" WX_LIBS)
# message("Link Libraries for lk_sandbox: ${WX_LIBS}")
target_link_libraries(lk_sandbox lk ${WX_LIBS})
endif()