diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e1760473..778682e7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -654,11 +654,16 @@ IF (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") ENDIF (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # Configure the Ceres config.h compile options header using the current -# compile options and put the configured header into the Ceres source tree. +# compile options and put the configured header into the Ceres build +# directory. Note that the ceres/internal subdir in /config where +# the configured config.h is placed is important, because Ceres will be +# built against this configured header, it needs to have the same relative +# include path as it would if it were in the source tree (or installed). LIST(REMOVE_DUPLICATES CERES_COMPILE_OPTIONS) INCLUDE(CreateCeresConfig) CREATE_CERES_CONFIG("${CERES_COMPILE_OPTIONS}" - ${CMAKE_SOURCE_DIR}/include/ceres/internal) + ${CMAKE_CURRENT_BINARY_DIR}/config/ceres/internal) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/config) ADD_SUBDIRECTORY(internal/ceres) @@ -684,6 +689,12 @@ INSTALL(FILES ${CERES_HDRS} DESTINATION include/ceres) FILE(GLOB CERES_PUBLIC_INTERNAL_HDRS ${CMAKE_SOURCE_DIR}/include/ceres/internal/*.h) INSTALL(FILES ${CERES_PUBLIC_INTERNAL_HDRS} DESTINATION include/ceres/internal) +# Also setup installation of Ceres config.h configured with the current +# build options into the installed headers directory. +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/config/ceres/internal/config.h + DESTINATION include/ceres/internal) + + IF (MINIGLOG) # Install miniglog header if being used as logging #includes appear in # installed public Ceres headers. diff --git a/cmake/CreateCeresConfig.cmake b/cmake/CreateCeresConfig.cmake index 43f4d17a0..23f449b64 100644 --- a/cmake/CreateCeresConfig.cmake +++ b/cmake/CreateCeresConfig.cmake @@ -56,11 +56,16 @@ SET(CERES_CONFIG_IN_FILE "${CMAKE_CURRENT_LIST_DIR}/config.h.in") # will be /include/ceres/internal. FUNCTION(CREATE_CERES_CONFIG CURRENT_CERES_COMPILE_OPTIONS CERES_CONFIG_OUTPUT_DIRECTORY) - # Verify that the specified output directory is valid. - IF (NOT (EXISTS "${CERES_CONFIG_OUTPUT_DIRECTORY}" AND - IS_DIRECTORY "${CERES_CONFIG_OUTPUT_DIRECTORY}")) + # Create the specified output directory if it does not exist. + IF (NOT EXISTS "${CERES_CONFIG_OUTPUT_DIRECTORY}") + MESSAGE(STATUS "Creating configured Ceres config.h output directory: " + "${CERES_CONFIG_OUTPUT_DIRECTORY}") + FILE(MAKE_DIRECTORY "${CERES_CONFIG_OUTPUT_DIRECTORY}") + ENDIF() + IF (EXISTS "${CERES_CONFIG_OUTPUT_DIRECTORY}" AND + NOT IS_DIRECTORY "${CERES_CONFIG_OUTPUT_DIRECTORY}") MESSAGE(FATAL_ERROR "Ceres Bug: Specified CERES_CONFIG_OUTPUT_DIRECTORY: " - "${CERES_CONFIG_OUTPUT_DIRECTORY} does not exist, or is not a directory.") + "${CERES_CONFIG_OUTPUT_DIRECTORY} exists, but is not a directory.") ENDIF() # Read all possible configurable compile options from config.h.in, this avoids diff --git a/include/ceres/internal/config.h b/config/ceres/internal/config.h similarity index 100% rename from include/ceres/internal/config.h rename to config/ceres/internal/config.h diff --git a/jni/Android.mk b/jni/Android.mk index 70271460b..23e588fde 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -79,6 +79,7 @@ CERES_INCLUDE_PATHS := $(CERES_EXTRA_INCLUDES) CERES_INCLUDE_PATHS += $(LOCAL_PATH)/../internal CERES_INCLUDE_PATHS += $(LOCAL_PATH)/../internal/ceres CERES_INCLUDE_PATHS += $(LOCAL_PATH)/../include +CERES_INCLUDE_PATHS += $(LOCAL_PATH)/../config # Use the alternate glog implementation if provided by the user. ifdef CERES_GLOG_DIR