-
Notifications
You must be signed in to change notification settings - Fork 28
/
CMakeLists.txt
160 lines (122 loc) · 6.43 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
cmake_minimum_required( VERSION 2.8 )
project( pyreclab )
#
# Project version
#
set( MAJOR_VERSION "0" )
set( MINOR_VERSION "1" )
set( RELEASE_VERSION "15" )
set( PACKAGE_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${RELEASE_VERSION}" )
# Set CMake macros
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${PROJECT_SOURCE_DIR}/cmake_scripts )
#
# Compilation options
#
set( PRLOPT_BUILD_WHEEL OFF CACHE BOOL "Build wheel package" )
set( CMAKE_PYTHON_VERSION 2.7 CACHE STRING "Python version" )
if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
set( MANYLINUX_VERSION manylinux1 CACHE STRING "manylinux version" )
if( ${CMAKE_PYTHON_VERSION} VERSION_LESS "3.3" ) # Before Python 3.3, there were two ABI-incompatible ways of building CPython
set( CMAKE_PYTHON_UCS4 ON CACHE BOOL "Enable unicode ucs4" )
else( ${CMAKE_PYTHON_VERSION} VERSION_LESS "3.3" )
unset( CMAKE_PYTHON_UCS4 CACHE )
endif( ${CMAKE_PYTHON_VERSION} VERSION_LESS "3.3" )
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
# Compiler definitions
add_definitions( -DNDEBUG )
add_compile_options( -fPIC )
add_compile_options( -O3 )
add_compile_options( -Wall )
find_package( PythonLibs "${CMAKE_PYTHON_VERSION}"
REQUIRED )
find_package( Boost REQUIRED )
include_directories(${Boost_INCLUDE_DIRS})
#
# Library building
#
add_subdirectory( dataio temp/dataio )
add_subdirectory( datahandlers temp/datahandlers )
add_subdirectory( algorithms temp/algorithms )
add_subdirectory( pyinterface temp/pyinterface )
add_subdirectory( eval_metrics temp/eval_metrics )
add_subdirectory( tools temp/tools )
if( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
set( CMAKE_MACOSX_RPATH 0 )
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
add_library( pyreclab SHARED
$<TARGET_OBJECTS:dataio>
$<TARGET_OBJECTS:datahandlers>
$<TARGET_OBJECTS:tools>
$<TARGET_OBJECTS:algorithms>
$<TARGET_OBJECTS:eval_metrics>
$<TARGET_OBJECTS:pyinterface> )
if( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
target_link_libraries( pyreclab ${PYTHON_LIBRARY} )
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
set_target_properties( pyreclab PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/pyreclab"
SUFFIX .so
SOVERSION "${MAJOR_VERSION}"
VERSION "${PACKAGE_VERSION}" )
# Library compilation for native version of Python 2.7
if( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND ${CMAKE_PYTHON_VERSION} VERSION_EQUAL "2.7" )
find_package( Python27MacOSXNativeLibs "${CMAKE_PYTHON_VERSION}"
REQUIRED )
set( LIBNAME_SUFFIX "_native_py" )
add_subdirectory( pyinterface temp/pyinterface${LIBNAME_SUFFIX} )
add_library( pyreclab${LIBNAME_SUFFIX} SHARED
$<TARGET_OBJECTS:dataio>
$<TARGET_OBJECTS:datahandlers>
$<TARGET_OBJECTS:tools>
$<TARGET_OBJECTS:algorithms>
$<TARGET_OBJECTS:eval_metrics>
$<TARGET_OBJECTS:pyinterface${LIBNAME_SUFFIX}> )
target_link_libraries( pyreclab${LIBNAME_SUFFIX} ${PYTHON_NATIVE_LIBRARY} )
set_target_properties( pyreclab${LIBNAME_SUFFIX} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/pyreclab"
SUFFIX .so
SOVERSION "${MAJOR_VERSION}"
VERSION "${PACKAGE_VERSION}" )
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND ${CMAKE_PYTHON_VERSION} VERSION_EQUAL "2.7" )
#
# Python packaging
#
if( PYTHON )
set( CMAKE_LIBRARY_LIST "'libpyreclab.so'" )
if( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND ${CMAKE_PYTHON_VERSION} VERSION_EQUAL "2.7" )
set( CMAKE_LIBRARY_LIST "${CMAKE_LIBRARY_LIST}, 'libpyreclab${LIBNAME_SUFFIX}.so'" )
set( PACKAGING_DEPS "pyreclab" "pyreclab_native_py" )
else( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND ${CMAKE_PYTHON_VERSION} VERSION_EQUAL "2.7" )
set( PACKAGING_DEPS "pyreclab" )
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND ${CMAKE_PYTHON_VERSION} VERSION_EQUAL "2.7" )
set( SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/pypackage/setup.py.in" )
set( SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/pypackage/setup.py" )
set( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp" )
set( DEPS "${PACKAGING_DEPS}" )
configure_file( ${SETUP_PY_IN} ${SETUP_PY} )
execute_process( COMMAND mkdir -p ${PROJECT_BINARY_DIR}/pyreclab/ )
execute_process( COMMAND cp ${PROJECT_BINARY_DIR}/pypackage/__init__.py ${PROJECT_BINARY_DIR}/pyreclab/ )
install( CODE "execute_process(COMMAND ${PYTHON} pypackage/setup.py install)" )
if( ${PRLOPT_BUILD_WHEEL} )
if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
add_custom_command( OUTPUT ${OUTPUT}
COMMAND ${CMAKE_COMMAND} -E copy "pypackage/__init__.py" "${PROJECT_BINARY_DIR}/pyreclab/"
COMMAND ${PYTHON} ${SETUP_PY} bdist_wheel "--plat-name" ${MANYLINUX_VERSION}_${CMAKE_SYSTEM_PROCESSOR} # PEP 513
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
DEPENDS ${DEPS} )
add_custom_target( pypackage ALL
DEPENDS ${OUTPUT} )
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
if( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
execute_process( COMMAND python -c "import distutils.util; print(distutils.util.get_platform())" OUTPUT_VARIABLE PY_PLATFORM )
string( REGEX REPLACE "\\." "_" PY_PLATFORM "${PY_PLATFORM}" )
string( REGEX REPLACE "-" "_" PY_PLATFORM "${PY_PLATFORM}" )
add_custom_command( OUTPUT ${OUTPUT}
COMMAND ${CMAKE_COMMAND} -E copy "pypackage/__init__.py" "${PROJECT_BINARY_DIR}/pyreclab/"
COMMAND ${PYTHON} ${SETUP_PY} bdist_wheel "--plat-name" ${PY_PLATFORM}
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
DEPENDS ${DEPS} )
add_custom_target( pypackage ALL
DEPENDS ${OUTPUT} )
endif( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
endif( ${PRLOPT_BUILD_WHEEL})
endif( PYTHON )