CMake: always honor manually set BUILD_* options

Figure out if the option should be enabled or disabled by default, but
unconditionally use it if it is set.
diff --git a/expat/CMakeLists.txt b/expat/CMakeLists.txt
index 9ec332e..08bb846 100644
--- a/expat/CMakeLists.txt
+++ b/expat/CMakeLists.txt
@@ -10,11 +10,27 @@
 set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")

 set(PACKAGE_TARNAME "${PACKAGE_NAME}")

 

-option(BUILD_tools "build the xmlwf tool for expat library" ON)

+if(WINCE)

+    set(BUILD_tools_default OFF)

+else()

+    set(BUILD_tools_default ON)

+endif()

+if(MSVC OR NOT BUILD_tools_default)

+    set(BUILD_doc_default OFF)

+else()

+    find_program(DOCBOOK_TO_MAN NAMES docbook2x-man)

+    if(DOCBOOK_TO_MAN)

+        set(BUILD_doc_default ON)

+    else()

+        set(BUILD_doc_default OFF)

+    endif()

+endif()

+

+option(BUILD_tools "build the xmlwf tool for expat library" ${BUILD_tools_default})

 option(BUILD_examples "build the examples for expat library" ON)

 option(BUILD_tests "build the tests for expat library" ON)

 option(BUILD_shared "build a shared expat library" ON)

-option(BUILD_doc "build man page for xmlwf" ON)

+option(BUILD_doc "build man page for xmlwf" ${BUILD_doc_default})

 option(USE_libbsd "utilize libbsd (for arc4random_buf)" OFF)

 option(INSTALL "install expat files in cmake install target" ON)

 

@@ -126,7 +142,7 @@
 expat_install(FILES lib/expat.h lib/expat_external.h DESTINATION include)

 expat_install(FILES ${CMAKE_CURRENT_BINARY_DIR}/expat.pc DESTINATION lib/pkgconfig)

 

-if(BUILD_tools AND NOT WINCE)

+if(BUILD_tools)

     set(xmlwf_SRCS

         xmlwf/xmlwf.c

         xmlwf/xmlfile.c

@@ -138,17 +154,17 @@
     set_property(TARGET xmlwf PROPERTY RUNTIME_OUTPUT_DIRECTORY xmlwf)

     target_link_libraries(xmlwf expat)

     expat_install(TARGETS xmlwf DESTINATION bin)

-    if(BUILD_doc AND NOT MSVC)

+    if(BUILD_doc)

         if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")

             set(make_command "$(MAKE)")

         else()

             set(make_command "make")

         endif()

 

-        add_custom_command(TARGET expat PRE_BUILD COMMAND "${make_command}" -C "${PROJECT_SOURCE_DIR}/doc" xmlwf.1)

+        add_custom_command(TARGET expat PRE_BUILD COMMAND "${make_command}" -C "${PROJECT_SOURCE_DIR}/doc" xmlwf.1 "DOCBOOK_TO_MAN=${DOCBOOK_TO_MAN}")

         expat_install(FILES "${PROJECT_SOURCE_DIR}/doc/xmlwf.1" DESTINATION share/man/man1)

     endif()

-endif(BUILD_tools AND NOT WINCE)

+endif()

 

 if(BUILD_examples)

     add_executable(elements examples/elements.c)