Просмотр исходного кода

Improving the ability to embed civetweb into a parent CMakeLists.txt

- Adding prefixes to variable names and targets
- Adding the ability to turn off the web server executable
Jacob Repp 7 лет назад
Родитель
Сommit
7ef6ccd4c8
3 измененных файлов с 51 добавлено и 46 удалено
  1. 5 2
      CMakeLists.txt
  2. 41 39
      src/CMakeLists.txt
  3. 5 5
      test/CMakeLists.txt

+ 5 - 2
CMakeLists.txt

@@ -54,6 +54,9 @@ set(CIVETWEB_THREAD_STACK_SIZE 102400 CACHE STRING
 set_property(CACHE CIVETWEB_THREAD_STACK_SIZE PROPERTY VALUE ${CIVETWEB_THREAD_STACK_SIZE})
 set_property(CACHE CIVETWEB_THREAD_STACK_SIZE PROPERTY VALUE ${CIVETWEB_THREAD_STACK_SIZE})
 message(STATUS "Thread Stack Size - ${CIVETWEB_THREAD_STACK_SIZE}")
 message(STATUS "Thread Stack Size - ${CIVETWEB_THREAD_STACK_SIZE}")
 
 
+option(CIVETWEB_ENABLE_SERVER_EXECUTABLE "Enable building of the server executable" ON)
+message(STATUS "Disable server - ${CIVETWEB_ENABLE_SERVER_EXECUTABLE}")
+
 # Serve no files from the web server
 # Serve no files from the web server
 option(CIVETWEB_SERVE_NO_FILES "Configures the server to serve no static files" OFF)
 option(CIVETWEB_SERVE_NO_FILES "Configures the server to serve no static files" OFF)
 message(STATUS "Serve no static files - ${CIVETWEB_SERVE_NO_FILES}")
 message(STATUS "Serve no static files - ${CIVETWEB_SERVE_NO_FILES}")
@@ -101,7 +104,7 @@ message(STATUS "Lua CGI support - ${CIVETWEB_ENABLE_LUA}")
 # Enable installing CivetWeb executables
 # Enable installing CivetWeb executables
 option(CIVETWEB_INSTALL_EXECUTABLE "Enable installing CivetWeb executable" ON)
 option(CIVETWEB_INSTALL_EXECUTABLE "Enable installing CivetWeb executable" ON)
 mark_as_advanced(FORCE CIVETWEB_INSTALL_EXECUTABLE) # Advanced users can disable
 mark_as_advanced(FORCE CIVETWEB_INSTALL_EXECUTABLE) # Advanced users can disable
-message(STATUS "Executable installation - ${CIVETWEB_INSTALL_EXECUTABLE}") 
+message(STATUS "Executable installation - ${CIVETWEB_INSTALL_EXECUTABLE}")
 
 
 # Allow builds to complete with warnings (do not set -Werror)
 # Allow builds to complete with warnings (do not set -Werror)
 # CivetWeb Linux support is stable:
 # CivetWeb Linux support is stable:
@@ -456,7 +459,7 @@ add_subdirectory(src)
 
 
 # Enable the testing of the library/executable
 # Enable the testing of the library/executable
 include(CTest)
 include(CTest)
-if (BUILD_TESTING)
+if (CIVETWEB_BUILD_TESTING)
   # Check unit testing framework Version
   # Check unit testing framework Version
   set(CIVETWEB_CHECK_VERSION 0.11.0 CACHE STRING
   set(CIVETWEB_CHECK_VERSION 0.11.0 CACHE STRING
     "The version of Check unit testing framework to build and include statically")
     "The version of Check unit testing framework to build and include statically")

+ 41 - 39
src/CMakeLists.txt

@@ -1,41 +1,41 @@
 # The C API library
 # The C API library
-add_library(c-library civetweb.c)
-set_target_properties(c-library PROPERTIES
+add_library(civetweb-c-library civetweb.c)
+set_target_properties(civetweb-c-library PROPERTIES
   OUTPUT_NAME "civetweb"
   OUTPUT_NAME "civetweb"
   VERSION ${CIVETWEB_VERSION}
   VERSION ${CIVETWEB_VERSION}
   SOVERSION ${CIVETWEB_VERSION}
   SOVERSION ${CIVETWEB_VERSION}
 )
 )
 if (BUILD_SHARED_LIBS)
 if (BUILD_SHARED_LIBS)
-  target_compile_definitions(c-library PRIVATE CIVETWEB_DLL_EXPORTS)
+  target_compile_definitions(civetweb-c-library PRIVATE CIVETWEB_DLL_EXPORTS)
 endif()
 endif()
 target_include_directories(
 target_include_directories(
-  c-library PUBLIC
+  civetweb-c-library PUBLIC
   ${PROJECT_SOURCE_DIR}/include)
   ${PROJECT_SOURCE_DIR}/include)
 install(
 install(
-  TARGETS c-library
+  TARGETS civetweb-c-library
   ARCHIVE DESTINATION lib
   ARCHIVE DESTINATION lib
   LIBRARY DESTINATION lib
   LIBRARY DESTINATION lib
   RUNTIME DESTINATION bin
   RUNTIME DESTINATION bin
-  COMPONENT c-library)
+  COMPONENT civetweb-c-library)
 install(FILES
 install(FILES
   ${PROJECT_SOURCE_DIR}/include/civetweb.h
   ${PROJECT_SOURCE_DIR}/include/civetweb.h
   DESTINATION include
   DESTINATION include
-  COMPONENT c-library)
+  COMPONENT civetweb-c-library)
 
 
 # Need Windows sockets if available
 # Need Windows sockets if available
 find_package(WinSock)
 find_package(WinSock)
 if (WINSOCK_FOUND)
 if (WINSOCK_FOUND)
-  target_link_libraries(c-library WINSOCK::WINSOCK)
+  target_link_libraries(civetweb-c-library WINSOCK::WINSOCK)
 endif()
 endif()
 
 
 # We need threading
 # We need threading
 find_package(Threads)
 find_package(Threads)
-target_link_libraries(c-library ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(civetweb-c-library ${CMAKE_THREAD_LIBS_INIT})
 
 
 # Need the realtime library if we're using timers
 # Need the realtime library if we're using timers
 find_package(LibRt)
 find_package(LibRt)
 if (CIVETWEB_ENABLE_WEBSOCKETS AND CIVETWEB_ENABLE_LUA AND LIBRT_FOUND)
 if (CIVETWEB_ENABLE_WEBSOCKETS AND CIVETWEB_ENABLE_LUA AND LIBRT_FOUND)
-  target_link_libraries(c-library LIBRT::LIBRT)
+  target_link_libraries(civetweb-c-library LIBRT::LIBRT)
 endif()
 endif()
 
 
 # We need to link OpenSSL if not dynamically loading
 # We need to link OpenSSL if not dynamically loading
@@ -43,13 +43,13 @@ if (CIVETWEB_ENABLE_SSL)
   if (CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING)
   if (CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING)
     find_package(LibDl)
     find_package(LibDl)
     if (LIBDL_FOUND)
     if (LIBDL_FOUND)
-      target_link_libraries(c-library -ldl)
+      target_link_libraries(civetweb-c-library -ldl)
     endif()
     endif()
   else()
   else()
     find_package(OpenSSL)
     find_package(OpenSSL)
     include_directories(${OPENSSL_INCLUDE_DIR})
     include_directories(${OPENSSL_INCLUDE_DIR})
     message(STATUS "OpenSSL include directory: ${OPENSSL_INCLUDE_DIR}")
     message(STATUS "OpenSSL include directory: ${OPENSSL_INCLUDE_DIR}")
-    target_link_libraries(c-library ${OPENSSL_LIBRARIES})
+    target_link_libraries(civetweb-c-library ${OPENSSL_LIBRARIES})
   endif()
   endif()
 endif()
 endif()
 
 
@@ -103,7 +103,7 @@ if (CIVETWEB_ENABLE_LUA)
     link_directories("${LUA_INSTALL_DIR}/lib")
     link_directories("${LUA_INSTALL_DIR}/lib")
     include_directories("${LUA_INSTALL_DIR}/include")
     include_directories("${LUA_INSTALL_DIR}/include")
     set(LUA_LIBRARIES "${LUA_INSTALL_DIR}/lib/liblua.a")
     set(LUA_LIBRARIES "${LUA_INSTALL_DIR}/lib/liblua.a")
-    add_dependencies(c-library lua)
+    add_dependencies(civetweb-c-library lua)
   else()
   else()
     find_package(Lua)
     find_package(Lua)
   endif()
   endif()
@@ -131,7 +131,7 @@ if (CIVETWEB_ENABLE_LUA)
   link_directories("${LUA_FILESYSTEM_INSTALL_DIR}/lib")
   link_directories("${LUA_FILESYSTEM_INSTALL_DIR}/lib")
   include_directories("${LUA_FILESYSTEM_INSTALL_DIR}/include")
   include_directories("${LUA_FILESYSTEM_INSTALL_DIR}/include")
   set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_FILESYSTEM_INSTALL_DIR}/lib/libluafilesystem.a")
   set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_FILESYSTEM_INSTALL_DIR}/lib/libluafilesystem.a")
