Skip to content

Commit

Permalink
Add Expat as a subdirectory instead of external.
Browse files Browse the repository at this point in the history
  - This allows for a cleaner configuration.

  - There was a dependency on a non-existent (yet) target expatex.
    CMake used to issue a developer warning

      CMake Warning (dev) at Config.cmake/fmixml.cmake:185 (add_dependencies):
      Policy CMP0046 is not set: Error on non-existent dependency in
      add_dependencies.  Run "cmake --help-policy CMP0046" for policy details.
      Use the cmake_policy command to set the policy and suppress this warning.

      The dependency target "/home/mahge/fmi-library/build_cmake/CMakeCache.txt"
      of target "expatex" does not exist.

  This a problem for some build tools like "Ninja" which are more strict

  libexpat can instead be added as a subdirectory. Its build tree will be
  in <fmil_binary_dir>/ThirdParty/Expat/exapat-2.1.0.

  This also allows it to inherit common configurations (e.g. build type
  debug/release) from its parent FMI library settings.
  • Loading branch information
mahge committed Sep 21, 2020
1 parent 0edf0b0 commit da0f8d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 66 deletions.
73 changes: 8 additions & 65 deletions Config.cmake/fmixml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,71 +139,14 @@ set(FMIXMLSOURCE

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DXML_STATIC -DFMI_XML_QUERY")

include(ExternalProject)

set(EXPAT_SETTINGS
-DBUILD_tools:BOOLEAN=OFF
-DBUILD_examples:BOOLEAN=OFF
-DBUILD_tests:BOOLEAN=OFF
-DBUILD_shared:BOOLEAN=OFF
-DXML_DTD:BOOLEAN=OFF
-DXML_NS:BOOLEAN=OFF
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
-DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
-DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}
-DCMAKE_LINK_LIBRARY_FLAG:STRING=${CMAKE_LINK_LIBRARY_FLAG}
-DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS}
-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/ExpatEx/install
)

ExternalProject_Add(
expatex
PREFIX "${FMIXML_EXPAT_DIR}"
SOURCE_DIR "${FMIXML_EXPAT_DIR}"
CMAKE_CACHE_ARGS ${EXPAT_SETTINGS}
BINARY_DIR ${CMAKE_BINARY_DIR}/ExpatEx
INSTALL_DIR ${CMAKE_BINARY_DIR}/ExpatEx/install
TMP_DIR ${CMAKE_BINARY_DIR}/ExpatEx/tmp
STAMP_DIR ${CMAKE_BINARY_DIR}/ExpatEx/stamp
)

ExternalProject_Add_Step(
expatex dependent_reconfigure
DEPENDEES configure
DEPENDERS build
COMMAND ${CMAKE_COMMAND} -E echo "Running: ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${EXPAT_SETTINGS} ${FMIXML_EXPAT_DIR}"
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${EXPAT_SETTINGS} "${FMIXML_EXPAT_DIR}"
DEPENDS ${CMAKE_BINARY_DIR}/CMakeCache.txt
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ExpatEx
)

add_dependencies(expatex ${CMAKE_BINARY_DIR}/CMakeCache.txt ${FMILIBRARYHOME}/CMakeLists.txt)

set(expatlib "${CMAKE_BINARY_DIR}/ExpatEx/${CMAKE_CFG_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}expat${CMAKE_STATIC_LIBRARY_SUFFIX}")

add_library(expat STATIC IMPORTED)

set_target_properties(
expat PROPERTIES
IMPORTED_LOCATION "${expatlib}"
)

add_dependencies(expat expatex)

if(FMILIB_INSTALL_SUBLIBS)
install(FILES
"${CMAKE_BINARY_DIR}/ExpatEx/install/lib/${CMAKE_STATIC_LIBRARY_PREFIX}expat${CMAKE_STATIC_LIBRARY_SUFFIX}"
DESTINATION lib)
endif()

set(EXPAT_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/ExpatEx/install/include)

include_directories("${EXPAT_INCLUDE_DIRS}" "${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2")
### Add the options of expat to the cache and add it as subdirectory.
set(BUILD_tools OFF CACHE BOOL "build the xmlwf tool for expat library")
set(BUILD_examples OFF CACHE BOOL "build the examples for expat library")
set(BUILD_tests OFF CACHE BOOL "build the tests for expat library")
set(BUILD_shared OFF CACHE BOOL "build a shared expat library")
add_subdirectory(ThirdParty/Expat/expat-2.1.0)

include_directories("${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2")

PREFIXLIST(FMIXMLSOURCE ${FMIXMLDIR}/)
PREFIXLIST(FMIXMLHEADERS ${FMIXMLDIR}/)
Expand Down
2 changes: 1 addition & 1 deletion ThirdParty/Expat/expat-2.1.0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ endif(BUILD_tests)

include(ConfigureChecks.cmake)

include_directories(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/lib)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4996)
endif(MSVC)
Expand Down

0 comments on commit da0f8d5

Please sign in to comment.