Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 0 additions & 156 deletions src/cython_cmake/cmake/UseCython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Name> [<CythonInput>]
# [C | CXX]
# [PY2 | PY3]
# [OUTPUT_VAR <OutputVar>])
#
# ``<Name>`` is the name of the new target, and ``<CythonInput>``
# 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 ``<Name>`` is provided, and it ends in the ".pyx" extension, then it
# is assumed to be the ``<CythonInput>``. The name of the input without the
# extension is used as the target name. If only ``<Name>`` is provided, and it
# does not end in the ".pyx" extension, then the ``<CythonInput>`` is assumed to
# be ``<Name>.pyx``.
#
# The Cython include search path is amended with any entries found in the
# ``INCLUDE_DIRECTORIES`` property of the directory containing the
# ``<CythonInput>`` 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 <OutputVar>``
# Set the variable ``<OutputVar>`` in the parent scope to the path to the
# generated source file. By default, ``<Name>`` is used as the output
# variable name.
#
# Defined variables:
#
# ``<OutputVar>``
# 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.
#
Expand All @@ -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)
Expand Down