-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
86 lines (69 loc) · 3.38 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
cmake_minimum_required(VERSION 2.6)
project (python-moos)
find_package(MOOS 10 REQUIRED)
FIND_PACKAGE(PythonInterp 2.7)
if(PYTHONINTERP_FOUND)
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('INCLUDEDIR')" OUTPUT_VARIABLE PYTHON_INCLUDE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('LIBDIR')" OUTPUT_VARIABLE PYTHON_LIB_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(PYTHON_LIBRARIES "${PYTHON_LIB_PATH}/libpython2.7.dylib" CACHE FILEPATH "Path to the libpython2.7.dylib library file" FORCE)
if(IS_DIRECTORY "${PYTHON_INCLUDE_PATH}/Python2.7")
set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}/Python2.7" CACHE FILEPATH "Directory holding the python.h include file" FORCE)
else()
set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}/python2.7" CACHE FILEPATH "Directory holding the python.h include file" FORCE)
endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(PYTHON_LIBRARIES "${PYTHON_LIB_PATH}/x86_64-linux-gnu/libpython2.7.so" CACHE FILEPATH "Path to the libpython2.7.so library file" FORCE)
if(IS_DIRECTORY "${PYTHON_INCLUDE_PATH}/Python2.7")
set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}/Python2.7" CACHE FILEPATH "Directory holding the python.h include file" FORCE)
else()
set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_PATH}/python2.7" CACHE FILEPATH "Directory holding the python.h include file" FORCE)
endif()
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(PYTHONLIBS_FOUND TRUE)
message(STATUS "PYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARIES}")
message(STATUS "PYTHON_INCLUDE_DIR:FILEPATH=${PYTHON_INCLUDE_DIRS}")
else()
find_package(PythonLibs) # default to standard cmake approach
endif(PYTHONINTERP_FOUND)
if(PYTHONLIBS_FOUND)
include_directories("${PYTHON_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "Unable to find PythonLibs.")
endif()
find_package(Boost REQUIRED python)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
endif()
if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
endif()
if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${MOOS_INCLUDE_DIRS})
set(src
pyMOOS.cpp
)
add_library(pymoos SHARED ${src})
set_target_properties( pymoos
PROPERTIES
SUFFIX ".so"
)
set_target_properties(pymoos
PROPERTIES
PREFIX "")
file(GLOB ExampleFiles ${CMAKE_SOURCE_DIR}/Documentation/examples/*.py)
add_custom_target(copy)
get_target_property(pymoosLocation pymoos LOCATION)
get_filename_component(pymoosDir ${pymoosLocation} PATH)
foreach(ExampleFile ${ExampleFiles})
add_custom_command(TARGET copy PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy ${ExampleFile} ${pymoosDir})
endforeach()
add_dependencies(pymoos copy)
TARGET_LINK_LIBRARIES(pymoos ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${MOOS_LIBRARIES})