CMakeLists.txt 3.77 KB
Newer Older
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
1 2 3 4 5
cmake_minimum_required( VERSION 2.8 )
project( VAPython )

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

6 7 8 9 10 11 12 13
if( NOT DEFINED ITA_VAPYTHON_VERSION_MAJOR )
	set( ITA_VAPYTHON_VERSION_MAJOR "v2017" CACHE STRING "VAPython version major (usually 'v' and year)" )
endif( NOT DEFINED ITA_VAPYTHON_VERSION_MAJOR )

if( NOT DEFINED ITA_VAPYTHON_VERSION_MINOR )
	set( ITA_VAPYTHON_VERSION_MINOR "d" CACHE STRING "VAPython version minor (usually a,b,c ...)" )
endif( NOT DEFINED ITA_VAPYTHON_VERSION_MINOR )

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
14 15 16 17 18 19
include( VistaCommon )

vista_use_package( VANet REQUIRED FIND_DEPENDENCIES )
vista_use_package( PythonLibs REQUIRED )

if( ITA_VISTA_BUILD_STATIC )
20 21 22 23
	add_definitions( -DVISTA_STATIC )
	if( WIN32 )
		list( APPEND VISTA_USE_PACKAGE_LIBRARIES ws2_32 winspool )
	endif( )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
24 25 26 27
endif( )

if( NOT BUILD_SHARED_LIBS )
	add_definitions( -DVAPYTHON_STATIC -DVABASE_STATIC -DVANET_STATIC )
28 29
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." )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
30 31 32 33
endif( )

add_definitions( -DPy_NO_ENABLE_SHARED )

34

35
# 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.
36
add_library( VAPython STATIC "src/vasingleton.cpp" "src/vasingletondoc.hpp" "src/vasingletonmethods.hpp" "MANIFEST.in" "setup.py" )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
37 38 39
target_link_libraries( VAPython ${VISTA_USE_PACKAGE_LIBRARIES} )


40
# Run distutils after (useless) build in your dev env to compile the Python extension into 'dist' folder
41
configure_file( "setup.py.proto" "${CMAKE_CURRENT_SOURCE_DIR}/setup.py" @ONLY )
42 43 44 45
set( BATCH_SCRIPT_EXTENSION "bat" )
if( NOT WIN32 )
	set( BATCH_SCRIPT_EXTENSION "sh" )
endif( )
46
set( BATCH_SCRIPT_TYPE distutils_build_va_python )
47
add_custom_command( TARGET VAPython POST_BUILD COMMAND "${BATCH_SCRIPT_TYPE}.${BATCH_SCRIPT_EXTENSION}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "Running distutils" VERBATIM )
48

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
49
# configure
50 51 52 53
#vista_configure_lib( VAPython )
#vista_install( VAPython )
#vista_create_cmake_configs( VAPython )
#vista_create_default_info_file( VAPython )
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
54 55

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

57

58
# install
59 60 61 62 63 64 65 66

# 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" )
67
endif( )
68

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
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( )
87 88

# Tests
89
install( DIRECTORY "tests" DESTINATION "python" )
90 91

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