-  add_dependencies(c-library luafilesystem)
+  add_dependencies(civetweb-c-library luafilesystem)
 
 
   # Lua SQLite Support
   # Lua SQLite Support
   if (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.3")
   if (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.3")
@@ -163,7 +163,7 @@ if (CIVETWEB_ENABLE_LUA)
   unset(INSTALL_DIR)
   unset(INSTALL_DIR)
   link_directories("${LUA_SQLITE_INSTALL_DIR}/lib")
   link_directories("${LUA_SQLITE_INSTALL_DIR}/lib")
   set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_SQLITE_INSTALL_DIR}/lib/libluasqlite.a")
   set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_SQLITE_INSTALL_DIR}/lib/libluasqlite.a")
-  add_dependencies(c-library luasqlite)
+  add_dependencies(civetweb-c-library luasqlite)
 
 
   # Lua XML Support
   # Lua XML Support
   if (${CIVETWEB_LUA_XML_VERSION} VERSION_EQUAL "1.8.0")
   if (${CIVETWEB_LUA_XML_VERSION} VERSION_EQUAL "1.8.0")
@@ -204,7 +204,7 @@ if (CIVETWEB_ENABLE_LUA)
   unset(INSTALL_DIR)
   unset(INSTALL_DIR)
   link_directories("${LUA_XML_INSTALL_DIR}/lib")
   link_directories("${LUA_XML_INSTALL_DIR}/lib")
   set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_XML_INSTALL_DIR}/lib/libluaxml.a")
   set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_XML_INSTALL_DIR}/lib/libluaxml.a")
