[PATCH v2] build: Set specific compiler flags for SWIG target

  • From: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Thu, 21 Mar 2019 12:15:45 +0100

From: Dimitri Staessens <dimitri@ouroboros.rocks>

The compiler flags for the SWIG target were added to the global
CMAKE_C_FLAGS used for the entire project, so the entire project was
compiled using these flags. This sets the flags uniquely for the SWIG
target. The eth has a similar case for the c99 flag. There was a
lingering include in dev.h that was removed.

Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
---
 include/ouroboros/wrap/CMakeLists.txt | 23 ++++++++++++++---------
 src/ipcpd/eth/CMakeLists.txt          |  5 ++++-
 src/lib/CMakeLists.txt                |  1 -
 src/lib/dev.c                         |  2 --
 4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/include/ouroboros/wrap/CMakeLists.txt 
b/include/ouroboros/wrap/CMakeLists.txt
index 9a5e107..b11f89d 100644
--- a/include/ouroboros/wrap/CMakeLists.txt
+++ b/include/ouroboros/wrap/CMakeLists.txt
@@ -20,12 +20,6 @@ else ()
       message(STATUS "Python found: Python bindings will be built")
       include_directories(${PYTHON_INCLUDE_PATH})
 
-      # Python assumes C99 since Python 3.6
-      test_and_set_c_compiler_flag_global(-std=c99)
-      # SWIG generates code for varargs with an unused parameter
-      test_and_set_c_compiler_flag_global(-Wno-unused-parameter)
-      # SWIG generates code with unsafe strncpy()
-      test_and_set_c_compiler_flag_global(-Wno-stringop-truncation)
       # CMake > 3.8 deprecates swig_add_module
       if (${CMAKE_VERSION} VERSION_LESS 3.8.0)
         swig_add_module(ouroboros python ouroboros.i)
@@ -36,6 +30,12 @@ else ()
           TYPE MODULE)
       endif()
 
+      # Python assumes C99 since Python 3.6
+      # SWIG generates code for varargs with an unused parameter
+      # SWIG generates code with unsafe strncpy()
+      set_target_properties(ouroboros PROPERTIES
+        COMPILE_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wno-unused-parameter \
+          -Wno-stringop-truncation")
       swig_link_libraries(ouroboros ${PYTHON_LIBRARIES} ouroboros-common
         ouroboros-dev ouroboros-irm)
 
@@ -58,9 +58,14 @@ else ()
           ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH})
       endif ()
 
-      install(FILES
-        ${CMAKE_CURRENT_BINARY_DIR}/_${SWIG_MODULE_ouroboros_REAL_NAME}.so
-        DESTINATION ${PYTHON_MODULE_PATH})
+      if (${CMAKE_VERSION} VERSION_LESS "3.13")
+        install (
+          ${CMAKE_CURRENT_BINARY_DIR}/${SWIG_MODULE_${ouroboros}_REAL_NAME}.so
+          DESTINATION ${PYTHON_MODULE_PATH})
+      else ()
+          install (TARGETS ouroboros
+          DESTINATION ${PYTHON_MODULE_PATH})
+      endif ()
       install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ouroboros.py
         DESTINATION ${PYTHON_MODULE_PATH})
     endif ()
diff --git a/src/ipcpd/eth/CMakeLists.txt b/src/ipcpd/eth/CMakeLists.txt
index abffbb2..eb4e9d2 100644
--- a/src/ipcpd/eth/CMakeLists.txt
+++ b/src/ipcpd/eth/CMakeLists.txt
@@ -66,7 +66,6 @@ if (NOT HAVE_RAW_SOCKETS AND NOT HAVE_BPF AND 
NETMAP_C_INCLUDE_DIR)
     "Disable netmap support for ETH IPCPs")
   if (NOT DISABLE_NETMAP)
     message(STATUS "Netmap support for Ethernet IPCPs enabled")
-    test_and_set_c_compiler_flag_global(-std=c99)
     set(HAVE_NETMAP TRUE PARENT_SCOPE)
     set(HAVE_ETH TRUE)
   else ()
@@ -107,6 +106,10 @@ if (HAVE_ETH)
   endif ()
 
   if (HAVE_NETMAP AND NOT APPLE)
+    set_target_properties(ipcpd-eth-llc PROPERTIES
+        COMPILE_FLAGS "${CMAKE_C_FLAGS} -std=c99")
+    set_target_properties(ipcpd-eth-dix PROPERTIES
+        COMPILE_FLAGS "${CMAKE_C_FLAGS} -std=c99")
     target_include_directories(ipcpd-eth-llc PUBLIC
       ${NETMAP_C_INCLUDE_DIR})
     target_include_directories(ipcpd-eth-dix PUBLIC
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index c18860a..d5e80fc 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -234,7 +234,6 @@ target_link_libraries(ouroboros-common ${LIBRT_LIBRARIES}
   ${LIBGCRYPT_LIBRARIES} ${FUSE_LIBRARIES})
 
 target_link_libraries(ouroboros-dev ouroboros-common)
-
 target_link_libraries(ouroboros-irm ouroboros-common)
 
 install(TARGETS ouroboros-common LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 10b34e4..6d5676a 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -26,8 +26,6 @@
 #define _POSIX_C_SOURCE 200809L
 #endif
 
-#include <ouroboros/endian.h>
-
 #include "config.h"
 
 #include <ouroboros/hash.h>
-- 
2.21.0


Other related posts: