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.
@@ -10,11 +10,27 @@ set(PACKAGE_VERSION "2.2.3")
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 @@ configure_file(expat.pc.in ${CMAKE_CURRENT_BINARY_DIR}/expat.pc)
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 @@ if(BUILD_tools AND NOT WINCE)
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)
