Commit 23b2f4b4 authored by Laurent Claustre's avatar Laurent Claustre

Merge branch 'cmake_fix_sip' into cmake

parents 3be37f37 740574c2
Pipeline #2277 passed with stages
in 1 minute and 1 second
......@@ -263,13 +263,6 @@ if(LIMA_ENABLE_SPS_IMAGE)
set(ct_srcs ${ct_srcs} control/src/CtSpsImage.cpp third-party/Sps/Src/sps.c)
endif()
#--------------------------------------------------------------------------------
# Option for openGL real-time display support
#--------------------------------------------------------------------------------
if(LIMA_ENABLE_GLDISPLAY)
add_subdirectory(third-party/gldisplay)
endif()
#--------------------------------------------------------------------------------
# Option for extra saving formats edf.gz, edf.lz4, cbf, hdf5, tiff, fits ...
#--------------------------------------------------------------------------------
......@@ -514,7 +507,6 @@ if(LIMA_ENABLE_PYTHON)
configure_file(sip/core/limacore.sip.in sip/core/limacore.sip)
configure_file(hardware/sip/HwFrameInfo.sip_after_4_12 sip/core/HwFrameInfo.sip)
endif()
set(SIP_CONCAT_PARTS 1)
set(SIP_INCLUDES ${SIP_INCLUDES}
"${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/sip"
"${CMAKE_CURRENT_SOURCE_DIR}/third-party/Processlib/tasks/sip"
......@@ -543,6 +535,13 @@ if(LIMA_ENABLE_PYTHON)
install(FILES common/python/__init__.py common/python/Debug.py DESTINATION "${PYTHON_SITE_PACKAGES_DIR}/Lima/Core")
endif()
#--------------------------------------------------------------------------------
# Option for openGL real-time display support
#--------------------------------------------------------------------------------
if(LIMA_ENABLE_GLDISPLAY)
add_subdirectory(third-party/gldisplay)
endif()
#--------------------------------------------------------------------------------
#TESTS, run ctest or make test
#--------------------------------------------------------------------------------
......
......@@ -37,7 +37,6 @@
set(SIP_INCLUDES)
set(SIP_TAGS)
set(SIP_CONCAT_PARTS 8)
set(SIP_DISABLE_FEATURES)
set(SIP_EXTRA_OPTIONS)
......@@ -78,12 +77,48 @@ macro(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
endforeach (_x ${SIP_DISABLE_FEATURES})
set(_message "-DMESSAGE=Generating CPP code for module ${MODULE_NAME}")
# if(WIN32)
# set(COPY_COMMAND copy)
# else()
# set(COPY_COMMAND cp)
# endif()
set(_module_sbf ${_module_path}/${MODULE_NAME}.sbf)
execute_process(
COMMAND ${SIP_EXECUTABLE} ${_sip_tags} ${_sip_x} ${SIP_EXTRA_OPTIONS}
${_sip_includes} -b ${_module_sbf}
${_abs_module_sip}
)
set(_lima_init_numpy_cpp)
if(NOT (${MODULE_NAME} STREQUAL "processlib"))
set(_lima_init_numpy "lima_init_numpy.cpp")
set(_lima_init_numpy_cpp ${_module_path}/${_lima_init_numpy})
# add_custom_command(
# OUTPUT ${_lima_init_numpy_cpp}
# COMMAND ${COPY_COMMAND} ${CMAKE_SOURCE_DIR}/sip/${_lima_init_numpy}
# ${_module_path}
# DEPENDS ${CMAKE_SOURCE_DIR}/sip/${_lima_init_numpy}
# )
configure_file(${CMAKE_SOURCE_DIR}/sip/${_lima_init_numpy}
${_module_path}
COPYONLY
)
endif()
set(_sip_output_files_list)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/cmake/readsipsbf.py
${_module_sbf} ${_module_path}
OUTPUT_VARIABLE _sip_output_files_list
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(_sip_output_files)
foreach(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS} )
if( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS} )
set(_sip_output_files ${_sip_output_files} ${_module_path}/sip${_child_module_name}part${CONCAT_NUM}.cpp )
endif( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS} )
endforeach(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS} )
foreach(filename IN LISTS _sip_output_files_list)
set(_sip_output_files ${_sip_output_files} ${filename})
endforeach(filename)
if(NOT WIN32)
set(TOUCH_COMMAND touch)
......@@ -95,29 +130,39 @@ macro(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
file(APPEND filename "")
endforeach(filename ${_sip_output_files})
endif(NOT WIN32)
# TODO: add all SIP files with the %Include directive + Exceptions.sip
add_custom_command(
OUTPUT ${_sip_output_files}
COMMAND ${CMAKE_COMMAND} -E echo ${message}
COMMAND ${TOUCH_COMMAND} ${_sip_output_files}
COMMAND ${SIP_EXECUTABLE} ${_sip_tags} ${_sip_x} ${SIP_EXTRA_OPTIONS} -b ${MODULE_NAME}.sbf -c ${_module_path} ${_sip_includes} ${_abs_module_sip}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/cmake/checksipexc.py ${_sip_output_files}
COMMAND ${SIP_EXECUTABLE} ${_sip_tags} ${_sip_x} ${SIP_EXTRA_OPTIONS}
${_sip_includes} -c ${_module_path}
${_abs_module_sip}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/cmake/checksipexc.py
${_sip_output_files}
DEPENDS ${_abs_module_sip} ${SIP_EXTRA_FILES_DEPEND}
)
# not sure if type MODULE could be uses anywhere, limit to cygwin for now
set(_sip_all_files ${_lima_init_numpy_cpp} ${_sip_output_files})
if (CYGWIN)
add_library(${_logical_name} MODULE ${_sip_output_files} )
add_library(${_logical_name} MODULE ${_sip_all_files} )
else (CYGWIN)
add_library(${_logical_name} SHARED ${_sip_output_files} )
add_library(${_logical_name} SHARED ${_sip_all_files} )
endif (CYGWIN)
target_link_libraries(${_logical_name} ${PYTHON_LIBRARY})
target_link_libraries(${_logical_name} ${EXTRA_LINK_LIBRARIES})
set_target_properties(${_logical_name} PROPERTIES PREFIX "" OUTPUT_NAME ${_child_module_name})
set_target_properties(${_logical_name} PROPERTIES
PREFIX "" OUTPUT_NAME ${_child_module_name}
LINKER_LANGUAGE CXX)
if (WIN32)
set_target_properties(${_logical_name} PROPERTIES SUFFIX ".pyd")
set_target_properties(${_logical_name} PROPERTIES IMPORT_SUFFIX ".dll")
endif (WIN32)
install(TARGETS ${_logical_name} DESTINATION "${PYTHON_SITE_PACKAGES_DIR}/${_parent_module_path}")
install(TARGETS ${_logical_name}
DESTINATION "${PYTHON_SITE_PACKAGES_DIR}/${_parent_module_path}")
endmacro(ADD_SIP_PYTHON_MODULE)
......@@ -27,8 +27,33 @@ import shutil
logger = logging.getLogger(__file__)
raise_linenr = None
raise_exc = []
def checksipexc(ifname, inplace=False):
global raise_linenr, raise_exc
lfname = ifname
sip_fname = '../../../common/sip/Exceptions.sip'
if lfname.startswith('/'):
sip_fname = os.path.realpath(sip_fname)
else:
lfname = os.path.join(os.curdir, lfname)
if not raise_exc:
bfile = open(sip_fname)
in_raise_code = False
for i, l in enumerate(bfile.readlines()):
l = l.strip()
if l == '%RaiseCode':
in_raise_code = True
raise_linenr = i + 2
elif l == '%End':
in_raise_code = False
elif in_raise_code:
raise_exc.append(l)
bfile.close()
ifile = open(ifname, "rt")
if inplace:
......@@ -44,17 +69,16 @@ def checksipexc(ifname, inplace=False):
state = Out
block = 0
linenr = 0
olinenr = 1
modified = False
ellipsis = '...'
exc_def = 'Exception &sipExceptionRef'
raise_unknown = 'sipRaiseUnknownException();'
raise_exc = ['const char *detail = sipExceptionRef.getErrMsg().c_str();',
'PyErr_SetString(sipException_Exception, detail);']
for line in ifile.readlines():
linenr += 1
new_state = state
l = line.strip()
......@@ -77,6 +101,7 @@ def checksipexc(ifname, inplace=False):
if InDefHandler not in [state, new_state] or had_exc_handler:
ofile.write(line.encode())
olinenr += line.count('\n')
else:
def_handler_code.append(line)
if new_state == Out:
......@@ -88,10 +113,15 @@ def checksipexc(ifname, inplace=False):
tok = handler_line.split(raise_unknown)
sep = '\n' + tok[0]
exc_line = sep.join(raise_exc)
handler_line = exc_line.join(tok)
sip_head = '#line %d "%s"\n' % (raise_linenr, sip_fname)
new_olinenr = olinenr + len(raise_exc) + 2
sip_tail = '#line %d "%s"\n\n' % (new_olinenr, lfname)
handler_line = sip_head + exc_line.join(tok) + sip_tail
ofile.write(handler_line.encode())
olinenr += handler_line.count('\n')
for handler_line in def_handler_code:
ofile.write(handler_line.encode())
olinenr += handler_line.count('\n')
modified = True
if new_state != state:
......
from __future__ import print_function
import sys, os
sbf_fname = sys.argv[1]
out_dir = sys.argv[2]
src_prefix = 'sources = '
for l in open(sbf_fname):
if l.startswith(src_prefix):
l = l[len(src_prefix):]
files = l.split()
s = ';'.join(map(lambda x: '%s/%s' % (out_dir, x), files))
print(s)
\ No newline at end of file
......@@ -251,7 +251,7 @@ public:
return *this;
}
AutoPtr& operator =(AutoPtr& o)
AutoPtr& operator =(const AutoPtr& o)
{
AutoPtrData *od = o.getData(); // protects against "a = a"
putData();
......
......@@ -37,7 +37,7 @@ using namespace lima;
%End
%RaiseCode
const std::string& tmpString = sipExceptionRef.getErrMsg();
const char *detail = tmpString.c_str();
const char *detail = tmpString.c_str();
PyErr_SetString(sipException_Exception, detail);
%End
};
......
......@@ -99,7 +99,7 @@ def config_cmake_options(options):
def install_lima_linux():
os.chdir(os.getcwd()+"/build")
global install_path, install_python_path, find_root_path
global install_path, install_python_path, find_root_path
try:
if install_path != "": install_path = " -DCMAKE_INSTALL_PREFIX="+str(install_path)
if install_python_path != "": install_python_path = " -DPYTHON_SITE_PACKAGES_DIR="+str(install_python_path)
......@@ -114,7 +114,7 @@ def install_lima_linux():
install_check = os.system("make install")
if str(install_check)!="0":
raise Exception("CMake couldn't install libraries. Make sure you have necessaries rights.")
except Exception as inst:
except Exception as inst:
if str(cmake_check)!="0":
sys.exit("Problem in CMake configuration")
elif str(compilation_check)!="0":
......@@ -123,7 +123,7 @@ def install_lima_linux():
sys.exit("Problem in CMake installation")
def install_lima_windows():
global install_path, install_python_path, find_root_path
global install_path, install_python_path, find_root_path
# for windows check compat between installed python and mandatory vc++ compiler
# See, https://wiki.python.org/moin/WindowsCompilers
if sys.version_info < (2, 6):
......@@ -145,11 +145,11 @@ def install_lima_windows():
os.chdir(os.getcwd()+"/build")
try :
if install_path != "": install_path = " -DCMAKE_INSTALL_PREFIX="+str(install_path)
if install_python_path != "": install_python_path = " -DPYTHON_SITE_PACKAGES_DIR="+str(install_python_path)
if find_root_path != "": find_root_path = " -DCMAKE_FIND_ROOT_PATH="+str(find_root_path)
if install_path != "": install_path = " -DCMAKE_INSTALL_PREFIX="+str(install_path)
if install_python_path != "": install_python_path = " -DPYTHON_SITE_PACKAGES_DIR="+str(install_python_path)
if find_root_path != "": find_root_path = " -DCMAKE_FIND_ROOT_PATH="+str(find_root_path)
cmake_check = os.system(cmake_cmd+source_path+" "+cmake_config++install_path+install_python_path+find_root_path)
cmake_check = os.system(cmake_cmd+source_path+" "+cmake_config+install_path+install_python_path+find_root_path)
if str(cmake_check)!="0":
raise Exception("Something went wrong in the CMake preparation. Make sure your configuration is good.")
......@@ -189,7 +189,7 @@ if __name__ == '__main__':
if "--install-python-prefix=" in option:
install_python_path=option[24:]
if "--find-root-path=" in option:
print (option)
print (option)
find_root_path=option[17:]
if OS_TYPE=="Linux":
install_lima_linux()
......
......@@ -516,11 +516,29 @@ return aReturnListPt;
%End
};
%ModuleHeaderCode
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/numpyconfig.h"
#if (defined(NPY_API_VERSION) && NPY_API_VERSION >= 0x00000004 && PY_VERSION_HEX >= 0x03000000)
#include "numpy/npy_3kcompat.h"
#endif
%End
%UnitCode
#include <lima_init_numpy.cpp>
#include <lima_repr_attr.cpp>
%End
%ModuleCode
extern "C"
{
#if PY_VERSION_HEX >= 0x03000000
int lima_import_array();
#else
void lima_import_array();
#endif
}
%End
%PostInitialisationCode
lima_import_array();
%End
......
%Module(name=lima@NAME@,version=0)
%ModuleHeaderCode
%ModuleCode
extern "C" {
#if PY_VERSION_HEX >= 0x03000000
int lima_import_array();
......@@ -11,8 +11,15 @@ void lima_import_array();
}
%End
%ModuleHeaderCode
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/numpyconfig.h"
#if (defined(NPY_API_VERSION) && NPY_API_VERSION >= 0x00000004 && PY_VERSION_HEX >= 0x03000000)
#include "numpy/npy_3kcompat.h"
#endif
%End
%UnitCode
#include <lima_init_numpy.cpp>
#include <lima_repr_attr.cpp>
%End
......
Subproject commit 3d04cfd8aafb61f6198c79754ad6ce68d844c450
Subproject commit 7e55804aefa2c3065af42e1a987b0ee302e19b44
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment