-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
139 lines (114 loc) · 4.7 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
cmake_minimum_required(VERSION 2.8.4)
project(nix_mx C CXX)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 4)
set(VERSION_PATCH 2)
set(VERSION_ABI 1)
# Switch static build
option(BUILD_STATIC "Build static version of the library" ON)
set(CMAKE_MACOSX_RPATH NOT${BUILD_STATIC})
### include local modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wunreachable-code")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -ggdb3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O2")
endif()
# packages
# Provide Boost lib
set(Boost_USE_STATIC_LIBS ${BUILD_STATIC})
find_package(Boost 1.49.0 REQUIRED date_time regex program_options system filesystem)
include_directories(${Boost_INCLUDE_DIR})
# Provide HDF5 lib
set(HDF5_USE_STATIC_LIBRARIES ${BUILD_STATIC})
find_package (HDF5 REQUIRED COMPONENTS C)
# The computing environment
if($ENV{CI})
find_package(Octave REQUIRED)
else()
find_package(MATLAB REQUIRED)
endif()
if(OCTAVE_FOUND)
add_definitions(-DMATLAB_MEX_FILE)
set(CE_PACKAGE "GNU Octave")
set(CE_VERSION "${OCTAVE_VERSION_STRING}")
set(CE_INCDIR ${OCTAVE_INCLUDE_DIRS})
set(CE_LIBRARIES ${OCTAVE_LIBRARIES})
set(CE_EXTENSION oct)
endif()
if(MATLAB_FOUND)
MESSAGE(STATUS "Matlab found at ${MATLAB_INCLUDE_DIR}")
add_definitions(-DMATLAB_MEX_FILE)
set(CE_PACKAGE "Matlab")
set(CE_VERSION "${MATLAB_VERSION}")
set(CE_INCDIR ${MATLAB_INCLUDE_DIR})
set(CE_LIBRARIES ${MATLAB_LIBRARIES})
set(CE_EXTENSION ${MATLAB_MEXEXT})
endif(MATLAB_FOUND)
if(NOT CE_PACKAGE)
MESSAGE(FATAL_ERROR "
No computing environment found!
Install GNU Octave (or MathWorks MATLAB).")
endif()
set(NIX_USE_STATIC_LIBS ${BUILD_STATIC})
find_package(NIX REQUIRED)
include_directories(${CE_INCDIR} ${NIX_INCLUDE_DIR} "src" "src/utils")
file(GLOB_RECURSE SOURCE_FILES src/*.cc)
file(GLOB_RECURSE INCLUDE_FILES src/*.h)
if(NOT WIN32)
set(LIBTYPE SHARED)
else()
set(LIBTYPE MODULE)
endif()
add_library(nix_mx ${LIBTYPE} nix_mx.cc ${SOURCE_FILES} ${INCLUDE_FILES})
target_link_libraries(nix_mx ${CE_LIBRARIES} ${NIX_LIBRARIES} ${Boost_LIBRARIES} ${HDF5_LIBRARIES})
set_target_properties(nix_mx PROPERTIES
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
SOVERSION ${VERSION_ABI})
set_target_properties(nix_mx PROPERTIES PREFIX "")
set_target_properties(nix_mx PROPERTIES SUFFIX .${CE_EXTENSION})
if(WIN32)
SET_TARGET_PROPERTIES(nix_mx PROPERTIES LINK_FLAGS "/export:mexFunction")
endif()
if(DEBUG_GLUE)
add_definitions(-DDEBUG_GLUE=1)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND ${CMAKE_VERSION} VERSION_GREATER 3.2)
set(ZIP_FILE_NAME "nix_mx_macOS_${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.zip")
add_custom_target(
macOS_zip
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/+nix ${CMAKE_BINARY_DIR}/+nix
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/examples ${CMAKE_BINARY_DIR}/examples
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests ${CMAKE_BINARY_DIR}/tests
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_BINARY_DIR}/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/startup.m ${CMAKE_BINARY_DIR}/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/LICENSE.txt ${CMAKE_BINARY_DIR}/
COMMAND ${CMAKE_COMMAND} -E tar "cf" ${ZIP_FILE_NAME} --format=zip
"${CMAKE_BINARY_DIR}/+nix"
"${CMAKE_BINARY_DIR}/LICENSE.txt"
"${CMAKE_BINARY_DIR}/README.md"
"${CMAKE_BINARY_DIR}/tests"
"${CMAKE_BINARY_DIR}/examples"
"${CMAKE_BINARY_DIR}/startup.m"
"${CMAKE_BINARY_DIR}/*.mexmac*"
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/+nix
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/tests
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/examples
COMMAND ${CMAKE_COMMAND} -E rm ${CMAKE_BINARY_DIR}/LICENSE.txt
COMMAND ${CMAKE_COMMAND} -E rm ${CMAKE_BINARY_DIR}/README.md
COMMAND ${CMAKE_COMMAND} -E rm ${CMAKE_BINARY_DIR}/startup.m)
endif()
MESSAGE(STATUS "===============================")
MESSAGE(STATUS "READY. ")
MESSAGE(STATUS "===============================")
MESSAGE(STATUS "Computing environment")
MESSAGE(STATUS " Package: ${CE_PACKAGE}")
MESSAGE(STATUS " Version: ${CE_VERSION}")
MESSAGE(STATUS " Module : ${CE_EXTENSION}")
MESSAGE(STATUS " BOOST : ${Boost_LIBRARIES}")
MESSAGE(STATUS " NIX : ${NIX_LIBRARIES}")
MESSAGE(STATUS "===============================")
MESSAGE(STATUS "CFLAGS: ${CMAKE_CXX_FLAGS}")
MESSAGE(STATUS "STATIC: ${BUILD_STATIC}")
MESSAGE(STATUS "===============================")