|
| 1 | +# Copyright 2021 The casbin Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +set(SOURCES |
| 16 | + main.cpp |
| 17 | +) |
| 18 | + |
| 19 | +add_library(pycasbin MODULE ${SOURCES}) |
| 20 | + |
| 21 | +set_target_properties(pycasbin PROPERTIES |
| 22 | + PREFIX "" |
| 23 | +) |
| 24 | + |
| 25 | +if(WIN32) |
| 26 | + # Windows uses .pyd extension for python modules |
| 27 | + set_target_properties(pycasbin PROPERTIES |
| 28 | + SUFFIX ".pyd" |
| 29 | + ) |
| 30 | +endif() |
| 31 | + |
| 32 | + |
| 33 | +# NOTE: Depending of the compiler version pybind11 2.4.3 does not compile with C++17 so revert to c++11 |
| 34 | + |
| 35 | +if(UNIX) |
| 36 | + # A 'module' is a dynamic library on Linux (i.e. '-fPIC' needed), |
| 37 | + # but a static library on Windows. |
| 38 | + |
| 39 | + # If supported for the target machine, emit position-independent code |
| 40 | + # suitable for dynamic linking. |
| 41 | + set_property(TARGET pycasbin PROPERTY POSITION_INDEPENDENT_CODE ON) |
| 42 | +endif() |
| 43 | + |
| 44 | +# macOS demands that the linker resolve all symbols at build time |
| 45 | +# Pass this flag to allow dynamic linking |
| 46 | +if(APPLE) |
| 47 | + set_target_properties(pycasbin PROPERTIES |
| 48 | + LINK_FLAGS "-undefined dynamic_lookup" |
| 49 | + ) |
| 50 | +endif() |
| 51 | + |
| 52 | +target_link_libraries(pycasbin |
| 53 | + PRIVATE |
| 54 | + # casbin |
| 55 | + pybind11::module |
| 56 | +) |
| 57 | + |
0 commit comments