Funny, that is what I ended up doing with all my support libraries. I create a #define in the configured header and then I do a try-compile to look for the symbol. If the symbol is there then I know it is a dynamic library.

For those interested (or for comments) here is the CMake code that I use:

IF (EXPAT_FOUND)
  INCLUDE(CheckSymbolExists)
  #############################################
  # Find out if EXPAT was build using dll's
  #############################################
  # Save required variable
  SET(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES})
  SET(CMAKE_REQUIRED_FLAGS_SAVE    ${CMAKE_REQUIRED_FLAGS})
  # Add EXPAT_INCLUDE_DIR to CMAKE_REQUIRED_INCLUDES
SET(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};$ {EXPAT_INCLUDE_DIRS}")

CHECK_SYMBOL_EXISTS(EXPAT_BUILT_AS_DYNAMIC_LIB "expat_config.h" HAVE_EXPAT_DLL)

    IF (HAVE_EXPAT_DLL STREQUAL "TRUE")
        SET (HAVE_EXPAT_DLL "1")
    ENDIF (HAVE_EXPAT_DLL STREQUAL "TRUE")

  # Restore CMAKE_REQUIRED_INCLUDES and CMAKE_REQUIRED_FLAGS variables
  SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})
  SET(CMAKE_REQUIRED_FLAGS    ${CMAKE_REQUIRED_FLAGS_SAVE})
  #
  #############################################

ENDIF (EXPAT_FOUND)


--
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services


On Jul 10, 2008, at 5:55 PM, James Bigler wrote:

You are correct that you can't simply test the HDF5_LIBRARIES
variables since in windows a .lib is used for both static and shared
linking.

Since you can get access to this information from a header file you
could do a try compile and look at the output, or you could read the
contents of the file into a variable and parse out the define with a
regular expression.  See file(READ filename variable [LIMIT numBytes]
[OFFSET offset] [HEX]) and string(REGEX MATCH <regular_expression>
<output variable> <input> [<input>...]).

James

On Fri, Jun 27, 2008 at 8:16 AM, Mike Jackson <[EMAIL PROTECTED]> wrote:
What are the recommended ways to determine what type of libraries my
application is linking against. An example should explain what I mean.

I use the HDF5 library as part of my project. It can be built either as a static or dynamic. If it is built as a static library then I don't need to copy it during the install phase. If it is built as a dynamic library then I
_do_ need to copy it.

Would parsing the HDF5_LIBRARIES variable for a .lib or .dll work? Although not sure about that since you link against the .lib on windows but use the
.dll? This is mainly for Visual Studio use.

Currently there is a #define HDF5_DLL_LIB defined in the H5config.h file. I
thought of trying a simple try-compile a test file to see if it would
compile and then base my decision on that.

Other ways? Better ways? Example code?

Thanks
--
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services



_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake



_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to