[CMake] Modifying LIBRARY_OUTPUT_PATH dynamically in a macro

gga ggarra at advancedsl.com.ar
Wed Jun 6 05:17:24 EDT 2007


I'm trying to change the destination where some shared libraries are
created, trying to place them in subdirectories.

I need to have a macro, which in turn will modify the
LIBRARY_OUTPUT_PATH and create the new library in that new directory.  I
have created such a beast.  The debug output spits out the path properly
for LIBRARY_OUTPUT_PATH.

Unfortunately, this seems to not work.  I am only able to change the
LIBRARY_OUTPUT_PATH in a new CMakeLists.txt file (ie. in a subdir), but
I don't seem to be able to modify it from within a single CMakeLists.txt
file and macro.  Cmake does not respect the change and just dumps the
libraries in the previously defined LIBRARY_OUTPUT_PATH location.

# A simple macro to create a maya plugin.
#
# Usage is:
#
# CREATE_MAYA_PLUG_IN(
#                      "mrLiquid" "0.7"
#                      "test.cpp hello.cpp"
#                      "OpenMaya OpenMayaAnim"
#                     )
#
MACRO(CREATE_MAYA_PLUG_IN NAME VERSION SOURCES LIBRARIES)

  # define a bunch of maya variables
  MAYA_DEFINITIONS()

  # split input name into a plugin name and any optional subdir
  STRING( REGEX MATCH "[^/]+$" PLUGNAME "${NAME}" )
  STRING( REGEX REPLACE "${PLUGNAME}$" "" ANYPATH "${NAME}" )

  # store output path
  SET( OLD_LIBRARY_PATH ${LIBRARY_OUTPUT_PATH} )

  # make sure subdirs exist
  FILE( MAKE_DIRECTORY
      "${LIBRARY_OUTPUT_PATH}"
      "${LIBRARY_OUTPUT_PATH}/maya${MAYA_VERSION}"
      )

  # change output path
  SET( LIBRARY_OUTPUT_PATH
      "${LIBRARY_OUTPUT_PATH}/maya${MAYA_VERSION}/${ANYPATH}" )

  # make sure output directory exists
  FILE( MAKE_DIRECTORY "${LIBRARY_OUTPUT_PATH}" )

  # debug the stuff
  MESSAGE( STATUS "# Creating Maya${MAYA_VERSION} plug-in ${PLUGNAME} in
${LIBRARY_OUTPUT_PATH} #" )


  # add the plugin
  ADD_LIBRARY( ${PLUGNAME} SHARED ${SOURCES} )
  TARGET_LINK_LIBRARIES( ${PLUGNAME} ${LIBRARIES} )

  # get old link flags
  GET_TARGET_PROPERTY( OLD_FLAGS "${PLUGNAME}" LINK_FLAGS )
  IF( NOT OLD_FLAGS )
    SET( OLD_FLAGS "" )
  ENDIF( NOT OLD_FLAGS )

  # change properties
  SET_TARGET_PROPERTIES(
      "${PLUGNAME}"
      PROPERTIES
      PREFIX     ""
      SUFFIX     "${MAYA_EXTENSION}"
      VERSION    "${VERSION}"
      SOVERSION  "${VERSION}"
      LINK_FLAGS "${MAYA_LINK_FLAGS} ${OLD_FLAGS}"
      )

  # revert output directory
  SET( LIBRARY_OUTPUT_PATH ${OLD_LIBRARY_PATH} )

ENDMACRO(CREATE_MAYA_PLUG_IN)


-- 
Gonzalo Garramuño
ggarra at advancedsl.com.ar

AMD4400 - ASUS48N-E
GeForce7300GT
Kubuntu Edgy


More information about the CMake mailing list