Skip to content

Building libsbml and its dependencies in the same project #227

@luciansmith

Description

@luciansmith

I have a problem. I'm trying to build libsbml in a project where libsbml's dependencies are also being built at the same time. The problem is that when libsbml tries to find expat, it sees that expat hasn't been built yet, and fails. However, this is to be expected: the system is going to build both expat and libsbml; it just has to wait.

Here's the relevant bits of my CMakeLists.txt file:

#expat
set (EXPAT_SHARED_LIBS OFF)
set (EXPAT_BUILD_EXAMPLES OFF)
set (EXPAT_BUILD_TESTS OFF)
set (EXPAT_BUILD_TOOLS OFF)
set (EXPAT_BUILD_TOOLS OFF)
if (WITH_STATIC_RUNTIME)
    #expat is overriding this
  set(EXPAT_MSVC_STATIC_CRT ON CACHE BOOL "Use /MT flag (static CRT) when compiling in MSVC" FORCE)
endif()

add_subdirectory(expat/expat)

set(EXPAT_INCLUDE_DIR "$<TARGET_PROPERTY:expat,INCLUDE_DIRECTORIES>")
set(EXPAT_LIBRARY "$<TARGET_LINKER_FILE:expat>")


# libsbml
message(STATUS "Adding libsbml as subdirectory")
set(WITH_EXPAT ON CACHE BOOL "Compile libsbml with the expat library" FORCE)
set(WITH_LIBXML OFF CACHE BOOL "Compile libsbml with libxml (off by default)" FORCE)
add_subdirectory(libsbml)

and here's the error message I get from CMake:

CMake Error at third_party/libsbml/CMakeModules/FindEXPAT.cmake:163 (message):
  Unable to compile a test executable against expat with

    
    EXPAT_INCLUDE_DIR = $<TARGET_PROPERTY:expat,INCLUDE_DIRECTORIES>
    EXPAT_LIBRARY     = $<TARGET_LINKER_FILE:expat>
    
Call Stack (most recent call first):
  third_party/libsbml/CMakeLists.txt:422 (find_package)

If I comment out the lines defining EXPAT_INCLUDE_DIR and EXPAT_LIBRARY, I get:

CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find EXPAT (missing: EXPAT_LIBRARY EXPAT_INCLUDE_DIR)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  third_party/libsbml/CMakeModules/FindEXPAT.cmake:179 (find_package_handle_standard_args)
  third_party/libsbml/CMakeLists.txt:422 (find_package)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions