Skip to content

Commit

Permalink
Bindings : **NB** Add Cmake flags to turn on bindings (Default=off)
Browse files Browse the repository at this point in the history
Many distributions have patches to change the CMake to turn off bindings
This internalize that to the upstream package in a sustainable manner.

This takes existing "PYTHON_BINDINGS", "CSHARP_BINDINGS" and
"MATLAB_BINDINGS" cmake flags and moves them to the top level cmake,
where they are defaulted off, and most distribution maintainers want.

This changes the default behavior, from build with all bindings found,
to only build bindings that are turned on via cmake.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Jan 21, 2020
1 parent 0a48e71 commit f1faa28
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 78 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ endif()
#set(SETUP_PY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/setup.py)
#configure_file(python/setup.py.in ${SETUP_PY} @ONLY)

option(CSHARP_BINDINGS "Install C# bindings" OFF)
option(PYTHON_BINDINGS "Install Python bindings" OFF)
option(MATLAB_BINDINGS "Build MATLAB bindings" OFF)
add_subdirectory(bindings)

if (WITH_MATLAB_BINDINGS_API)
Expand Down
14 changes: 11 additions & 3 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
add_subdirectory(csharp)
add_subdirectory(matlab)
add_subdirectory(python)
if (CSHARP_BINDINGS)
add_subdirectory(csharp)
endif()

if (MATLAB_BINDINGS)
add_subdirectory(matlab)
endif()

