Dynamically create rules for available libext*.a libraries, clean up rules
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 27 May 2013 11:52:15 +0000 (13:52 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 27 May 2013 13:15:34 +0000 (15:15 +0200)
CMakeLists.txt

index 199819006aece63437d81be1c6da10c97ac14ef3..a6f12719c6c1c5d2c797f39cdf46333f8320186c 100644 (file)
@@ -3,27 +3,36 @@ cmake_minimum_required(VERSION 2.6)
 PROJECT(firewall3 C)
 ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
 
+SET(sed_match   "^[[:space:]]*__ipt_module(\\(.*\\)).*")
+SET(sed_replace "-Wl,--undefined=libxt_\\1_init -Wl,--undefined=libipt_\\1_init -Wl,--undefined=libip6t_\\1_init")
+
+EXECUTE_PROCESS(COMMAND sed -n -e "s/${sed_match}/${sed_replace}/; T n; H; :n; \${ x; s/^\\n//; s/\\n/ /gp }" ${CMAKE_SOURCE_DIR}/iptables.h
+                OUTPUT_VARIABLE ext_syms OUTPUT_STRIP_TRAILING_WHITESPACE)
+
 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--unresolved-symbols=ignore-all ${ext_syms}")
 
-IF(APPLE)
-  INCLUDE_DIRECTORIES(/opt/local/include)
-  LINK_DIRECTORIES(/opt/local/lib)
+IF (EXISTS "${CMAKE_SOURCE_DIR}/libext.a")
+  ADD_LIBRARY(ext STATIC IMPORTED)
+  SET_PROPERTY(TARGET ext PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libext.a)
+  LIST(APPEND ext_libs ext)
 ENDIF()
 
-ADD_LIBRARY(ext STATIC IMPORTED)
-SET_PROPERTY(TARGET ext PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libext.a)
-
-ADD_LIBRARY(ext4 STATIC IMPORTED)
-SET_PROPERTY(TARGET ext4 PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libext4.a")
+IF (EXISTS "${CMAKE_SOURCE_DIR}/libext4.a")
+  ADD_LIBRARY(ext4 STATIC IMPORTED)
+  SET_PROPERTY(TARGET ext4 PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libext4.a")
+  LIST(APPEND ext_libs ext4)
+ENDIF()
 
-ADD_LIBRARY(ext6 STATIC IMPORTED)
-SET_PROPERTY(TARGET ext6 PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libext6.a")
+IF (EXISTS "${CMAKE_SOURCE_DIR}/libext6.a")
+  ADD_LIBRARY(ext6 STATIC IMPORTED)
+  SET_PROPERTY(TARGET ext6 PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libext6.a")
+  LIST(APPEND ext_libs ext6)
+ENDIF()
 
 ADD_EXECUTABLE(firewall3 main.c options.c defaults.c zones.c forwards.c rules.c redirects.c utils.c ubus.c ipsets.c includes.c iptables.c)
-TARGET_LINK_LIBRARIES(firewall3 uci ubox ubus ip4tc ip6tc xtables m -Wl,--whole-archive ext ext4 ext6 -Wl,--no-whole-archive)
+TARGET_LINK_LIBRARIES(firewall3 uci ubox ubus ip4tc ip6tc xtables m ${ext_libs})
 
 SET(CMAKE_INSTALL_PREFIX /usr)
 
-INSTALL(TARGETS firewall3
-       RUNTIME DESTINATION sbin
-)
+INSTALL(TARGETS firewall3 RUNTIME DESTINATION sbin)