diff --git a/src/cython_cmake/cmake/UseCython.cmake b/src/cython_cmake/cmake/UseCython.cmake index 4daf8bf..0dede78 100644 --- a/src/cython_cmake/cmake/UseCython.cmake +++ b/src/cython_cmake/cmake/UseCython.cmake @@ -57,76 +57,6 @@ # ) # # -# .. cmake:command:: add_cython_target -# -# Create a custom rule to generate the source code for a Python extension module -# using cython. -# -# add_cython_target( [] -# [C | CXX] -# [PY2 | PY3] -# [OUTPUT_VAR ]) -# -# ```` is the name of the new target, and ```` -# is the path to a cython source file. Note that, despite the name, no new -# targets are created by this function. Instead, see ``OUTPUT_VAR`` for -# retrieving the path to the generated source for subsequent targets. -# -# If only ```` is provided, and it ends in the ".pyx" extension, then it -# is assumed to be the ````. The name of the input without the -# extension is used as the target name. If only ```` is provided, and it -# does not end in the ".pyx" extension, then the ```` is assumed to -# be ``.pyx``. -# -# The Cython include search path is amended with any entries found in the -# ``INCLUDE_DIRECTORIES`` property of the directory containing the -# ```` file. Use ``include_directories`` to add to the Cython -# include search path. -# -# Options: -# -# ``C | CXX`` -# Force the generation of either a C or C++ file. By default, a C file is -# generated, unless the C language is not enabled for the project; in this -# case, a C++ file is generated by default. -# -# ``PY2 | PY3`` -# Force compilation using either Python-2 or Python-3 syntax and code -# semantics. By default, Python-2 syntax and semantics are used if the major -# version of Python found is 2. Otherwise, Python-3 syntax and semantics are -# used. -# -# ``OUTPUT_VAR `` -# Set the variable ```` in the parent scope to the path to the -# generated source file. By default, ```` is used as the output -# variable name. -# -# Defined variables: -# -# ```` -# The path of the generated source file. -# -# Cache variables that affect the behavior include: -# -# ``CYTHON_ANNOTATE`` -# Whether to create an annotated .html file when compiling. -# -# ``CYTHON_FLAGS`` -# Additional flags to pass to the Cython compiler. -# -# Usage example: -# -# .. code-block:: cmake -# -# find_package(Cython) -# -# # Note: In this case, either one of these arguments may be omitted; their -# # value would have been inferred from that of the other. -# add_cython_target(cy_code cy_code.pyx) -# -# add_library(cy_code MODULE ${cy_code}) -# target_link_libraries(cy_code ...) -# #============================================================================= # Copyright 2011 Kitware, Inc. # @@ -144,92 +74,6 @@ #============================================================================= -function(add_cython_target _name) - set(_options C CXX PY2 PY3) - set(_one_value OUTPUT_VAR) - set(_multi_value ) - - cmake_parse_arguments(_args - "${_options}" - "${_one_value}" - "${_multi_value}" - ${ARGN} - ) - - # Configuration options. - set(CYTHON_ANNOTATE OFF - CACHE BOOL "Create an annotated .html file when compiling *.pyx.") - - set(CYTHON_FLAGS "" CACHE STRING - "Extra flags to the cython compiler.") - mark_as_advanced(CYTHON_ANNOTATE CYTHON_FLAGS) - - if(_args_C) - set(_language "C") - endif() - if(_args_CXX) - set(_language "CXX") - endif() - - if(_args_PY2) - set(_language_level "2") - endif() - if(_args_PY3) - set(_language_level "3") - endif() - - list(GET _args_UNPARSED_ARGUMENTS 0 _arg0) - - # if provided, use _arg0 as the input file path - if(_arg0) - set(_source_file ${_arg0}) - - # otherwise, must determine source file from name, or vice versa - else() - get_filename_component(_name_ext "${_name}" EXT) - - # if extension provided, _name is the source file - if(_name_ext) - set(_source_file ${_name}) - get_filename_component(_name "${_source_file}" NAME_WE) - - # otherwise, assume the source file is ${_name}.pyx - else() - set(_source_file ${_name}.pyx) - endif() - endif() - - # Set additional flags. - set(_cython_args) - if(CYTHON_ANNOTATE) - list(APPEND _cython_args "--annotate") - endif() - if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR - CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - list(APPEND _cython_args - "--gdb" - "--line-directives" - ) - endif() - string(STRIP "${CYTHON_FLAGS}" _stripped_cython_flags) - if(_stripped_cython_flags) - string(REGEX REPLACE " " ";" CYTHON_FLAGS_LIST "${_stripped_cython_flags}") - list(APPEND _cython_args ${CYTHON_FLAGS_LIST}) - endif() - - Cython_compile_pyx( - LANGUAGE ${_language} - LANGUAGE_LEVEL ${_language_level} - CYTHON_ARGS ${_cython_args} - OUTPUT_VARIABLE ${_args_OUTPUT_VAR} - ${_source_file} - ) - - if(_args_OUTPUT_VAR) - set(${_args_OUTPUT_VAR} ${${_args_OUTPUT_VAR}} PARENT_SCOPE) - endif() -endfunction() - function(Cython_compile_pyx) set(_options ) set(_one_value LANGUAGE_LEVEL LANGUAGE OUTPUT_VARIABLE)