diff --git a/CMakeLists.txt b/CMakeLists.txt index 59910dbc..5d2d630d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,14 @@ cmake_minimum_required(VERSION 3.5) project(PhysicsFS VERSION ${PHYSFS_VERSION} LANGUAGES C ) +if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + set(PHYSFS_SUBPROJECT OFF) + set(PHYSFS_ROOTPROJECT ON) +else() + set(PHYSFS_SUBPROJECT ON) + set(PHYSFS_ROOTPROJECT OFF) +endif() + include(GNUInstallDirs) # Increment this if/when we break backwards compatibility. @@ -232,7 +240,7 @@ if(PHYSFS_BUILD_TEST) list(APPEND PHYSFS_INSTALL_TARGETS test_physfs) endif() -option(PHYSFS_DISABLE_INSTALL "Disable installing PhysFS" OFF) +option(PHYSFS_DISABLE_INSTALL "Disable installing PhysFS" "${PHYSFS_SUBPROJECT}") if(NOT PHYSFS_DISABLE_INSTALL) install(TARGETS ${PHYSFS_INSTALL_TARGETS} EXPORT PhysFSExport @@ -262,7 +270,7 @@ if(NOT PHYSFS_DISABLE_INSTALL) endif() endif() -option(PHYSFS_BUILD_DOCS "Build doxygen based documentation" TRUE) +option(PHYSFS_BUILD_DOCS "Build doxygen based documentation" ${PHYSFS_ROOTPROJECT}) if(PHYSFS_BUILD_DOCS) find_package(Doxygen) if(DOXYGEN_FOUND) @@ -275,17 +283,31 @@ if(PHYSFS_BUILD_DOCS) file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n") file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${PHYSFS_VERSION}\"\n") file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n") + file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "INPUT = \"${CMAKE_CURRENT_SOURCE_DIR}/src/physfs.h\"\n") file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n") set(PHYSFS_TARGETNAME_DOCS "docs" CACHE STRING "Name of 'docs' build target") - add_custom_target( - ${PHYSFS_TARGETNAME_DOCS} - ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/docs/html/index.html" + COMMAND ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}" COMMENT "Building documentation in 'docs' directory..." + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/physfs.h" "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile" ) + add_custom_target(${PHYSFS_TARGETNAME_DOCS} ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/docs/html/index.html" + ) + + if(NOT PHYSFS_DISABLE_INSTALL) + install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/html" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/physfs" + ) + install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/man" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}" + ) + endif() + else() message(STATUS "Doxygen not found. You won't be able to build documentation.") endif()