forked from numenta/nupic-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
524 lines (457 loc) · 22.9 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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# --------------------------------------------------------------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2014, Numenta, Inc. Unless you have purchased from
# Numenta, Inc. a separate commercial license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
#
# Contributor(s):
# David Ragazzi (@DavidRagazzi): Full conversion and adaptation from Autotools scripts
# Austin Marshall (amarshall@numenta.com): On-going maintenance
# Matthew Taylor (matt@numenta.org): Updates for nupic.core integration
# --------------------------------------------------------------------------------------------------------------------------
# Command Line Options
# ====================
# -DNUPIC_CORE : (optional) Absolute path to nupic.core binary release directory
cmake_minimum_required(VERSION 2.8)
project(nupic CXX)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# This function reads variables from a file in the following format:
# FOO = 'bar'
function (read_variable_from_file file_content variable value)
set(${value} PARENT_SCOPE)
foreach(line ${file_content})
string(REGEX MATCH "^${variable}" match "${line}")
if(NOT "${match}" STREQUAL "")
string(REGEX REPLACE "${variable} = '([^']+)'.*" "\\1" tag_value "${line}")
set(${value} "${tag_value}" PARENT_SCOPE)
endif()
endforeach()
endfunction()
function (unpack_nupic_core source_path package_file)
string(REGEX REPLACE "\\.tar\\.gz" "" UNPACK_DIR "${package_file}")
message(STATUS "Unpacking ${package_file} into ${UNPACK_DIR}...")
set(RELEASE_DIR "${source_path}/build/release")
file(REMOVE_RECURSE "${source_path}/build/release/bin")
file(REMOVE_RECURSE "${source_path}/build/release/include")
file(REMOVE_RECURSE "${source_path}/build/release/lib")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf "${package_file}"
WORKING_DIRECTORY "${source_path}/build/release"
)
file(RENAME "${UNPACK_DIR}/bin" "${RELEASE_DIR}/bin")
file(RENAME "${UNPACK_DIR}/include" "${RELEASE_DIR}/include")
file(RENAME "${UNPACK_DIR}/lib" "${RELEASE_DIR}/lib")
file(REMOVE_RECURSE "${UNPACK_DIR}")
endfunction()
#
# Identify platform
#
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(PLATFORM "darwin")
set(STDLIB "-stdlib=libc++")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.7")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(PLATFORM "linux")
set(STDLIB "")
endif()
set(BITNESS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITNESS 64)
endif()
#
# Checks if Python is installed and gets its variables.
# Minimum version of Python is 2.6 -- earlier versions *will* fail.
#
# Please don't use 'find_package' for finding Python (System version), it has presented several conflicting results.
# Instead we just use a shell command to execute a simple python command, if exit code is 0 ('success') then we have python installed.
#
#
# Check for user-defined PYTHON env variable
#
if(NOT "$ENV{PYTHON}" STREQUAL "")
set(PYTHON "$ENV{PYTHON}")
else()
set(PYTHON "python")
endif()
execute_process(COMMAND ${PYTHON} --version
RESULT_VARIABLE EXIT_CODE)
if(NOT EXIT_CODE EQUAL 0)
message(FATAL_ERROR "System Python not found. You do not have a system version of Python or it is not set on environment path.")
endif()
#
# Gives the version of Python necessary to get installation directories
# for use with ${PYTHON_VERSION}, etc.
#
execute_process(COMMAND ${PYTHON} -c "import sys;sys.stdout.write(str(sys.version_info[0]) + '.' + str(sys.version_info[1]))"
OUTPUT_VARIABLE PYTHON_VERSION)
if(NOT(${PYTHON_VERSION} EQUAL "2.6" OR ${PYTHON_VERSION} EQUAL "2.7"))
message(FATAL_ERROR "Only these versions of Python are accepted: 2.6, 2.7")
endif()
set(NUPIC_CORE_EXTRA_CXXFLAGS, "-DNTA_PYTHON_SUPPORT=${PYTHON_VERSION} ${NUPIC_CORE_EXTRA_CXXFLAGS}")
#
# Find out where system installation of python is.
#
execute_process(COMMAND ${PYTHON} -c "import sys;sys.stdout.write(sys.prefix)"
OUTPUT_VARIABLE PYTHON_PREFIX)
string(REGEX REPLACE "\\\\" "/" PYTHON_PREFIX ${PYTHON_PREFIX})
set(PYTHON_INCLUDE_DIR "${PYTHON_PREFIX}/include/python${PYTHON_VERSION}")
set(PYTHON_LIBRARY_DIR "${PYTHON_PREFIX}/lib/python${PYTHON_VERSION}")
#
# Finds out version of Numpy and headers's path.
#
execute_process(COMMAND ${PYTHON} -c "import sys;import numpy;sys.stdout.write(numpy.get_include())"
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR)
string(REGEX REPLACE "\\\\" "/" NUMPY_INCLUDE_DIR ${NUMPY_INCLUDE_DIR})
execute_process(COMMAND ${PYTHON} -c "import sys;import numpy;sys.stdout.write(numpy.__version__)"
OUTPUT_VARIABLE NUMPY_VERSION)
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
if("${NUPIC_CORE}" STREQUAL "")
# User did not specify NUPIC_CORE binary location, assume relative to nupic
set(NUPIC_CORE "${PROJECT_SOURCE_DIR}/extensions/core/build/release")
set(NUPIC_CORE_SOURCE "${PROJECT_SOURCE_DIR}/extensions/core")
set(FETCH_NUPIC_CORE TRUE)
else()
# User specified that they have their own nupic.core
set(FETCH_NUPIC_CORE FALSE)
endif()
set(CMAKE_PREFIX_PATH ${NUPIC_CORE})
set(CMAKE_INCLUDE_PATH "${NUPIC_CORE}/include")
add_definitions(-DNTA_PLATFORM_${PLATFORM}${BITNESS}
-DHAVE_CONFIG_H
-DNTA_INTERNAL
-DBOOST_NO_WREGEX
-DNUPIC2
-DNTA_ASSERTIONS_ON
-DNTA_ASM
-DNTA_PYTHON_SUPPORT=${PYTHON_VERSION})
include_directories(SYSTEM
"${PROJECT_SOURCE_DIR}/external/${PLATFORM}${BITNESS}/include"
"${PROJECT_SOURCE_DIR}/external/common/include"
"${PROJECT_SOURCE_DIR}/extensions"
"${PROJECT_SOURCE_DIR}"
"${PROJECT_BINARY_DIR}"
"${PYTHON_PREFIX}/lib"
"${PYTHON_INCLUDE_DIR}"
${CMAKE_INCLUDE_PATH}
${NUMPY_INCLUDE_DIR})
set(COMMON_COMPILE_FLAGS "-fPIC") # `position independent code`, required for shared libraries
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -std=c++11") # Adhere to c++11 spec
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} ${STDLIB}") # Adhere to c++11 spec
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -m${BITNESS}") # Generate 32 or 64 bit code
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fvisibility=hidden -Wall -Wreturn-type -Wunused -Wno-unused-parameter")
set(LIB_STATIC_SUPPORT py_support)
add_library(${LIB_STATIC_SUPPORT}
extensions/py_support/NumpyVector.cpp
extensions/py_support/PyArray.cpp
extensions/py_support/PyHelpers.cpp
extensions/py_support/PythonStream.cpp)
set_target_properties(${LIB_STATIC_SUPPORT} PROPERTIES COMPILE_FLAGS ${COMMON_COMPILE_FLAGS})
set_target_properties(${LIB_STATIC_SUPPORT} PROPERTIES LINK_FLAGS "-m${BITNESS} {STDLIB}")
set(NUPIC_CORE_BUCKET "https://s3-us-west-2.amazonaws.com/artifacts.numenta.org/numenta/nupic.core")
if(FETCH_NUPIC_CORE)
# User has not specified NUPIC_CORE location, so we'll download the binaries
# First, get the nupic.core SHA and remote location from local config.
if(EXISTS "${PROJECT_SOURCE_DIR}/.nupic_config")
file(STRINGS "${PROJECT_SOURCE_DIR}/.nupic_config" MODULES_FILE_CONTENT REGEX "^[^#]")
elseif(EXISTS "$ENV{HOME}/.nupic_config")
file(STRINGS "$ENV{HOME}/.nupic_config" MODULES_FILE_CONTENT REGEX "^[^#]")
else()
file(STRINGS "${PROJECT_SOURCE_DIR}/.nupic_modules" MODULES_FILE_CONTENT REGEX "^[^#]")
endif()
read_variable_from_file("${MODULES_FILE_CONTENT}" "NUPIC_CORE_REMOTE" NUPIC_CORE_REMOTE)
read_variable_from_file("${MODULES_FILE_CONTENT}" "NUPIC_CORE_COMMITISH" NUPIC_CORE_COMMITISH)
set(NUPIC_CORE_REMOTE_URL "${NUPIC_CORE_BUCKET}/nupic_core-${NUPIC_CORE_COMMITISH}-${PLATFORM}${BITNESS}.tar.gz")
set(NUPIC_CORE_LOCAL_PACKAGE "${NUPIC_CORE}/nupic_core-${NUPIC_CORE_COMMITISH}-${PLATFORM}${BITNESS}.tar.gz")
if(EXISTS "${NUPIC_CORE_LOCAL_PACKAGE}")
message(STATUS "Target nupic.core package already exists at ${NUPIC_CORE_LOCAL_PACKAGE}.")
unpack_nupic_core("${NUPIC_CORE_SOURCE}" "${NUPIC_CORE_LOCAL_PACKAGE}")
else()
message(STATUS "Attempting to fetch nupic.core binaries from ${NUPIC_CORE_REMOTE_URL} and save to ${NUPIC_CORE_LOCAL_PACKAGE}...")
file(DOWNLOAD "${NUPIC_CORE_REMOTE_URL}" "${NUPIC_CORE_LOCAL_PACKAGE}"
INACTIVITY_TIMEOUT 30
TIMEOUT 300
STATUS "NUPIC_CORE_DOWNLOAD_STATUS"
SHOW_PROGRESS)
# TODO: Give user a way to clean up all the downloaded binaries. It can be
# manually done with `rm -rf ${NUPIC_CORE}/extensions/core` but would be
# cleaner with something like `python setup.py clean`.
if(NOT NUPIC_CORE_DOWNLOAD_STATUS EQUAL 0)
message(WARNING "Error downloading nupic.core package: ${NUPIC_CORE_DOWNLOAD_STATUS}")
message(STATUS "Building nupic.core from local checkout ${NUPIC_CORE_SOURCE}...")
# Remove the local package file, which didn't get populated due to the
# download failure.
file(REMOVE "${NUPIC_CORE_LOCAL_PACKAGE}")
# Get nupic.core dependency through git.
if (NOT(EXISTS "${NUPIC_CORE_SOURCE}/.git"))
# There's not a git repo in NUPIC_CORE_SOURCE, so we can blow the whole
# directory away and clone nupic.core there.
file(REMOVE_RECURSE "${NUPIC_CORE_SOURCE}")
file(MAKE_DIRECTORY "${NUPIC_CORE_SOURCE}")
execute_process(COMMAND git clone ${NUPIC_CORE_REMOTE} ${NUPIC_CORE_SOURCE}
RESULT_VARIABLE EXIT_CODE)
if(NOT EXIT_CODE EQUAL 0)
message(FATAL_ERROR "Unable to clone ${NUPIC_CORE_REMOTE} into ${NUPIC_CORE_SOURCE}")
endif()
else()
# Fetch if already cloned.
execute_process(COMMAND git fetch ${NUPIC_CORE_REMOTE}
WORKING_DIRECTORY ${NUPIC_CORE_SOURCE}
RESULT_VARIABLE EXIT_CODE)
if(NOT EXIT_CODE EQUAL 0)
message(FATAL_ERROR "Unable to fetch ${NUPIC_CORE_REMOTE}")
endif()
endif()
# Get the exact SHA we need for nupic.core.
execute_process(COMMAND git reset --hard ${NUPIC_CORE_COMMITISH}
WORKING_DIRECTORY ${NUPIC_CORE_SOURCE}
RESULT_VARIABLE EXIT_CODE)
if(NOT EXIT_CODE EQUAL 0)
message(FATAL_ERROR "Unable to checkout ${NUPIC_CORE_COMMITISH} in ${NUPIC_CORE_SOURCE}")
endif()
# Execute the Make scripts
execute_process(COMMAND git clean -fdx
WORKING_DIRECTORY ${NUPIC_CORE_SOURCE}
RESULT_VARIABLE EXIT_CODE)
if(NOT EXIT_CODE EQUAL 0)
message(FATAL_ERROR "Compiling 'nupic.core' library within ${PROJECT_SOURCE_DIR} failed: ${BUILD_NUPIC_CORE_OUTP}")
endif()
# Build and set external libraries
message(STATUS "Building 'nupic.core' library...")
# Clean 'build/scripts' subfolder at submodule folder
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${NUPIC_CORE_SOURCE}/build/scripts)
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${NUPIC_CORE_SOURCE}/build/scripts)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${NUPIC_CORE_SOURCE}/build/scripts)
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${NUPIC_CORE})
# Generate the Make scripts
execute_process(COMMAND ${CMAKE_COMMAND} ${NUPIC_CORE_SOURCE}/src -DCMAKE_INSTALL_PREFIX=${NUPIC_CORE}
WORKING_DIRECTORY ${NUPIC_CORE_SOURCE}/build/scripts)
set(USER_MAKE_COMMAND "make" CACHE STRING "Default `make` command used to build nupic.core")
# Execute the Make scripts
execute_process(COMMAND ${USER_MAKE_COMMAND} install -j3
WORKING_DIRECTORY ${NUPIC_CORE_SOURCE}/build/scripts
RESULT_VARIABLE EXIT_CODE
OUTPUT_VARIABLE OUTP)
if(NOT EXIT_CODE EQUAL 0)
message(FATAL_ERROR "Compiling 'nupic.core' library within ${NUPIC_SOURCE_DIR} failed")
endif()
message(STATUS "Done.")
else()
message(STATUS "Download successful.")
unpack_nupic_core("${NUPIC_CORE_SOURCE}" "${NUPIC_CORE_LOCAL_PACKAGE}")
endif()
endif()
else()
message(STATUS "Using nupic.core binaries at ${NUPIC_CORE}")
endif()
find_library(LIB_STATIC_GTEST gtest)
set(LIB_STATIC_NUPICCORE nupic_core)
find_library(LIB_STATIC_NUPICCORE_LOC ${LIB_STATIC_NUPICCORE} "${NUPIC_CORE}/lib")
add_library(${LIB_STATIC_NUPICCORE_LOC} STATIC IMPORTED GLOBAL)
set(COMMON_LINK_FLAGS "${COMMON_LINK_FLAGS} -fPIC")
set(COMMON_LINK_FLAGS "${COMMON_LINK_FLAGS} -m${BITNESS}")
set(COMMON_LINK_FLAGS "${COMMON_LINK_FLAGS} -std=c++11")
set(COMMON_LINK_FLAGS "${COMMON_LINK_FLAGS} ${STDLIB}")
set(COMMON_LINK_FLAGS "${COMMON_LINK_FLAGS} -L${NUPIC_CORE}/lib")
set(COMMON_LINK_FLAGS "${COMMON_LINK_FLAGS} -lyaml-cpp")
set(COMMON_LINK_FLAGS "${COMMON_LINK_FLAGS} -L${PYTHON_PREFIX}/lib")
set(COMMON_LIBS ${LIB_STATIC_NUPICCORE})
if("${PLATFORM}" STREQUAL "linux")
list(APPEND COMMON_LIBS pthread dl)
elseif("${PLATFORM}" STREQUAL "darwin")
set(COMPILE_FLAGS "${COMPILE_FLAGS} -O3")
endif()
set(EXECUTABLE_HTMTEST testpyhtm)
set(LIBRARIES ${LIB_STATIC_SUPPORT})
add_executable(${EXECUTABLE_HTMTEST} extensions/htmtest/htmtest.cpp)
target_link_libraries(${EXECUTABLE_HTMTEST} ${COMMON_LIBS})
set_target_properties(${EXECUTABLE_HTMTEST}
PROPERTIES COMPILE_FLAGS ${COMMON_COMPILE_FLAGS}
LINK_FLAGS "${COMMON_LINK_FLAGS}")
add_custom_target(tests_htm
COMMAND ${EXECUTABLE_HTMTEST}
DEPENDS ${EXECUTABLE_HTMTEST})
set(LIB_DYNAMIC_CPPREGION cpp_region)
add_library(${LIB_DYNAMIC_CPPREGION}
SHARED
extensions/cpp_region/PyRegion.cpp
extensions/cpp_region/unittests/PyHelpersTest.cpp)
target_link_libraries(${LIB_DYNAMIC_CPPREGION}
dl
python${PYTHON_VERSION}
${LIB_STATIC_SUPPORT}
${LIB_STATIC_GTEST}
${COMMON_LIBS})
set_target_properties(${LIB_DYNAMIC_CPPREGION}
PROPERTIES COMPILE_FLAGS ${COMMON_COMPILE_FLAGS}
LINK_FLAGS ${COMMON_LINK_FLAGS})
#
# SWIG
#
set(SWIG_EXECUTABLE "${PROJECT_SOURCE_DIR}/external/${PLATFORM}${BITNESS}/bin/swig" CACHE STRING "Swig executable")
set(SWIG_DIR "${PROJECT_SOURCE_DIR}/external/common/share/swig/3.0.2" CACHE STRING "Swig dir")
set(PROJECT_BUILD_TEMP_DIR ${PROJECT_SOURCE_DIR}/temp)
# CMAKE_CURRENT_BINARY_DIR is used by swig module for put wrappers on, so don't erase this line!
set(CMAKE_CURRENT_BINARY_DIR ${PROJECT_BUILD_TEMP_DIR})
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -I${PROJECT_SOURCE_DIR}")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -I${PROJECT_SOURCE_DIR}/include")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -I${PROJECT_BUILD_INCLUDE_DIR}")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -I${PROJECT_SOURCE_DIR}/extensions")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -I${PROJECT_BUILD_RELEASE_DIR}/include")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -isystem${PROJECT_SOURCE_DIR}/extensions/core/external/${NTA_PLATFORM_OS}/include")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -isystem${PROJECT_SOURCE_DIR}/extensions/core/external/common/include")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -isystem${PROJECT_SOURCE_DIR}/external/${NTA_PLATFORM_OS}/include")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -isystem${PROJECT_SOURCE_DIR}/external/common/include")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -isystem${NUPIC_CORE}/include")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -isystem${NUPIC_CORE}/include/yaml-cpp")
set(NTA_INCLUDEFLAGS "${NTA_INCLUDEFLAGS} -I${PYTHON_PREFIX}/lib")
include(${CMAKE_ROOT}/Modules/UseSWIG.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_SWIG_FLAGS
-features
autodoc=0,directors=0
-noproxyimport
-keyword
-modern
-modernargs
-noproxydel
-fvirtual
-fastunpack
-nofastproxy
-fastquery
-outputtuple
-castmode
-w402
-w503
-w511
-w302
-w362
-w312
-w389
-DSWIG_PYTHON_LEGACY_BOOL
-DNTA_PLATFORM_${PLATFORM}${BITNESS}
-DNTA_PYTHON_SUPPORT=${PYTHON_VERSION}
-I${NUMPY_INCLUDE_DIR}
-I${SWIG_DIR}/python
-I${SWIG_DIR}
-I${PYTHON_PREFIX}/lib)
set(SWIG_COMMON_LIBRARIES
${PYTHON_LIBRARIES}
dl
python${PYTHON_VERSION}
${LIB_STATIC_NUPICCORE}
${LIB_STATIC_SUPPORT})
set(LIB_SHARED_ENGINEINTERNAL engine_internal)
file(MAKE_DIRECTORY "${PROJECT_BUILD_TEMP_DIR}/extensions/bindings/py/engine_internal")
set_source_files_properties(extensions/bindings/py/engine_internal/EngineInternalPy.i PROPERTIES CPLUSPLUS ON)
set_property(SOURCE extensions/bindings/py/engine_internal/EngineInternalPy.i PROPERTY SWIG_FLAGS ${CMAKE_SWIG_FLAGS})
swig_add_module(${LIB_SHARED_ENGINEINTERNAL}
python
extensions/bindings/py/engine_internal/EngineInternalPy.i)
set_target_properties(${SWIG_MODULE_${LIB_SHARED_ENGINEINTERNAL}_REAL_NAME}
PROPERTIES COMPILE_FLAGS ${COMMON_COMPILE_FLAGS}
LINK_FLAGS ${COMMON_LINK_FLAGS}
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
swig_link_libraries(${LIB_SHARED_ENGINEINTERNAL} ${SWIG_COMMON_LIBRARIES})
set(LIB_SHARED_MATH math)
file(MAKE_DIRECTORY "${PROJECT_BUILD_TEMP_DIR}/extensions/bindings/py/math")
set_source_files_properties(extensions/bindings/py/math/MathPy.i PROPERTIES CPLUSPLUS ON)
set_property(SOURCE extensions/bindings/py/math/MathPy.i PROPERTY SWIG_FLAGS ${CMAKE_SWIG_FLAGS})
swig_add_module(${LIB_SHARED_MATH}
python
extensions/bindings/py/math/MathPy.i
extensions/bindings/py/math/PySparseTensor.cpp)
set_target_properties(${SWIG_MODULE_${LIB_SHARED_MATH}_REAL_NAME}
PROPERTIES COMPILE_FLAGS ${COMMON_COMPILE_FLAGS}
LINK_FLAGS ${COMMON_LINK_FLAGS}
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
swig_link_libraries(${LIB_SHARED_MATH} ${SWIG_COMMON_LIBRARIES})
set(LIB_SHARED_ALGORITHMS algorithms)
file(MAKE_DIRECTORY "${PROJECT_BUILD_TEMP_DIR}/extensions/bindings/py/algorithms")
set_source_files_properties(extensions/bindings/py/algorithms/AlgorithmsPy.i PROPERTIES CPLUSPLUS ON)
set_property(SOURCE extensions/bindings/py/algorithms/AlgorithmsPy.i PROPERTY SWIG_FLAGS ${CMAKE_SWIG_FLAGS})
swig_add_module(${LIB_SHARED_ALGORITHMS} python extensions/bindings/py/algorithms/AlgorithmsPy.i)
set_target_properties(${SWIG_MODULE_${LIB_SHARED_ALGORITHMS}_REAL_NAME}
PROPERTIES COMPILE_FLAGS ${COMMON_COMPILE_FLAGS}
LINK_FLAGS ${COMMON_LINK_FLAGS}
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
swig_link_libraries(${LIB_SHARED_ALGORITHMS} ${SWIG_COMMON_LIBRARIES})
set(LIB_SHARED_IORANGE iorange)
file(MAKE_DIRECTORY "${PROJECT_BUILD_TEMP_DIR}/extensions/bindings/py/iorange")
set_source_files_properties(extensions/bindings/py/iorange/IorangePy.i PROPERTIES CPLUSPLUS ON)
set_property(SOURCE extensions/bindings/py/iorange/IorangePy.i PROPERTY SWIG_FLAGS ${CMAKE_SWIG_FLAGS})
swig_add_module(${LIB_SHARED_IORANGE} python extensions/bindings/py/iorange/IorangePy.i)
set_target_properties(${SWIG_MODULE_${LIB_SHARED_IORANGE}_REAL_NAME}
PROPERTIES COMPILE_FLAGS ${COMMON_COMPILE_FLAGS}
LINK_FLAGS ${COMMON_LINK_FLAGS}
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
swig_link_libraries(${LIB_SHARED_IORANGE} ${SWIG_COMMON_LIBRARIES})
set(SKIP_COMPARE_VERSIONS (NOT ${FETCH_NUPIC_CORE}) CACHE BOOL "Skip nupic.core version comparison")
if (NOT ${SKIP_COMPARE_VERSIONS})
# Compare expected version of nupic.core against installed version
set(EXECUTABLE_COMPAREVERSION compare_nupic_core_version)
add_executable(${EXECUTABLE_COMPAREVERSION} extensions/compare_nupic_core_version.cpp)
target_link_libraries(${EXECUTABLE_COMPAREVERSION} ${COMMON_LIBS})
set_target_properties(${EXECUTABLE_COMPAREVERSION}
PROPERTIES COMPILE_FLAGS ${COMMON_COMPILE_FLAGS}
LINK_FLAGS "${COMMON_LINK_FLAGS}")
add_dependencies(${EXECUTABLE_COMPAREVERSION} ${COMMON_LIBS})
add_custom_target(assert_nupic_core_version
COMMAND ${EXECUTABLE_COMPAREVERSION} ${NUPIC_CORE_COMMITISH}
DEPENDS ${EXECUTABLE_COMPAREVERSION})
add_dependencies(${LIB_DYNAMIC_CPPREGION} assert_nupic_core_version)
endif()
#
# Custom targets
#
add_custom_target(python_unit_tests
COMMAND ${PYTHON} ${PROJECT_SOURCE_DIR}/scripts/run_tests.py -u --coverage
COMMENT "Python unit tests")
add_custom_target(python_integration_tests
COMMAND ${PYTHON} ${PROJECT_SOURCE_DIR}/scripts/run_tests.py -i --coverage
COMMENT "Python integration tests")
add_custom_target(python_swarming_tests
COMMAND ${PYTHON} ${PROJECT_SOURCE_DIR}/scripts/run_tests.py -w --coverage
COMMENT "Python swarming tests")
add_custom_target(python_all_tests
COMMAND ${PYTHON} ${PROJECT_SOURCE_DIR}/scripts/run_tests.py --all --coverage # swarming tests fail with the -n parallel run
COMMENT "Python tests + integration + swarming (requires DB)")
add_custom_target(tests_pyhtm
COMMAND testpyhtm
COMMENT "Basic tests in Python")
add_custom_target(tests_all
DEPENDS python_all_tests
DEPENDS tests_pyhtm
COMMENT "Running all tests")
#
# Installation targets
#
install(TARGETS
${EXECUTABLE_HTMTEST}
DESTINATION ${PROJECT_SOURCE_DIR}/bin)
install(TARGETS
${LIB_DYNAMIC_CPPREGION}
DESTINATION ${PROJECT_SOURCE_DIR}/nupic)
install(FILES
"${PROJECT_BINARY_DIR}/${SWIG_MODULE_${LIB_SHARED_ENGINEINTERNAL}_REAL_NAME}.so"
"${PROJECT_BUILD_TEMP_DIR}/${LIB_SHARED_ENGINEINTERNAL}.py"
"${PROJECT_BINARY_DIR}/${SWIG_MODULE_${LIB_SHARED_MATH}_REAL_NAME}.so"
"${PROJECT_BUILD_TEMP_DIR}/${LIB_SHARED_MATH}.py"
"${PROJECT_BINARY_DIR}/${SWIG_MODULE_${LIB_SHARED_ALGORITHMS}_REAL_NAME}.so"
"${PROJECT_BUILD_TEMP_DIR}/${LIB_SHARED_ALGORITHMS}.py"
"${PROJECT_BINARY_DIR}/${SWIG_MODULE_${LIB_SHARED_IORANGE}_REAL_NAME}.so"
"${PROJECT_BUILD_TEMP_DIR}/${LIB_SHARED_IORANGE}.py"
DESTINATION ${PROJECT_SOURCE_DIR}/nupic/bindings)