uci: Fix extra semicolons warnings
[oweals/uci.git] / CMakeLists.txt
index e846ceb3171253716b23b7375596aa65daf6ad55..da4ac68c01391f326ed39b777a6bb735c617960b 100644 (file)
@@ -3,32 +3,60 @@ cmake_minimum_required(VERSION 2.6)
 PROJECT(uci C)
 
 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
-ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I. -DUCI_PREFIX="${CMAKE_INSTALL_PREFIX}")
+
+ADD_DEFINITIONS(-Wall -Werror)
+IF(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6)
+       ADD_DEFINITIONS(-Wextra -Werror=implicit-function-declaration)
+       ADD_DEFINITIONS(-Wformat -Werror=format-security -Werror=format-nonliteral)
+ENDIF()
+ADD_DEFINITIONS(-Os -std=gnu99 -g3 -Wmissing-declarations -Wno-unused-parameter)
+ADD_DEFINITIONS(-DUCI_PREFIX="${CMAKE_INSTALL_PREFIX}")
+
 
 OPTION(UCI_DEBUG "debugging support" OFF)
 OPTION(UCI_DEBUG_TYPECAST "typecast debugging support" OFF)
 OPTION(BUILD_LUA "build Lua binding" ON)
+OPTION(BUILD_STATIC "statically linking uci" OFF)
+
+FIND_PATH(ubox_include_dir libubox/usock.h)
 
 CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/uci_config.h.in ${CMAKE_SOURCE_DIR}/uci_config.h )
 
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${ubox_include_dir})
 
 SET(LIB_SOURCES libuci.c file.c util.c delta.c parse.c blob.c)
 
+FIND_LIBRARY(ubox NAMES ubox)
+IF(BUILD_STATIC)
+  FIND_LIBRARY(ubox-static NAMES libubox.a)
+ENDIF(BUILD_STATIC)
+
 ADD_LIBRARY(uci SHARED ${LIB_SOURCES})
-TARGET_LINK_LIBRARIES(uci ubox)
 SET_TARGET_PROPERTIES(uci PROPERTIES OUTPUT_NAME uci)
+TARGET_LINK_LIBRARIES(uci ${ubox})
+
+ADD_LIBRARY(uci-static STATIC ${LIB_SOURCES})
+SET_TARGET_PROPERTIES(uci-static PROPERTIES OUTPUT_NAME uci)
+TARGET_LINK_LIBRARIES(uci-static ${ubox-static})
 
 ADD_EXECUTABLE(cli cli.c)
 SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME uci)
-TARGET_LINK_LIBRARIES(cli uci)
+IF(BUILD_STATIC)
+  TARGET_LINK_LIBRARIES(cli uci-static ${ubox-static})
+ELSE(BUILD_STATIC)
+  TARGET_LINK_LIBRARIES(cli uci ${ubox})
+ENDIF(BUILD_STATIC)
 
 ADD_LIBRARY(ucimap STATIC ucimap.c)
 
-ADD_EXECUTABLE(ucimap-example ucimap-example.c)
-TARGET_LINK_LIBRARIES(ucimap-example uci ucimap)
+IF(BUILD_LUA)
+  ADD_SUBDIRECTORY(lua)
+ENDIF()
 
-ADD_SUBDIRECTORY(lua)
+IF(UNIT_TESTING)
+  ENABLE_TESTING()
+  ADD_SUBDIRECTORY(tests)
+ENDIF()
 
 INSTALL(FILES uci.h uci_config.h uci_blob.h ucimap.h
        DESTINATION include