-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
420 lines (360 loc) · 13.2 KB
/
CMakeLists.txt
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
cmake_minimum_required (VERSION 2.8.7)
if (USE_STDLIBCPP)
set(MZN_LIBCPP libstdc++)
else()
set(MZN_LIBCPP libc++)
endif()
if(APPLE)
SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.7")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "${MZN_LIBCPP}")
endif(APPLE)
project (minisearch CXX C)
# The version number.
set (libminizinc_VERSION_MAJOR 0)
set (libminizinc_VERSION_MINOR 1)
set (libminizinc_VERSION_PATCH 0b1)
if (ADDITIONAL_DATE_STRING)
set (libminizinc_VERSION_PATCH "${libminizinc_VERSION_PATCH}.${ADDITIONAL_DATE_STRING}")
endif()
include(CheckCXXCompilerFlag)
SET(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
check_cxx_compiler_flag(-Werror HAS_WERROR)
if (HAS_WERROR)
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror")
endif()
check_cxx_compiler_flag(-std=c++11 HAS_STDCPP11)
if (HAS_STDCPP11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
check_cxx_compiler_flag(-std=c++0x HAS_STDCPP0X)
if (HAS_STDCPP0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()
endif()
check_cxx_compiler_flag(-stdlib=${MZN_LIBCPP} HAS_STDLIBLIBCPP)
if (HAS_STDLIBLIBCPP)
set(SAFE_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=${MZN_LIBCPP}")
check_cxx_source_compiles("int main(void) {return 0;}" LINKS_STDLIBLIBCPP)
if (NOT LINKS_STDLIBLIBCPP)
set(CMAKE_CXX_FLAGS "${SAFE_CMAKE_CXX_FLAGS}")
endif()
endif()
check_cxx_source_compiles("#include <unordered_set>
int main(void) { std::unordered_set<int> x; return 0; }" HAS_CPP11)
if (NOT HAS_CPP11)
check_cxx_source_compiles("#include <tr1/unordered_set>
int main(void) { std::tr1::unordered_set<int> x; return 0; }" HAS_CPP11_TR1)
if (HAS_CPP11_TR1)
set(MZN_NEED_TR1 1)
else()
message(FATAL_ERROR "A c++11 compatible C++ standard library is required to build libminizinc.")
endif()
endif()
CHECK_CXX_SOURCE_COMPILES("int main(void) { static __thread int x; (void)x; return 0;}" HAS_ATTR_THREAD)
if (NOT HAS_ATTR_THREAD)
CHECK_CXX_SOURCE_COMPILES("int main(void) { __declspec(thread) static int x; (void)x; return 0;}" HAS_DECLSPEC_THREAD)
endif()
CHECK_CXX_SOURCE_COMPILES("#include <cstdlib>
int main(void) { long long int x = atoll(\"123\"); (void)x; }" HAS_ATOLL)
CHECK_CXX_SOURCE_COMPILES("
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libproc.h>
#include <unistd.h>
int main (int argc, char* argv[])
{
pid_t pid = getpid();
char path[PROC_PIDPATHINFO_MAXSIZE];
(void) proc_pidpath (pid, path, sizeof(path));
return 0;
}
" HAS_PIDPATH)
CHECK_CXX_SOURCE_COMPILES("
#include <windows.h>
int main (int argc, char* argv[]) {
char path[MAX_PATH];
(void) GetModuleFileName(NULL, path, MAX_PATH);
return 0;
}" HAS_GETMODULEFILENAME)
CHECK_CXX_SOURCE_COMPILES("
#include <windows.h>
int main (int argc, char* argv[]) {
(void) GetFileAttributes(NULL);
return 0;
}" HAS_GETFILEATTRIBUTES)
CHECK_CXX_SOURCE_COMPILES("
#include <string.h>
int main (int argc, char* argv[]) {
(void) memcpy_s(NULL,0,NULL,0);
return 0;
}" HAS_MEMCPY_S)
SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/minizinc)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/doc/html)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/doc/pdf)
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
${PROJECT_SOURCE_DIR}/include/minizinc/config.hh.in
${PROJECT_BINARY_DIR}/minizinc/config.hh
)
configure_file (
${PROJECT_SOURCE_DIR}/doc/spec/version.tex.in
${PROJECT_BINARY_DIR}/doc/pdf/version.tex
)
include_directories(${PROJECT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
add_custom_target(MZNParser echo "Creating parser")
# When updating the cached files, update MD5 sums defined in this file
include(${PROJECT_SOURCE_DIR}/lib/cached/md5_cached.cmake)
macro(MD5 filename md5sum)
file(READ "${filename}" RAW_MD5_FILE)
string(REGEX REPLACE "\r" "" STRIPPED_MD5_FILE "${RAW_MD5_FILE}")
string(MD5 ${md5sum} "${STRIPPED_MD5_FILE}")
endmacro(MD5)
find_program(FLEX_EXEC flex)
if(FLEX_EXEC)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/lexer.yy.cpp
DEPENDS ${PROJECT_SOURCE_DIR}/lib/lexer.lxx
COMMAND ${FLEX_EXEC} -L -o${PROJECT_BINARY_DIR}/lexer.yy.cpp ${PROJECT_SOURCE_DIR}/lib/lexer.lxx
)
set_source_files_properties(${PROJECT_BINARY_DIR}/lexer.yy.cpp GENERATED)
set(lexer_cpp ${PROJECT_BINARY_DIR}/lexer.yy.cpp)
else(FLEX_EXEC)
MD5(${PROJECT_SOURCE_DIR}/lib/lexer.lxx lexer_lxx_md5)
if(NOT "${lexer_lxx_md5}" STREQUAL "${lexer_lxx_md5_cached}")
message(FATAL_ERROR "The file lexer.lxx has been modified but flex cannot be run.")
endif()
set(lexer_cpp ${PROJECT_SOURCE_DIR}/lib/cached/lexer.yy.cpp)
endif(FLEX_EXEC)
find_program(BISON_EXEC bison)
if(BISON_EXEC)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/parser.tab.cpp ${PROJECT_BINARY_DIR}/minizinc/parser.tab.hh
DEPENDS ${lexer_cpp} ${PROJECT_SOURCE_DIR}/lib/parser.yxx
COMMAND "${BISON_EXEC}" -l -o ${PROJECT_BINARY_DIR}/parser.tab.cpp --defines=${PROJECT_BINARY_DIR}/minizinc/parser.tab.hh ${PROJECT_SOURCE_DIR}/lib/parser.yxx
)
set_source_files_properties(${PROJECT_BINARY_DIR}/parser.tab.cpp GENERATED)
set(parser_cpp ${PROJECT_BINARY_DIR}/parser.tab.cpp)
set(parser_hh ${PROJECT_BINARY_DIR}/minizinc/parser.tab.hh)
else(BISON_EXEC)
MD5(${PROJECT_SOURCE_DIR}/lib/parser.yxx parser_yxx_md5)
if(NOT "${parser_yxx_md5}" STREQUAL "${parser_yxx_md5_cached}")
message(FATAL_ERROR "The file parser.yxx has been modified but bison cannot be run.")
endif()
include_directories(${PROJECT_SOURCE_DIR}/lib/cached)
set(parser_cpp ${PROJECT_SOURCE_DIR}/lib/cached/parser.tab.cpp)
set(parser_hh ${PROJECT_SOURCE_DIR}/lib/cached/minizinc/parser.tab.hh)
endif(BISON_EXEC)
add_library(minizinc
lib/ast.cpp
lib/astexception.cpp
lib/aststring.cpp
lib/astvec.cpp
lib/builtins.cpp
lib/cli.cpp
lib/copy.cpp
lib/eval_par.cpp
lib/file_utils.cpp
lib/gc.cpp
lib/htmlprinter.cpp
${lexer_cpp}
lib/model.cpp
${parser_cpp}
lib/prettyprinter.cpp
lib/search.cpp
lib/solver.cpp
lib/solver_instance.cpp
lib/solver_instance_base.cpp
lib/typecheck.cpp
lib/flatten.cpp
lib/optimize.cpp
lib/options.cpp
lib/optimize_constraints.cpp
lib/parser.yxx
lib/statistics.cpp
lib/lexer.lxx
lib/values.cpp
include/minizinc/ast.hh
include/minizinc/ast.hpp
include/minizinc/astexception.hh
include/minizinc/astiterator.hh
include/minizinc/aststring.hh
include/minizinc/astvec.hh
include/minizinc/builtins.hh
include/minizinc/cli.hh
include/minizinc/config.hh.in
include/minizinc/copy.hh
include/minizinc/eval_par.hh
include/minizinc/exception.hh
include/minizinc/file_utils.hh
include/minizinc/flatten.hh
include/minizinc/flatten_internal.hh
include/minizinc/gc.hh
include/minizinc/hash.hh
include/minizinc/htmlprinter.hh
include/minizinc/iter.hh
include/minizinc/model.hh
include/minizinc/optimize.hh
include/minizinc/optimize_constraints.hh
include/minizinc/options.hh
include/minizinc/parser.hh
include/minizinc/prettyprinter.hh
include/minizinc/search.hh
include/minizinc/solver.hh
include/minizinc/solver_instance.hh
include/minizinc/solver_instance_base.hh
include/minizinc/statistics.hh
include/minizinc/stl_map_set.hh
include/minizinc/timer.hh
include/minizinc/type.hh
include/minizinc/typecheck.hh
include/minizinc/values.hh
include/minizinc/stl_map_set.hh
include/minizinc/thirdparty/SafeInt3.hpp
${parser_hh}
)
# add the executable
#add_executable(mzn2fzn mzn2fzn.cpp)
#target_link_libraries(mzn2fzn minizinc)
#add_executable(solns2out solns2out.cpp)
#target_link_libraries(solns2out minizinc)
find_package ( Threads REQUIRED )
option (HAS_GECODE "Build with Gecode" OFF)
option (HAS_FZN "Build with text-based FlatZinc interface" ON)
if(HAS_GECODE)
include_directories("${GECODE_HOME}/include")
link_directories("${GECODE_HOME}/lib")
if(EXISTS "$ENV{GECODE_HOME}")
include_directories("$ENV{GECODE_HOME}")
link_directories("$ENV{GECODE_HOME}")
endif()
add_library(minizinc_gecode
solvers/gecode/fzn_space.cpp
solvers/gecode/gecode_engine.cpp
solvers/gecode/gecode_solverinstance.cpp
solvers/gecode/gecode_constraints.cpp
solvers/gecode/aux_brancher.hh)
target_link_libraries(minizinc_gecode
minizinc gecodegist
gecodedriver gecodesearch gecodeminimodel
gecodefloat gecodeint gecodeset
gecodekernel gecodesupport)
add_executable(mzn-gecode
solvers/gecode/mzn-gecode.cpp
)
target_link_libraries(mzn-gecode minizinc_gecode minizinc
gecodegist gecodedriver gecodesearch gecodeminimodel
gecodefloat gecodeint gecodeset
gecodekernel gecodesupport ${CMAKE_THREAD_LIBS_INIT})
add_executable(mzn-gecode-lite
solvers/gecode/mzn-gecode-lite.cpp
)
target_link_libraries(mzn-gecode-lite minizinc_gecode minizinc
gecodegist gecodedriver gecodesearch gecodeminimodel
gecodefloat gecodeint gecodeset
gecodekernel gecodesupport ${CMAKE_THREAD_LIBS_INIT})
INSTALL(TARGETS minizinc_gecode mzn-gecode mzn-gecode-lite
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
INSTALL(DIRECTORY solvers/gecode
DESTINATION include/minizinc/solvers
)
endif()
#add_executable(mzn2doc mzn2doc.cpp)
#target_link_libraries(mzn2doc minizinc)
if(HAS_FZN)
add_library(minizinc_fzn
solvers/fzn/fzn_solverinstance.cpp
)
target_link_libraries(minizinc_fzn minizinc)
add_executable(minisearch solvers/fzn/mzn-fzn-lite.cpp)
target_link_libraries(minisearch minizinc_fzn minizinc)
INSTALL(TARGETS minisearch
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()
#INSTALL(TARGETS mzn2fzn solns2out mzn2doc minizinc
# RUNTIME DESTINATION bin
# LIBRARY DESTINATION lib
# ARCHIVE DESTINATION lib
#)
option (BUILD_HTML_DOCUMENTATION "Build HTML documentation for the MiniZinc library" OFF)
if (BUILD_HTML_DOCUMENTATION)
add_custom_target(doc ALL
DEPENDS "mzn2doc"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND mzn2doc --toplevel-groups 2
--include-stdlib
--html-header ${PROJECT_SOURCE_DIR}/doc/html/header.html
--html-footer ${PROJECT_SOURCE_DIR}/doc/html/footer.html
--output-base ${PROJECT_BINARY_DIR}/doc/html/doc share/minizinc/std/globals.mzn
)
FILE(COPY
${PROJECT_SOURCE_DIR}/doc/html/style.css
${PROJECT_SOURCE_DIR}/doc/html/header.html
${PROJECT_SOURCE_DIR}/doc/html/footer.html
${PROJECT_SOURCE_DIR}/doc/html/MiniZn_logo.jpg
DESTINATION ${PROJECT_BINARY_DIR}/doc/html/)
INSTALL(DIRECTORY ${PROJECT_BINARY_DIR}/doc/html DESTINATION doc)
endif()
option (BUILD_STATIC_EXECUTABLE "Build statically linked executables" OFF)
option(BUILD_32BIT "Build for 32bit architectures" OFF)
if(BUILD_32BIT)
set_target_properties(minisearch PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
#set_target_properties(mzn2doc mzn2fzn solns2out PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
set_target_properties(minizinc_fzn PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
set_target_properties(minizinc PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
set (CMAKE_C_FLAGS "-m32")
endif()
option (BUILD_PDF_DOCUMENTATION "Build PDF documentation for the MiniZinc language" OFF)
if (BUILD_PDF_DOCUMENTATION)
add_custom_target(doc_spec ALL
DEPENDS doc/spec/common-spec.tex doc/spec/minizinc-spec.tex
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/doc/spec
COMMAND latexmk -pdf -output-directory=${PROJECT_BINARY_DIR}/doc/pdf minizinc-spec
)
endif()
if (BUILD_STATIC_EXECUTABLE)
set(CMAKE_EXE_LINKER_FLAGS -static)
endif()
INSTALL(DIRECTORY share/minizinc DESTINATION share)
INSTALL(FILES LICENSE.txt README_bin.txt DESTINATION doc/..)
INSTALL(DIRECTORY ${PROJECT_SOURCE_DIR}/tests/minisearch/regression_tests/ DESTINATION examples FILES_MATCHING PATTERN "*.mzn")
INSTALL(DIRECTORY include/minizinc
DESTINATION include
PATTERN config.hh.in EXCLUDE
)
INSTALL(FILES ${PROJECT_BINARY_DIR}/minizinc/config.hh DESTINATION include/minizinc)
INSTALL(FILES README.txt INSTALL.txt LICENSE.txt DESTINATION doc/..)
INSTALL(DIRECTORY doc/pdf DESTINATION doc)
INSTALL(DIRECTORY share/examples DESTINATION share)
INSTALL(DIRECTORY lib/cached DESTINATION lib PATTERN md5_cached.cmake EXCLUDE)
INSTALL(FILES ${parser_hh} DESTINATION include/minizinc)
SET(CPACK_PACKAGE_VERSION_MAJOR ${libminizinc_VERSION_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${libminizinc_VERSION_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${libminizinc_VERSION_PATCH})
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
IF(WIN32 AND NOT UNIX)
SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} My Famous Project")
SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.minizinc.org")
SET(CPACK_NSIS_CONTACT "[email protected]")
SET(CPACK_NSIS_MODIFY_PATH ON)
SET(CPACK_GENERATOR "ZIP")
ELSE(WIN32 AND NOT UNIX)
SET(CPACK_SOURCE_STRIP_FILES "")
SET(CPACK_GENERATOR "TGZ")
ENDIF(WIN32 AND NOT UNIX)
set(CPACK_SOURCE_GENERATOR "TGZ;ZIP")
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_SOURCE_IGNORE_FILES
"${CMAKE_CURRENT_BINARY_DIR}/;/tests/;/.git/;/.gitignore;~$;${CPACK_SOURCE_IGNORE_FILES}")
include(CPack)