Yet another attempt to use CMake

This commit is contained in:
Alexey Sokolov
2015-12-14 00:16:44 +00:00
parent 04ad80b86e
commit 561a18054c
51 changed files with 2204 additions and 77 deletions

View File

@@ -0,0 +1,97 @@
#
# Copyright (C) 2004-2016 ZNC, see the NOTICE file for details.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set(modinclude_modpython PUBLIC ${PYTHON_INCLUDE_DIRS}
"${CMAKE_CURRENT_BINARY_DIR}/.." PARENT_SCOPE)
set(modlink_modpython PUBLIC ${PYTHON_LIBRARIES} PARENT_SCOPE)
set(moddef_modpython PUBLIC "SWIG_TYPE_TABLE=znc" PARENT_SCOPE)
set(moddepend_modpython modpython_functions modpython_swigruntime PARENT_SCOPE)
if(APPLE)
set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS
"${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
endif()
if(SWIG_FOUND)
add_custom_command(
OUTPUT "pyfunctions.cpp"
COMMAND "${PERL_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/codegen.pl"
"${CMAKE_CURRENT_SOURCE_DIR}/functions.in"
"pyfunctions.cpp")
add_custom_command(
OUTPUT "swigpyrun.h"
COMMAND "${SWIG_EXECUTABLE}" -python -py3 -c++ -shadow -external-runtime
"swigpyrun.h"
VERBATIM)
add_custom_command(
OUTPUT "modpython_biglib.cpp" "znc_core.py"
COMMAND "${SWIG_EXECUTABLE}" -python -py3 -c++ -shadow
"-I${PROJECT_BINARY_DIR}/include"
"-I${PROJECT_SOURCE_DIR}/include"
"-I${CMAKE_CURRENT_SOURCE_DIR}/.."
-DZNC_EXPORT_LIB_EXPORT
-outdir "${CMAKE_CURRENT_BINARY_DIR}"
-o "${CMAKE_CURRENT_BINARY_DIR}/modpython_biglib.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/modpython.i"
DEPENDS "modpython.i"
VERBATIM)
else()
add_custom_command(
OUTPUT swigpyrun.h znc_core.py modpython_biglib.cpp pyfunctions.cpp
COMMAND "${CMAKE_COMMAND}" -E tar xz
"${CMAKE_CURRENT_SOURCE_DIR}/generated.tar.gz"
VERBATIM)
endif()
add_custom_target(modpython_functions DEPENDS "pyfunctions.cpp")
add_custom_target(modpython_swigruntime DEPENDS "swigpyrun.h")
znc_add_library(modpython_lib MODULE modpython_biglib.cpp)
target_include_directories(modpython_lib PRIVATE
"${PROJECT_BINARY_DIR}/include"
"${PROJECT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_BINARY_DIR}/.."
"${CMAKE_CURRENT_SOURCE_DIR}/.."
${PYTHON_INCLUDE_DIRS})
target_link_libraries(modpython_lib ${znc_link} ${PYTHON_LIBRARIES})
set_target_properties(modpython_lib PROPERTIES
PREFIX "_"
OUTPUT_NAME "znc_core"
NO_SONAME true)
target_compile_definitions(modpython_lib PRIVATE "SWIG_TYPE_TABLE=znc")
if(CYGWIN)
target_link_libraries(modpython_lib module_modpython)
endif()
install(TARGETS modpython_lib
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/znc/modpython")
install(FILES "znc.py" "${CMAKE_CURRENT_BINARY_DIR}/znc_core.py"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/znc/modpython")
function(add_python_module mod modpath)
install(FILES "${modpath}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/znc")
endfunction()
# This target is used to generate tarball which doesn't depend on SWIG.
add_custom_target(modpython_dist
COMMAND "${CMAKE_COMMAND}" -E tar cz
"${CMAKE_CURRENT_SOURCE_DIR}/generated.tar.gz"
"swigpyrun.h" "znc_core.py" "modpython_biglib.cpp" "pyfunctions.cpp"
DEPENDS swigpyrun.h znc_core.py modpython_biglib.cpp pyfunctions.cpp
VERBATIM)
add_dependencies(modpython_dist copy_csocket_h)

View File

@@ -17,18 +17,18 @@ endif
.SECONDARY:
all: modpython/_znc_core.cpp modpython/znc_core.py modpython/pyfunctions.cpp modpython/swigpyrun.h
all: modpython/modpython_biglib.cpp modpython/znc_core.py modpython/pyfunctions.cpp modpython/swigpyrun.h
modpython/swigpyrun.h:
@mkdir -p modpython
$(Q)$(SWIG) -python -py3 -c++ -shadow -external-runtime $@
modpython/_znc_core.cpp: modpython/modpython.i modpython/module.h modpython/cstring.i
modpython/modpython_biglib.cpp: modpython/modpython.i modpython/module.h modpython/cstring.i
$(E) Generating ZNC API for python...
@mkdir -p modpython .depend
$(Q)$(SWIG) -python -py3 -c++ -shadow -outdir modpython -I$(srcdir) -I$(srcdir)/../include -I../include -MD -MF .depend/modpython.swig.dep -w362,315,401 -o $@ $<
modpython/znc_core.py: modpython/_znc_core.cpp
modpython/znc_core.py: modpython/modpython_biglib.cpp
modpython/pyfunctions.cpp: modpython/codegen.pl modpython/functions.in
@mkdir -p modpython

View File

@@ -23,7 +23,7 @@ CLEAN += modpython/_znc_core.$(PYCEXT_EXT)
CLEAN += modpython/_znc_core.o modpython/compiler.o
ifneq "$(SWIG)" ""
# Only delete these files if we can regenerate them
CLEAN += modpython/_znc_core.cpp modpython/znc_core.py
CLEAN += modpython/modpython_biglib.cpp modpython/znc_core.py
CLEAN += modpython/swigpyrun.h modpython/pyfunctions.cpp
endif
ifneq "$(srcdir)" "."
@@ -44,7 +44,7 @@ all: modpython_all
endif
modpython_all: modpython/_znc_core.$(PYCEXT_EXT)
modpython/_znc_core.o: modpython/_znc_core.cpp Makefile
modpython/_znc_core.o: modpython/modpython_biglib.cpp Makefile
@mkdir -p modpython
@mkdir -p .depend
$(E) Building ZNC python bindings library...
@@ -56,6 +56,12 @@ modpython/_znc_core.$(PYCEXT_EXT): modpython/_znc_core.o Makefile modpython.so
ifneq "$(SWIG)" ""
include $(srcdir)/modpython/Makefile.gen
else
modpython/swigpyrun.h modpython/znc_core.py modpython/pyfunctions.cpp: modpython/modpython_biglib.cpp
modpython/modpython_biglib.cpp: modpython/generated.tar.gz
@mkdir -p modpython
$(E) Unpacking ZNC python bindings...
$(Q)tar -xf $^ -C modpython
endif
modpython.o: modpython/pyfunctions.cpp modpython/swigpyrun.h

View File

@@ -27,10 +27,7 @@ class String {
class CModPython;
#if HAVE_VISIBILITY
#pragma GCC visibility push(default)
#endif
class CPyModule : public CModule {
class ZNC_EXPORT_LIB_EXPORT CPyModule : public CModule {
PyObject* m_pyObj;
CModPython* m_pModPython;
VWebSubPages* _GetSubPages();
@@ -216,7 +213,7 @@ inline CPyModule* CreatePyModule(CUser* pUser, CIRCNetwork* pNetwork,
pModPython);
}
class CPyTimer : public CTimer {
class ZNC_EXPORT_LIB_EXPORT CPyTimer : public CTimer {
PyObject* m_pyObj;
CModPython* m_pModPython;
@@ -246,7 +243,7 @@ inline CPyTimer* CreatePyTimer(CPyModule* pModule, unsigned int uInterval,
pyObj);
}
class CPySocket : public CSocket {
class ZNC_EXPORT_LIB_EXPORT CPySocket : public CSocket {
PyObject* m_pyObj;
CModPython* m_pModPython;
@@ -332,7 +329,3 @@ class CModulesIter {
CModules* m_pModules;
CModules::const_iterator m_it;
};
#if HAVE_VISIBILITY
#pragma GCC visibility pop
#endif