if (PYTHON_BINDINGS)
add_subdirectory(python)
endif()
95 changes: 47 additions & 48 deletions bindings/csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,61 @@ find_program(MCS_EXECUTABLE
mark_as_advanced(MCS_EXECUTABLE)

if (MCS_EXECUTABLE)
option(CSHARP_BINDINGS "Install C# bindings" ON)

if (CSHARP_BINDINGS)
set(LIBIIO_CS_PC_IN "${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp.pc.cmakein")
set(LIBIIO_CS_PC "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp-${VERSION}.pc")
configure_file(${LIBIIO_CS_PC_IN} ${LIBIIO_CS_PC} @ONLY)
if(NOT SKIP_INSTALL_ALL)
install(FILES ${LIBIIO_CS_PC} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
endif()
message(STATUS "Found C#: Building bindings")
set(LIBIIO_CS_PC_IN "${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp.pc.cmakein")
set(LIBIIO_CS_PC "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp-${VERSION}.pc")
configure_file(${LIBIIO_CS_PC_IN} ${LIBIIO_CS_PC} @ONLY)
if(NOT SKIP_INSTALL_ALL)
install(FILES ${LIBIIO_CS_PC} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
endif()

set(LIBIIO_CS_DLL_CONFIG_IN "${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp.dll.config.cmakein")
set(LIBIIO_CS_DLL_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.dll.config")
configure_file(${LIBIIO_CS_DLL_CONFIG_IN} ${LIBIIO_CS_DLL_CONFIG} @ONLY)
if(NOT SKIP_INSTALL_ALL)
install(FILES ${LIBIIO_CS_DLL_CONFIG} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cli/libiio-sharp-${VERSION})
endif()
set(LIBIIO_CS_DLL_CONFIG_IN "${CMAKE_CURRENT_SOURCE_DIR}/libiio-sharp.dll.config.cmakein")
set(LIBIIO_CS_DLL_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.dll.config")
configure_file(${LIBIIO_CS_DLL_CONFIG_IN} ${LIBIIO_CS_DLL_CONFIG} @ONLY)
if(NOT SKIP_INSTALL_ALL)
install(FILES ${LIBIIO_CS_DLL_CONFIG} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cli/libiio-sharp-${VERSION})
endif()

set(LIBIIO_CS_VERSION ${VERSION}.0.0)
set(LIBIIO_CS_INFO_IN ${CMAKE_CURRENT_SOURCE_DIR}/AssemblyInfo.cs.in)
set(LIBIIO_CS_INFO ${CMAKE_CURRENT_BINARY_DIR}/AssemblyInfo.cs)
configure_file(${LIBIIO_CS_INFO_IN} ${LIBIIO_CS_INFO} @ONLY)
set(LIBIIO_CS_VERSION ${VERSION}.0.0)
set(LIBIIO_CS_INFO_IN ${CMAKE_CURRENT_SOURCE_DIR}/AssemblyInfo.cs.in)
set(LIBIIO_CS_INFO ${CMAKE_CURRENT_BINARY_DIR}/AssemblyInfo.cs)
configure_file(${LIBIIO_CS_INFO_IN} ${LIBIIO_CS_INFO} @ONLY)

set(LIBIIO_CS_DLL "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.dll")
set(LIBIIO_CS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/Attr.cs
${CMAKE_CURRENT_SOURCE_DIR}/Channel.cs
${CMAKE_CURRENT_SOURCE_DIR}/Context.cs
${CMAKE_CURRENT_SOURCE_DIR}/Device.cs
${CMAKE_CURRENT_SOURCE_DIR}/IOBuffer.cs
${CMAKE_CURRENT_SOURCE_DIR}/Trigger.cs
${LIBIIO_CS_INFO}
)
set(LIBIIO_CS_DLL "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.dll")
set(LIBIIO_CS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/Attr.cs
${CMAKE_CURRENT_SOURCE_DIR}/Channel.cs
${CMAKE_CURRENT_SOURCE_DIR}/Context.cs
${CMAKE_CURRENT_SOURCE_DIR}/Device.cs
${CMAKE_CURRENT_SOURCE_DIR}/IOBuffer.cs
${CMAKE_CURRENT_SOURCE_DIR}/Trigger.cs
${LIBIIO_CS_INFO}
)

foreach(SRC ${LIBIIO_CS_SOURCES})
file(TO_NATIVE_PATH ${SRC} TMP)
set(LIBIIO_CS_SOURCES_REALPATH ${LIBIIO_CS_SOURCES_REALPATH} ${TMP})
endforeach(SRC)
foreach(SRC ${LIBIIO_CS_SOURCES})
file(TO_NATIVE_PATH ${SRC} TMP)
set(LIBIIO_CS_SOURCES_REALPATH ${LIBIIO_CS_SOURCES_REALPATH} ${TMP})
endforeach(SRC)

file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/key.snk SIGN_KEY)
file(TO_NATIVE_PATH ${LIBIIO_CS_DLL} LIBIIO_CS_DLL_OUT)
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/key.snk SIGN_KEY)
file(TO_NATIVE_PATH ${LIBIIO_CS_DLL} LIBIIO_CS_DLL_OUT)

add_custom_command(OUTPUT ${LIBIIO_CS_DLL}
COMMAND ${MCS_EXECUTABLE} /target:library /out:${LIBIIO_CS_DLL_OUT} /debug /keyfile:${SIGN_KEY} ${LIBIIO_CS_SOURCES_REALPATH}
DEPENDS ${LIBIIO_CS_SOURCES}
)
add_custom_command(OUTPUT ${LIBIIO_CS_DLL}
COMMAND ${MCS_EXECUTABLE} /target:library /out:${LIBIIO_CS_DLL_OUT} /debug /keyfile:${SIGN_KEY} ${LIBIIO_CS_SOURCES_REALPATH}
DEPENDS ${LIBIIO_CS_SOURCES}
)

add_custom_target(libiio-sharp ALL DEPENDS ${LIBIIO_CS_DLL})
add_custom_target(libiio-sharp ALL DEPENDS ${LIBIIO_CS_DLL})

if(NOT SKIP_INSTALL_ALL)
set(DEBUG_SYMBOLS_FILE "")
if(EXISTS "${LIBIIO_CS_DLL}.mdb")
set(DEBUG_SYMBOLS_FILE "${LIBIIO_CS_DLL}.mdb")
elseif(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.pdb")
set(DEBUG_SYMBOLS_FILE "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.pdb")
endif()
install(FILES ${LIBIIO_CS_DLL} ${DEBUG_SYMBOLS_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cli/libiio-sharp-${VERSION})
if(NOT SKIP_INSTALL_ALL)
set(DEBUG_SYMBOLS_FILE "")
if(EXISTS "${LIBIIO_CS_DLL}.mdb")
set(DEBUG_SYMBOLS_FILE "${LIBIIO_CS_DLL}.mdb")
elseif(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.pdb")
set(DEBUG_SYMBOLS_FILE "${CMAKE_CURRENT_BINARY_DIR}/libiio-sharp.pdb")
endif()
install(FILES ${LIBIIO_CS_DLL} ${DEBUG_SYMBOLS_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cli/libiio-sharp-${VERSION})
endif()
else()
message(FATAL_ERROR "C# compiler search failed : Can not build C# bindings")
endif()
29 changes: 14 additions & 15 deletions bindings/matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ mark_as_advanced(MATLAB_EXECUTABLE)
option(WITH_MATLAB_BINDINGS_API "Enable MATLAB bindings API" ON)

if (MATLAB_EXECUTABLE AND NOT SKIP_INSTALL_ALL)
option(MATLAB_BINDINGS "Install MATLAB bindings" ON)

if (MATLAB_BINDINGS)
install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/libiio"
PATTERN "CMakeLists.txt" EXCLUDE
)
install(
CODE "execute_process(
COMMAND ${MATLAB_EXECUTABLE} -nodesktop
-nodisplay -r \"cd('${CMAKE_INSTALL_PREFIX}/share/libiio/matlab');iio_installer_script;exit;\"
OUTPUT_QUIET)")
set(WITH_MATLAB_BINDINGS_API ON CACHE BOOL "" FORCE)
endif()
message(STATUS "Found MATLAB: Building bindings")
install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/libiio"
PATTERN "CMakeLists.txt" EXCLUDE
)
install(
CODE "execute_process(
COMMAND ${MATLAB_EXECUTABLE} -nodesktop
-nodisplay -r \"cd('${CMAKE_INSTALL_PREFIX}/share/libiio/matlab');iio_installer_script;exit;\"
OUTPUT_QUIET)")
set(WITH_MATLAB_BINDINGS_API ON CACHE BOOL "" FORCE)
else()
message(FATAL_ERROR "MATLAB search failed : Can not build bindings")
endif()
22 changes: 10 additions & 12 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ else()
endif()

if (Python_Interpreter_FOUND)
option(PYTHON_BINDINGS "Install Python bindings" ON)
message(STATUS "Found Python: Building bindings")
set(SETUP_PY_IN ${CMAKE_CURRENT_SOURCE_DIR}/setup.py.cmakein)
set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py)

if (PYTHON_BINDINGS)
configure_file(${SETUP_PY_IN} ${SETUP_PY})

set(SETUP_PY_IN ${CMAKE_CURRENT_SOURCE_DIR}/setup.py.cmakein)
set(SETUP_PY ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/iio.py ${CMAKE_CURRENT_BINARY_DIR}/iio.py COPYONLY)

configure_file(${SETUP_PY_IN} ${SETUP_PY})
add_custom_target(libiio-py ALL DEPENDS ${SETUP_PY} COMMAND ${Python_EXECUTABLE} ${SETUP_PY} --quiet build)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/iio.py ${CMAKE_CURRENT_BINARY_DIR}/iio.py COPYONLY)

add_custom_target(libiio-py ALL DEPENDS ${SETUP_PY} COMMAND ${Python_EXECUTABLE} ${SETUP_PY} --quiet build)

if(NOT SKIP_INSTALL_ALL)
install(CODE "execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${Python_EXECUTABLE} ${SETUP_PY} install --root=\$ENV{DESTDIR}/ --prefix=${CMAKE_INSTALL_PREFIX})")
endif()
if(NOT SKIP_INSTALL_ALL)
install(CODE "execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${Python_EXECUTABLE} ${SETUP_PY} install --root=\$ENV{DESTDIR}/ --prefix=${CMAKE_INSTALL_PREFIX})")
endif()
else()
message(FATAL_ERROR "Python search failed : Can not build Python bindings")
endif()

0 comments on commit f1faa28

Please sign in to comment.