diff --git a/rosidl_generator_py/CMakeLists.txt b/rosidl_generator_py/CMakeLists.txt index fb7fba50..3f0aabd0 100644 --- a/rosidl_generator_py/CMakeLists.txt +++ b/rosidl_generator_py/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.14) project(rosidl_generator_py) diff --git a/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake b/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake index 4af35d68..58a4598d 100644 --- a/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake +++ b/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake @@ -17,10 +17,12 @@ find_package(rosidl_runtime_c REQUIRED) find_package(rosidl_typesupport_c REQUIRED) find_package(rosidl_typesupport_interface REQUIRED) -find_package(PythonInterp 3.5 REQUIRED) +# find_package(PythonInterp 3.5 REQUIRED) -find_package(python_cmake_module REQUIRED) -find_package(PythonExtra MODULE REQUIRED) +# find_package(python_cmake_module REQUIRED) +# find_package(PythonExtra MODULE REQUIRED) + +find_package(Python3 REQUIRED Development Interpreter NumPy) # Get a list of typesupport implementations from valid rmw implementations. rosidl_generator_py_get_typesupports(_typesupport_impls) @@ -126,11 +128,6 @@ endif() set(_target_suffix "__py") -set(_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) -if(WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE_DEBUG}) -endif() - # move custom command into a subdirectory to avoid multiple invocations on Windows set(_subdir "${CMAKE_CURRENT_BINARY_DIR}/${rosidl_generate_interfaces_TARGET}${_target_suffix}") file(MAKE_DIRECTORY "${_subdir}") @@ -142,23 +139,6 @@ set_property( ${_generated_extension_files} ${_generated_py_files} ${_generated_c_files} PROPERTY GENERATED 1) -macro(set_properties _build_type) - set_target_properties(${_target_name} PROPERTIES - COMPILE_OPTIONS "${_extension_compile_flags}" - PREFIX "" - LIBRARY_OUTPUT_DIRECTORY${_build_type} ${_output_path} - RUNTIME_OUTPUT_DIRECTORY${_build_type} ${_output_path} - OUTPUT_NAME "${PROJECT_NAME}_s__${_typesupport_impl}${PythonExtra_EXTENSION_SUFFIX}" - SUFFIX "${PythonExtra_EXTENSION_EXTENSION}") -endmacro() - -macro(set_lib_properties _build_type) - set_target_properties(${_target_name_lib} PROPERTIES - COMPILE_OPTIONS "${_extension_compile_flags}" - LIBRARY_OUTPUT_DIRECTORY${_build_type} ${_output_path} - RUNTIME_OUTPUT_DIRECTORY${_build_type} ${_output_path}) -endmacro() - set(_target_name_lib "${rosidl_generate_interfaces_TARGET}__python") add_library(${_target_name_lib} SHARED ${_generated_c_files}) target_link_libraries(${_target_name_lib} @@ -171,44 +151,25 @@ add_dependencies( target_link_libraries( ${_target_name_lib} - ${PythonExtra_LIBRARIES} + Python3::NumPy + Python3::Python ) target_include_directories(${_target_name_lib} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_c ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_py - ${PythonExtra_INCLUDE_DIRS} ) -# Check if numpy is in the include path -find_file(_numpy_h numpy/numpyconfig.h - PATHS ${PythonExtra_INCLUDE_DIRS} -) +# rosidl_get_typesupport_target(c_typesupport_target "${rosidl_generate_interfaces_TARGET}" "rosidl_typesupport_c") +# TODO(sloretz) - replace line below with ros2/rosidl#606 line above +set(c_typesupport_target"${rosidl_generate_interfaces_TARGET}__rosidl_typesupport_c") # XXX +target_link_libraries(${_target_name_lib} ${c_typesupport_target}) -if(APPLE OR WIN32 OR NOT _numpy_h) - # add include directory for numpy headers - set(_python_code - "import numpy" - "print(numpy.get_include())" - ) - execute_process( - COMMAND "${PYTHON_EXECUTABLE}" "-c" "${_python_code}" - OUTPUT_VARIABLE _output - RESULT_VARIABLE _result - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(NOT _result EQUAL 0) - message(FATAL_ERROR - "execute_process(${PYTHON_EXECUTABLE} -c '${_python_code}') returned " - "error code ${_result}") - endif() - message(STATUS "Using numpy include directory: ${_output}") - target_include_directories(${_target_name_lib} PUBLIC "${_output}") +set(_extension_compile_flags "") +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(_extension_compile_flags -Wall -Wextra) endif() -rosidl_target_interfaces(${_target_name_lib} - ${rosidl_generate_interfaces_TARGET} rosidl_typesupport_c) - foreach(_typesupport_impl ${_typesupport_impls}) find_package(${_typesupport_impl} REQUIRED) # a typesupport package might not be able to generated a target anymore @@ -217,10 +178,9 @@ foreach(_typesupport_impl ${_typesupport_impls}) continue() endif() - set(_pyext_suffix "__pyext") - set(_target_name "${PROJECT_NAME}__${_typesupport_impl}${_pyext_suffix}") + set(_target_name "${PROJECT_NAME}_s__${_typesupport_impl}") - add_library(${_target_name} SHARED + Python3_add_library(${_target_name} MODULE ${_generated_extension_${_typesupport_impl}_files} ) add_dependencies( @@ -229,21 +189,17 @@ foreach(_typesupport_impl ${_typesupport_impls}) ${rosidl_generate_interfaces_TARGET}__rosidl_typesupport_c ) - set(_extension_compile_flags "") - if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(_extension_compile_flags -Wall -Wextra) - endif() - set_properties("") - if(WIN32) - set_properties("_DEBUG") - set_properties("_MINSIZEREL") - set_properties("_RELEASE") - set_properties("_RELWITHDEBINFO") - endif() + # target_compile_options(${_target_name} PRIVATE ${_extension_compile_flags}) + # TODO(sloretz) use target_compile_options when python extension passes -Wpedantic + set_target_properties(${_target_name} PROPERTIES COMPILE_OPTIONS "${_extension_compile_flags}") # XXX + + set_target_properties(${_target_name} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${_output_path} + RUNTIME_OUTPUT_DIRECTORY ${_output_path}) + target_link_libraries( - ${_target_name} + ${_target_name} PUBLIC ${_target_name_lib} - ${PythonExtra_LIBRARIES} ${rosidl_generate_interfaces_TARGET}__${_typesupport_impl} ) @@ -251,19 +207,17 @@ foreach(_typesupport_impl ${_typesupport_impls}) PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_c ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_py - ${PythonExtra_INCLUDE_DIRS} ) - rosidl_target_interfaces(${_target_name} - ${rosidl_generate_interfaces_TARGET} rosidl_typesupport_c) + target_link_libraries(${_target_name} PUBLIC ${c_typesupport_target}) - ament_target_dependencies(${_target_name} + ament_target_dependencies(${_target_name} PUBLIC "rosidl_runtime_c" "rosidl_typesupport_c" "rosidl_typesupport_interface" ) foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES}) - ament_target_dependencies(${_target_name} + ament_target_dependencies(${_target_name} PUBLIC ${_pkg_name} ) endforeach() @@ -271,18 +225,18 @@ foreach(_typesupport_impl ${_typesupport_impls}) add_dependencies(${_target_name} ${rosidl_generate_interfaces_TARGET}__${_typesupport_impl} ) - ament_target_dependencies(${_target_name} + ament_target_dependencies(${_target_name} PUBLIC "rosidl_runtime_c" "rosidl_generator_py" ) if(NOT rosidl_generate_interfaces_SKIP_INSTALL) + # PYTHON_INSTALL_DIR is defined by ament_cmake_python install(TARGETS ${_target_name} DESTINATION "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}") endif() endforeach() -set(PYTHON_EXECUTABLE ${_PYTHON_EXECUTABLE}) foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES}) set(_pkg_install_base "${${_pkg_name}_DIR}/../../..") @@ -297,13 +251,15 @@ foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES}) endif() endforeach() -set_lib_properties("") -if(WIN32) - set_lib_properties("_DEBUG") - set_lib_properties("_MINSIZEREL") - set_lib_properties("_RELEASE") - set_lib_properties("_RELWITHDEBINFO") -endif() + +# target_compile_options(${_target_name_lib} PRIVATE ${_extension_compile_flags}) +# TODO(sloretz) use target_compile_options when python extension passes -Wpedantic +set_target_properties(${_target_name_lib} PROPERTIES COMPILE_OPTIONS "${_extension_compile_flags}") # XXX + +set_target_properties(${_target_name_lib} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${_output_path} + RUNTIME_OUTPUT_DIRECTORY ${_output_path}) + if(NOT rosidl_generate_interfaces_SKIP_INSTALL) install(TARGETS ${_target_name_lib} ARCHIVE DESTINATION lib