From cf00ebd56d933e17a9ee7a4cd686786a1a7aeefa Mon Sep 17 00:00:00 2001 From: Mahder Gebremedhin Date: Mon, 21 Sep 2020 14:04:48 +0200 Subject: [PATCH] Add Expat as a subdirectory instead of external. - This allows for a cleaner configuration. - When the project is used as a sub-project of another parent project, i.e., added as add_subdirectory(fmi-library), the build system is is broken for the Ninja generator. - There was also dependency on a non-existent (yet) target CMakeCache.txt. 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. CMakeCache.txt is not generated until end of config. - libexpat can, instead, be added as a subdirectory. Its build tree will be in /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. --- Config.cmake/fmixml.cmake | 72 +++------------------ ThirdParty/Expat/expat-2.1.0/CMakeLists.txt | 2 +- 2 files changed, 9 insertions(+), 65 deletions(-) diff --git a/Config.cmake/fmixml.cmake b/Config.cmake/fmixml.cmake index 03acb3ed..eb805e5b 100644 --- a/Config.cmake/fmixml.cmake +++ b/Config.cmake/fmixml.cmake @@ -139,70 +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) - +### 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) + +set(EXPAT_INCLUDE_DIRS ThirdParty/Expat/expat-2.1.0/lib) include_directories("${EXPAT_INCLUDE_DIRS}" "${FMILIB_THIRDPARTYLIBS}/FMI/" "${FMIXMLGENDIR}/FMI1" "${FMIXMLGENDIR}/FMI2") PREFIXLIST(FMIXMLSOURCE ${FMIXMLDIR}/) diff --git a/ThirdParty/Expat/expat-2.1.0/CMakeLists.txt b/ThirdParty/Expat/expat-2.1.0/CMakeLists.txt index 0c923baa..bd521502 100644 --- a/ThirdParty/Expat/expat-2.1.0/CMakeLists.txt +++ b/ThirdParty/Expat/expat-2.1.0/CMakeLists.txt @@ -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)