Skip to content

Commit

Permalink
Add CMake for Python layer
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanMeans committed Feb 28, 2020
1 parent 735dd2f commit c49b41c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
9 changes: 9 additions & 0 deletions modules/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(TARGET_LANG "python")

find_package(SWIG)

if(SWIG_FOUND AND Python_FOUND)
add_subdirectory("nitf")
else()
message(WARNING "Unable to build python layer")
endif()
31 changes: 31 additions & 0 deletions modules/python/nitf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_policy(SET CMP0078 NEW)
cmake_policy(SET CMP0086 NEW)
include(UseSWIG)
if (Python_FOUND)
set_property(SOURCE source/nitro.i PROPERTY INCLUDE_DIRECTORIES
# Include from binary dir for generated config sources
"${CMAKE_CURRENT_BINARY_DIR}/../../c/nrt/include"
"${CMAKE_CURRENT_BINARY_DIR}/../../c/nitf/include"

# And then manually add source includes for everything else we need
# TODO: Is there a better way to do this...?
"${NITRO_C_SOURCE_DIR}/nrt/include"
"${NITRO_C_SOURCE_DIR}/nitf/include")
set_property(SOURCE source/nitro.i PROPERTY CPLUSPLUS ON)
swig_add_library(nitropy TYPE SHARED
LANGUAGE python
OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source/generated
OUTFILE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source/generated
SOURCES source/nitro.i)

target_include_directories(nitropy PRIVATE ${Python_INCLUDE_DIRS} ${Python_NumPy_INCLUDE_DIRS}
${NITRO_C_SOURCE_DIR}/nrt/include
${NITRO_C_SOURCE_DIR}/nitf/include)
target_link_libraries(nitropy nitf numpyutils-c++ sys-c++ except-c++ io-c++ str-c++)
install(TARGETS nitropy DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/site-packages/)
install(FILES source/__init__.py source/generated/nitropy.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/site-packages/)
add_dependencies(nitropy coda-oss)
else()
message(FATAL_ERROR "Can't find PYTHON_HOME")
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#endif

#define SWIG_PYTHON_DIRECTOR_NO_VTABLE
#define SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS


#ifdef __cplusplus
Expand Down Expand Up @@ -3760,6 +3759,9 @@ SWIG_AsVal_bool (PyObject *obj, bool *val)
}


#define SWIG_From_double PyFloat_FromDouble


SWIGINTERN int
SWIG_AsVal_char (PyObject * obj, char *val)
{
Expand Down Expand Up @@ -34645,7 +34647,7 @@ SWIG_init(void) {

SWIG_InstallConstants(d,swig_const_table);

SWIG_Python_SetConstant(d, "NRT_FILE",SWIG_FromCharPtr("/data1/u/jmeans/nitro/modules/c/nrt/include/nrt/Defines.h"));
SWIG_Python_SetConstant(d, "NRT_FILE",SWIG_FromCharPtr("/home/jmeans/oss/nitro/modules/c/nrt/include/nrt/Defines.h"));
SWIG_Python_SetConstant(d, "NRT_LINE",SWIG_From_int(static_cast< int >(95)));
SWIG_Python_SetConstant(d, "NRT_FUNC",SWIG_FromCharPtr("unknown function"));
SWIG_Python_SetConstant(d, "NRT_DEFAULT_PERM",SWIG_From_int(static_cast< int >(0644)));
Expand Down Expand Up @@ -34686,7 +34688,7 @@ SWIG_init(void) {
SWIG_Python_SetConstant(d, "NRT_ERR_INT_STACK_OVERFLOW",SWIG_From_int(static_cast< int >(NRT_ERR_INT_STACK_OVERFLOW)));
SWIG_Python_SetConstant(d, "NRT_ERR_UNK",SWIG_From_int(static_cast< int >(NRT_ERR_UNK)));
SWIG_Python_SetConstant(d, "NRT_MAX_READ_ATTEMPTS",SWIG_From_int(static_cast< int >(100)));
SWIG_Python_SetConstant(d, "NITF_FILE",SWIG_FromCharPtr("/data1/u/jmeans/nitro/modules/c/nitf/include/nitf/System.h"));
SWIG_Python_SetConstant(d, "NITF_FILE",SWIG_FromCharPtr("/home/jmeans/oss/nitro/modules/c/nitf/include/nitf/System.h"));
SWIG_Python_SetConstant(d, "NITF_LINE",SWIG_From_int(static_cast< int >(58)));
SWIG_Python_SetConstant(d, "NITF_FUNC",SWIG_FromCharPtr("unknown function"));
SWIG_Python_SetConstant(d, "NITF_MAX_PATH",SWIG_From_int(static_cast< int >(1024)));
Expand All @@ -34700,9 +34702,7 @@ SWIG_init(void) {
SWIG_Python_SetConstant(d, "NITF_DATE_FORMAT_20",SWIG_FromCharPtr("%d%H%M%SZ%b%y"));
SWIG_Python_SetConstant(d, "NITF_DATE_FORMAT_21",SWIG_FromCharPtr("%Y%m%d%H%M%S"));
SWIG_Python_SetConstant(d, "NITF_TRE_HASH_SIZE",SWIG_From_int(static_cast< int >(8)));
SWIG_Python_SetConstant(d, "HAVE_CLOCK_GETTIME",SWIG_From_int(static_cast< int >(1)));
SWIG_Python_SetConstant(d, "HAVE_SYS_TIME_H",SWIG_From_int(static_cast< int >(1)));
SWIG_Python_SetConstant(d, "NRT_LIB_VERSION",SWIG_FromCharPtr("2.8"));
SWIG_Python_SetConstant(d, "NRT_LIB_VERSION",SWIG_From_double(static_cast< double >(2.8)));
SWIG_Python_SetConstant(d, "NITF_LIB_VERSION",SWIG_FromCharPtr("2.8"));
SWIG_Python_SetConstant(d, "NITF_COMPRESSION_HASH_SIZE",SWIG_From_int(static_cast< int >(2)));
SWIG_Python_SetConstant(d, "NITF_DECOMPRESSION_HASH_SIZE",SWIG_From_int(static_cast< int >(2)));
Expand Down
2 changes: 0 additions & 2 deletions modules/python/nitf/source/generated/nitropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,6 @@ def nrt_BufferAdapter_construct(buf, size, ownBuf, error):
NITF_DATE_FORMAT_20 = _nitropy.NITF_DATE_FORMAT_20
NITF_DATE_FORMAT_21 = _nitropy.NITF_DATE_FORMAT_21
NITF_TRE_HASH_SIZE = _nitropy.NITF_TRE_HASH_SIZE
HAVE_CLOCK_GETTIME = _nitropy.HAVE_CLOCK_GETTIME
HAVE_SYS_TIME_H = _nitropy.HAVE_SYS_TIME_H
NRT_LIB_VERSION = _nitropy.NRT_LIB_VERSION
NITF_LIB_VERSION = _nitropy.NITF_LIB_VERSION
NITF_COMPRESSION_HASH_SIZE = _nitropy.NITF_COMPRESSION_HASH_SIZE
Expand Down

0 comments on commit c49b41c

Please sign in to comment.