File: FindPyCXX.cmake

package info (click to toggle)
freecad 1.0.0%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 463,492 kB
  • sloc: cpp: 930,635; python: 586,652; xml: 103,037; ansic: 9,568; fortran: 3,878; lex: 699; sh: 645; javascript: 311; yacc: 271; makefile: 120
file content (128 lines) | stat: -rw-r--r-- 4,338 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Locate PyCXX headers and source files

# This module defines
# PYCXX_INCLUDE_DIR
# PYCXX_SOURCE_DIR
# PYCXX_FOUND
# PYCXX_SOURCES
# PYCXX_VERSION
#
# The PYCXX_*_DIR variables can be set to tell this module where
# the files are.


# There's no standard location for PyCXX.
#
# The authors' example is to put it in "~\" [sic].
#
# Ubuntu puts the includes into /usr/include/python2.7/CXX and sources into
# /usr/share/python2.7/CXX.
#
# The Zultron Fedora RPM does the same as Ubuntu.

set(PYCXX_FOUND "YES")

# find the header directory
if(PYCXX_INCLUDE_DIR)
    # headers better be in there
    if(NOT EXISTS "${PYCXX_INCLUDE_DIR}/CXX/Config.hxx")
        if(PyCXX_FIND_REQUIRED)
            MESSAGE(FATAL_ERROR
                "PyCXX: could not find CXX/Config.hxx in PYCXX_INCLUDE_DIR "
            "${PYCXX_INCLUDE_DIR}")
        else(PyCXX_FIND_REQUIRED)
            MESSAGE(WARNING
                "PyCXX: could not find CXX/Config.hxx in PYCXX_INCLUDE_DIR "
            "${PYCXX_INCLUDE_DIR}")
            unset(PYCXX_FOUND)
        endif(PyCXX_FIND_REQUIRED)
    endif(NOT EXISTS "${PYCXX_INCLUDE_DIR}/CXX/Config.hxx")
else(PYCXX_INCLUDE_DIR)
    # check in 'standard' places
    find_path(PYCXX_INCLUDE_DIR CXX/Config.hxx
        ${PYTHON_INCLUDE_DIR}
        "${CMAKE_CURRENT_LIST_DIR}/..")
    if(NOT PYCXX_INCLUDE_DIR)
        if(PyCXX_FIND_REQUIRED)
            MESSAGE(FATAL_ERROR
                "PyCXX not found; please set PYCXX_INCLUDE_DIR to "
                "the location of CXX/Config.hxx")
        else(PyCXX_FIND_REQUIRED)
            MESSAGE(STATUS "PyCXX not found")
            unset(PYCXX_FOUND)
        endif(PyCXX_FIND_REQUIRED)
    endif(NOT PYCXX_INCLUDE_DIR)
endif(PYCXX_INCLUDE_DIR)

# find the sources directory
if(PYCXX_SOURCE_DIR)
    # source directory specified, they'd better be there
    if(NOT EXISTS "${PYCXX_SOURCE_DIR}/cxxextensions.c")
        if(PyCXX_FIND_REQUIRED)
            MESSAGE(FATAL_ERROR
                "PyCXX: cxxextensions.c not found in PYCXX_SOURCE_DIR "
                "${PYCXX_SOURCE_DIR}")
        else(PyCXX_FIND_REQUIRED)
            MESSAGE(WARNING
                "PyCXX: cxxextensions.c not found in PYCXX_SOURCE_DIR "
                "${PYCXX_SOURCE_DIR}")
            unset(PYCXX_FOUND)
        endif(PyCXX_FIND_REQUIRED)
    endif(NOT EXISTS "${PYCXX_SOURCE_DIR}/cxxextensions.c")
else(PYCXX_SOURCE_DIR)
    # check in 'standard' places
    find_path(PYCXX_SOURCE_DIR cxxextensions.c
        "${PYCXX_INCLUDE_DIR}/CXX"
        "${PYCXX_INCLUDE_DIR}/Src"
        "${PYTHON_INCLUDE_DIR}/CXX"
        "${PYTHON_INCLUDE_DIR}/Src"
        "${CMAKE_CURRENT_LIST_DIR}/../Src"
        "${CMAKE_CURRENT_LIST_DIR}/../CXX")
    if(NOT PYCXX_SOURCE_DIR)
        if(PyCXX_FIND_REQUIRED)
            MESSAGE(FATAL_ERROR
                "PyCXX not found; please set PYCXX_SOURCE_DIR to "
                "the location of cxxextensions.c")
        else(PyCXX_FIND_REQUIRED)
            MESSAGE(STATUS "PyCXX not found")
            unset(PYCXX_FOUND)
        endif(PyCXX_FIND_REQUIRED)
    endif(NOT PYCXX_SOURCE_DIR)
endif(PYCXX_SOURCE_DIR)

# Find PyCXX Version
if(PYCXX_INCLUDE_DIR AND PYCXX_SOURCE_DIR)
    file(READ ${PYCXX_INCLUDE_DIR}/CXX/Version.hxx PYCXX_VERSION_H)
    foreach(item IN ITEMS MAJOR MINOR PATCH)
        string(REGEX REPLACE
            ".*#define[ \t]+PYCXX_VERSION_${item}[ \t]+([0-9]+).*"
            "\\1" PYCXX_VERSION_${item}
            "${PYCXX_VERSION_H}"
        )
    endforeach()
    set(PYCXX_VERSION ${PYCXX_VERSION_MAJOR}.${PYCXX_VERSION_MINOR}.${PYCXX_VERSION_PATCH})
endif()

# see what we've got
if(PYCXX_FOUND)
    MESSAGE(STATUS "PyCXX found:")
    MESSAGE(STATUS "  Headers:  ${PYCXX_INCLUDE_DIR}")
    MESSAGE(STATUS "  Sources:  ${PYCXX_SOURCE_DIR}")
    MESSAGE(STATUS "  Version:  ${PYCXX_VERSION}")

    # Build the list of sources for convenience
    set(PYCXX_SOURCES
        ${PYCXX_SOURCE_DIR}/cxxextensions.c
        ${PYCXX_SOURCE_DIR}/cxx_extensions.cxx
        ${PYCXX_SOURCE_DIR}/cxxsupport.cxx
        ${PYCXX_SOURCE_DIR}/IndirectPythonInterface.cxx
    )

    #set old 6.2 pycxx compatibility  
    list(APPEND PYCXX_SOURCES ${PYCXX_SOURCE_DIR}/cxx_exceptions.cxx)
    add_definitions(-DPYCXX_6_2_COMPATIBILITY)
    #end old compatibility
else(PYCXX_FOUND)
    MESSAGE(STATUS "PyCXX not found")
endif(PYCXX_FOUND)