-  add_dependencies(c-library luaxml)
+  add_dependencies(civetweb-c-library luaxml)
 
 
   # SQLite Support
   # SQLite Support
   string (REGEX MATCHALL "[0-9]+" SQLITE_VERSION_MATCHES ${CIVETWEB_SQLITE_VERSION})
   string (REGEX MATCHALL "[0-9]+" SQLITE_VERSION_MATCHES ${CIVETWEB_SQLITE_VERSION})
@@ -233,34 +233,36 @@ if (CIVETWEB_ENABLE_LUA)
   link_directories("${SQLITE_INSTALL_DIR}/lib")
   link_directories("${SQLITE_INSTALL_DIR}/lib")
   include_directories("${SQLITE_INSTALL_DIR}/include")
   include_directories("${SQLITE_INSTALL_DIR}/include")
   set(LUA_LIBRARIES "${LUA_LIBRARIES};${SQLITE_INSTALL_DIR}/lib/libsqlite.a")
   set(LUA_LIBRARIES "${LUA_LIBRARIES};${SQLITE_INSTALL_DIR}/lib/libsqlite.a")
-  add_dependencies(c-library sqlite)
+  add_dependencies(civetweb-c-library sqlite)
 
 
   # Link all the Lua libraries
   # Link all the Lua libraries
-  target_link_libraries(c-library ${LUA_LIBRARIES})
+  target_link_libraries(civetweb-c-library ${LUA_LIBRARIES})
 endif()
 endif()
 
 
 # The web server executable
 # The web server executable
-add_executable(c-executable main.c)
-set_target_properties(c-executable PROPERTIES
-  OUTPUT_NAME "civetweb"
-)
-if (CIVETWEB_INSTALL_EXECUTABLE)
-  install(
-    TARGETS c-executable
-    ARCHIVE DESTINATION lib
-    LIBRARY DESTINATION lib
-    RUNTIME DESTINATION bin
-    COMPONENT server)
-endif()
-if (BUILD_SHARED_LIBS)
-  target_compile_definitions(c-executable PRIVATE CIVETWEB_DLL_IMPORTS)
-endif()
-target_include_directories(
-  c-executable PUBLIC
-  ${PROJECT_SOURCE_DIR}/include)
-target_link_libraries(c-executable c-library)
-if (LIBRT_FOUND)
-  target_link_libraries(c-executable LIBRT::LIBRT)
+if (CIVETWEB_ENABLE_SERVER)
+    add_executable(civetweb-c-executable main.c)
+    set_target_properties(civetweb-c-executable PROPERTIES
+        OUTPUT_NAME "civetweb"
+    )
+    if (CIVETWEB_INSTALL_EXECUTABLE)
+        install(
+            TARGETS civetweb-c-executable
+            ARCHIVE DESTINATION lib
+            LIBRARY DESTINATION lib
+            RUNTIME DESTINATION bin
+            COMPONENT server)
+    endif()
+    if (BUILD_SHARED_LIBS)
+        target_compile_definitions(civetweb-c-executable PRIVATE CIVETWEB_DLL_IMPORTS)
+    endif()
+    target_include_directories(
+        civetweb-c-executable PUBLIC
+        ${PROJECT_SOURCE_DIR}/include)
+    target_link_libraries(civetweb-c-executable civetweb-c-library)
+    if (LIBRT_FOUND)
+        target_link_libraries(civetweb-c-executable LIBRT::LIBRT)
+    endif()
 endif()
 endif()
 
 
 if (CIVETWEB_ENABLE_LUA)
 if (CIVETWEB_ENABLE_LUA)

