-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
61 lines (46 loc) · 1.97 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
cmake_minimum_required(VERSION 2.6)
project(ndreg)
set(PACKAGE_VERSION "0.0.1")
#option(EnableProfiling "Enable profiling with pprof" OFF)
#if(EnableProfiling)
# set(FLAG_LIST "CMAKE_CXX_FLAGS;CMAKE_EXE_LINKER_FLAGS;CMAKE_SHARED_LINKER_FLAGS")
# foreach(FLAG ${FLAG_LIST})
# get_property(helpString CACHE ${FLAG} PROPERTY HELPSTRING)
# set(${FLAG} "${${FLAG}} -pg" CACHE STRING "${helpString}" FORCE)
# endforeach()
#endif()
# Build metamorphosis binary
find_package(ITK)
if(NOT ITK_FOUND)
message(FATAL_ERROR "ITK not found. Please set ITK_DIR.")
endif()
find_program(PYTHON "python")
if(NOT PYTHON)
message(FATAL_ERROR "Python not found. Please set PYTHON.")
endif()
# Configure setup.py in binary directory
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
configure_file(${SETUP_PY_IN} ${SETUP_PY})
# Copy python source files to binary directory
set(PY_FILENAME_LIST "ndreg.py;landmarks.py;__init__.py")
foreach(FILENAME ${PY_FILENAME_LIST})
set(SRC_PY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ndreg/${FILENAME})
set(BIN_PY_PATH ${CMAKE_CURRENT_BINARY_DIR}/ndreg/${FILENAME})
set(BIN_PY_PATH_LIST ${BIN_PY_PATH_LIST} ${BIN_PY_PATH})
add_custom_command(OUTPUT ${BIN_PY_PATH}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SRC_PY_PATH} ${BIN_PY_PATH}
DEPENDS ${SRC_PY_PATH})
endforeach()
# Build ndreg egg
include(${ITK_USE_FILE})
add_subdirectory(ndreg)
set(TIMESTAMP "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")
add_custom_command(OUTPUT ${TIMESTAMP}
COMMAND ${PYTHON} -m py_compile ${BIN_PY_PATH_LIST} # Check for syntax errors by compiling python files
COMMAND ${PYTHON} ${SETUP_PY} build # Make the egg
COMMAND ${CMAKE_COMMAND} -E touch ${TIMESTAMP} # Generate timestamp file
DEPENDS ${BIN_PY_PATH_LIST} metamorphosis)
add_custom_target(ndreg ALL DEPENDS ${TIMESTAMP})
# Install ndreg egg
install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install --user)")