CMakeLists.txt 3.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
cmake_minimum_required( VERSION 2.8 )
project( VAPython )

list( APPEND CMAKE_MODULE_PATH "$ENV{VISTA_CMAKE_COMMON}" )

include( VistaCommon )

vista_use_package( VANet REQUIRED FIND_DEPENDENCIES )
vista_use_package( PythonLibs REQUIRED )

if( ITA_VISTA_BUILD_STATIC )
	add_definitions( -DVISTABASE_STATIC -DVISTAMATH_STATIC -DVISTAASPECTS_STATIC -DVISTATOOLS_STATIC -DVISTAINTERPROCCOMM_STATIC )
endif( )

if( NOT BUILD_SHARED_LIBS )
	add_definitions( -DVAPYTHON_STATIC -DVABASE_STATIC -DVANET_STATIC )
17 18
else( )
	message( WARNING "You are building shared libs, but it is _highly_ recommended to use static linking against ViSTA and VA libs with the Python binding. Otherwise DLLs with mismatching version could be loaded, which will lead to unpredictable behavior." )
19 20 21 22
endif( )

add_definitions( -DPy_NO_ENABLE_SHARED )

23

24
# Only add library here to check if it compiles in your preferred build env. CMake will run Python distutils to actually compile the extension, see below.
25
add_library( VAPython STATIC "src/vasingleton.cpp" "src/vasingletondoc.hpp" "src/vasingletonmethods.hpp" "MANIFEST.in" "setup.py" )
26 27 28
target_link_libraries( VAPython ${VISTA_USE_PACKAGE_LIBRARIES} )


29 30 31 32 33
# Run distutils after (useless) build in your dev env to compile the Python extension into 'dist' folder
set( BATCH_SCRIPT_EXTENSION "bat" )
if( NOT WIN32 )
	set( BATCH_SCRIPT_EXTENSION "sh" )
endif( )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
34 35 36 37 38
set( BATCH_SCRIPT_TYPE distutils_build_static )
if( BUILD_SHARED_LIBS )
	set( BATCH_SCRIPT_TYPE distutils_build_shared )
endif( )
add_custom_command( TARGET VAPython POST_BUILD COMMAND "${BATCH_SCRIPT_TYPE}.${BATCH_SCRIPT_EXTENSION}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running distutils" VERBATIM )
39

40
# configure
41 42 43 44
#vista_configure_lib( VAPython )
#vista_install( VAPython )
#vista_create_cmake_configs( VAPython )
#vista_create_default_info_file( VAPython )
45 46

set_property( TARGET VAPython PROPERTY FOLDER "VA/Bindings" )
47

48

49
# install
50 51 52 53 54 55 56 57

# Copy python extension if available. Requires successful distutils execution.
vista_install_files_by_extension( dist/Lib/site-packages "python/Lib/site-packages" "pyd" "egg-info" )

# install by copying DLL/SO next to python extension
set( SHARED_LIBRARY_EXTENSION "dll" )
if( NOT WIN32 )
	set( SHARED_LIBRARY_EXTENSION "so" )
58
endif( )
59

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
if( BUILD_SHARED_LIBS )
	# VA shared libs
	install( FILES "${VABASE_LIBRARY_DIRS}/VABase.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" )
	install( FILES "${VANET_LIBRARY_DIRS}/VANet.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" )

	# VistaCoreLibs shared libs
	foreach( VISTACORELIBS_LIBRARY_DIR ${VISTACORELIBS_LIBRARY_DIRS} )
		if( EXISTS "${VISTACORELIBS_LIBRARY_DIR}/VistaBase.${SHARED_LIBRARY_EXTENSION}" )
			install( FILES "${VISTACORELIBS_LIBRARY_DIR}/VistaBase.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" )
		endif( )
		if( EXISTS "${VISTACORELIBS_LIBRARY_DIR}/VistaAspects.${SHARED_LIBRARY_EXTENSION}" )
			install( FILES "${VISTACORELIBS_LIBRARY_DIR}/VistaAspects.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" )
		endif( )
		if( EXISTS "${VISTACORELIBS_LIBRARY_DIR}/VistaInterProcComm.${SHARED_LIBRARY_EXTENSION}" )
			install( FILES "${VISTACORELIBS_LIBRARY_DIR}/VistaInterProcComm.${SHARED_LIBRARY_EXTENSION}" DESTINATION "python/Lib/site-packages" )
		endif( )
	endforeach( )
endif( )
78 79

# Tests
80
install( DIRECTORY "tests" DESTINATION "python" )
81 82

# Examples
83
install( DIRECTORY "examples" DESTINATION "python" )