+ 5 - 5
test/CMakeLists.txt

@@ -17,7 +17,7 @@ include(ExternalProject)
 #  set(CHECK_PATCH_COMMAND "")
 #  set(CHECK_PATCH_COMMAND "")
 #endif()
 #endif()
 ExternalProject_Add(check-unit-test-framework
 ExternalProject_Add(check-unit-test-framework
-  DEPENDS c-library
+  DEPENDS civetweb-c-library
 
 
 ## Use an official, released check version:
 ## Use an official, released check version:
 #  URL "https://codeload.github.com/libcheck/check/zip/${CIVETWEB_CHECK_VERSION}"
 #  URL "https://codeload.github.com/libcheck/check/zip/${CIVETWEB_CHECK_VERSION}"
@@ -79,7 +79,7 @@ endif()
 target_include_directories(
 target_include_directories(
   public-func-c-unit-tests PUBLIC
   public-func-c-unit-tests PUBLIC
   ${PROJECT_SOURCE_DIR}/include)
   ${PROJECT_SOURCE_DIR}/include)
-target_link_libraries(public-func-c-unit-tests c-library ${CHECK_LIBRARIES})
+target_link_libraries(public-func-c-unit-tests civetweb-c-library ${CHECK_LIBRARIES})
 add_dependencies(public-func-c-unit-tests check-unit-test-framework)
 add_dependencies(public-func-c-unit-tests check-unit-test-framework)
 
 
 add_library(public-server-c-unit-tests STATIC public_server.c)
 add_library(public-server-c-unit-tests STATIC public_server.c)
@@ -89,7 +89,7 @@ endif()
 target_include_directories(
 target_include_directories(
   public-server-c-unit-tests PUBLIC
   public-server-c-unit-tests PUBLIC
   ${PROJECT_SOURCE_DIR}/include)
   ${PROJECT_SOURCE_DIR}/include)
-target_link_libraries(public-server-c-unit-tests c-library ${CHECK_LIBRARIES})
+target_link_libraries(public-server-c-unit-tests civetweb-c-library ${CHECK_LIBRARIES})
 add_dependencies(public-server-c-unit-tests check-unit-test-framework)
 add_dependencies(public-server-c-unit-tests check-unit-test-framework)
 
 
 add_library(private-c-unit-tests STATIC private.c)
 add_library(private-c-unit-tests STATIC private.c)
@@ -113,7 +113,7 @@ endif()
 target_include_directories(
 target_include_directories(
   exe-c-unit-tests PUBLIC
   exe-c-unit-tests PUBLIC
   ${PROJECT_SOURCE_DIR}/include)
   ${PROJECT_SOURCE_DIR}/include)
-target_link_libraries(exe-c-unit-tests c-library ${CHECK_LIBRARIES})
+target_link_libraries(exe-c-unit-tests civetweb-c-library ${CHECK_LIBRARIES})
 add_dependencies(exe-c-unit-tests check-unit-test-framework)
 add_dependencies(exe-c-unit-tests check-unit-test-framework)
 
 
 add_executable(main-c-unit-test main.c)
 add_executable(main-c-unit-test main.c)
@@ -143,7 +143,7 @@ macro(civetweb_add_test suite test_case)
   if (WIN32)
   if (WIN32)
     string(REPLACE ";" "\\;" test_path "$ENV{PATH}")
     string(REPLACE ";" "\\;" test_path "$ENV{PATH}")
     set_tests_properties(${test} PROPERTIES
     set_tests_properties(${test} PROPERTIES
-      ENVIRONMENT "PATH=${test_path}\\;$<TARGET_FILE_DIR:c-library>")
+      ENVIRONMENT "PATH=${test_path}\\;$<TARGET_FILE_DIR:civetweb-c-library>")
   endif()
   endif()
 endmacro(civetweb_add_test)
 endmacro(civetweb_add_test)