Opened 15 years ago

Last modified 13 years ago

#19781 closed enhancement

modify cmake Modules for MacPorts prefix — at Version 7

Reported by: dweber@… Owned by: css@…
Priority: Normal Milestone:
Component: ports Version: 1.7.1
Keywords: FindITK.cmake cmake modules Cc: css@…
Port: cmake

Description (last modified by dweber@…)

I'm working on an InsightToolkit port that will install into a non-standard MacPorts install path. I've discovered that the defaults in the cmake Modules may not pick up the MacPort installations. For example, in /opt/local/share/cmake-2.6/Modules/FindITK.cmake, we could modify it to the following:

    # Look in standard UNIX install locations.
    /opt/local/lib/InsightToolkit
    /usr/local/lib/InsightToolkit
    /usr/lib/InsightToolkit

I was able to get this result with a command line like this:

cat /opt/local/share/cmake-2.6/Modules/FindITK.cmake | sed -e 's|/usr/local/lib/InsightToolkit|/opt/local/lib/InsightToolkit\n\t/usr/local/lib/InsightToolkit|g'

I suppose other tweaks like this could be a part of the post-destroot for the cmake port. The goal is to allow any MacPort installation to rely on cmake modules to pick up other MacPort libraries automatically, and in preference (with precedence) to anything similar installed outside of ${prefix} on the system.

Best regards, Darren

Change History (7)

comment:1 Changed 15 years ago by dweber@…

More information about this...

I've got a new revision of InsightToolkit working nicely, but it works best with a modification to the cmake module for FindITK.cmake. This file is installed at

/opt/local/share/cmake-2.6/Modules/FindITK.cmake

In the current testing revision of InsightToolkit is at:

https://svn.macosforge.org/repository/macports/users/dweber/graphics/InsightToolkit/Portfile

http://trac.macports.org/changeset/51573

The post-destroot creates version specific library and include paths, with symlinks to them from a generic path, and also modifies a few configuration files, including FindITK.cmake, so the system can find these version specific installations:

post-destroot {
    # For some reason, cmake does not install into the CMAKE_INSTALL_NAME_DIR
    move ${destroot}${prefix}/lib/${name}       ${destroot}${itkLibPath}
    move ${destroot}${prefix}/include/${name}   ${destroot}${itkIncPath}
    # Create a symlink from the generic lib and include for InsightToolkit to this version
    ln -sf ${distname} ${destroot}${prefix}/lib/${name}
    ln -sf ${distname} ${destroot}${prefix}/include/${name}
    # copy FindITK.cmake to a version specific file, which might persist even
    # when cmake is updated, deactivated, etc.
    set findITK [glob ${prefix}/share/cmake-*/Modules/FindITK.cmake]
    set findITKbranch [strsed ${findITK} #FindITK#FindITK-${branch}#]
    copy ${findITK} ${destroot}${findITK}
    copy ${findITK} ${destroot}${findITKbranch}
    # Change the content of $findITK and $findITKbranch, to find MacPorts lib
    set stdlib /usr/local/lib/InsightToolkit
    set newlib ${prefix}/lib/InsightToolkit
    reinplace "s|${stdlib}|${newlib}\\\n    ${newlib}-${branch}\\\n    ${stdlib}|g" ${destroot}${findITK}
    reinplace "s|${stdlib}|${newlib}\\\n    ${newlib}-${branch}\\\n    ${stdlib}|g" ${destroot}${findITKbranch}
    # Change the content of ITKConfig.cmake
    reinplace "s|${name}|${distname}|g" ${destroot}${itkLibPath}/ITKConfig.cmake
    copy ${destroot}${itkLibPath}/ITKConfig.cmake ${destroot}${itkLibPath}/itk-${branch}-config.cmake
}

Note the reinplace commands in the post-destroot, which result in the following diff on FindITK.cmake:

--- FindITK.cmake-orig    2009-05-28 09:57:35.000000000 -0700
+++ FindITK.cmake    2009-05-28 10:00:09.000000000 -0700
@@ -50,6 +50,8 @@
     ${ITK_DIR_SEARCH}
 
     # Look in standard UNIX install locations.
+    /opt/local/lib/InsightToolkit
+    /opt/local/lib/InsightToolkit-3.12
     /usr/local/lib/InsightToolkit
     /usr/lib/InsightToolkit

Note that similar additions could be made for FindVTK.cmake, at about:

    # Look in standard UNIX install locations.
    /usr/local/lib/vtk
    /usr/lib/vtk

The problem with modification to FindITK.cmake in the InsightToolkit is that the activation stage will fail without the -f flag to force an overwrite of the FindITK.cmake file provided by cmake. It makes more sense to modify the cmake port directly.

Do you agree these are useful changes to the cmake port? Can I assume responsibility for making these changes to the cmake port?

Thanks, Darren

comment:2 Changed 15 years ago by dweber@…

Cc: css@… added

comment:3 Changed 15 years ago by dweber@…

Proposed changes now in my user svn at:

https://trac.macports.org/browser/users/dweber/devel/cmake/Portfile

It may be necessary to apply similar changes to many of the cmake modules. The changes in my svn focus only on ITK and VTK, simply for lack of time to explore other modules at the moment.

If this change is adopted in cmake, then I can remove similar hacks that are otherwise required for FindITK.cmake and FindVTK.cmake in the InsightToolkit and vtk-devel ports.

Best, Darren

comment:5 Changed 15 years ago by cssdev

Owner: changed from macports-tickets@… to css@…
Status: newassigned

I'm just returning from travel, but this was adressed in the general sense in #18420, specifically comment:ticket:18420:4. Maybe there's some way we could easily get the appropriate settings into the user's environment, because otherwise trying to manually track the changes for so many CMake modules might be troublesome to create so many modifications for each module.

comment:6 Changed 15 years ago by dweber@…

There is a simple solution to this, within the cmake port, using a bit of tcl in the post-destroot phase.

These are probably all the module files that contain /usr/local (the default prefix for most *nix open-source software):

[ dweber@X ~ ]$ grep ".*/usr/local.*" /opt/local/share/cmake-2.6/Modules/*.cmake
/opt/local/share/cmake-2.6/Modules/CMakeDetermineJavaCompiler.cmake:    /usr/local/bin
/opt/local/share/cmake-2.6/Modules/CMakeDetermineJavaCompiler.cmake:    /usr/local/java/bin
/opt/local/share/cmake-2.6/Modules/CMakeDetermineSystem.cmake:  FIND_PROGRAM(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
/opt/local/share/cmake-2.6/Modules/CMakeGenericSystem.cmake:  SET(CMAKE_INSTALL_PREFIX "/usr/local"
/opt/local/share/cmake-2.6/Modules/FindAVIFile.cmake:    /usr/local/avifile/include
/opt/local/share/cmake-2.6/Modules/FindAVIFile.cmake:    /usr/local/include/avifile
/opt/local/share/cmake-2.6/Modules/FindAVIFile.cmake:    /usr/local/avifile/lib
/opt/local/share/cmake-2.6/Modules/FindAVIFile.cmake:    /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindBLAS.cmake:    PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
/opt/local/share/cmake-2.6/Modules/FindBLAS.cmake:    PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
/opt/local/share/cmake-2.6/Modules/FindFLTK.cmake:    /usr/local/lib/fltk
/opt/local/share/cmake-2.6/Modules/FindFLTK.cmake:    /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindFLTK.cmake:    /usr/local/fltk
/opt/local/share/cmake-2.6/Modules/FindFLTK.cmake:      /usr/local/fltk
/opt/local/share/cmake-2.6/Modules/FindFLTK.cmake:      /usr/local/fltk/lib
/opt/local/share/cmake-2.6/Modules/FindFLTK2.cmake:    /usr/local/lib/fltk2
/opt/local/share/cmake-2.6/Modules/FindFLTK2.cmake:    /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindFLTK2.cmake:    /usr/local/fltk2
/opt/local/share/cmake-2.6/Modules/FindFLTK2.cmake:      /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindFLTK2.cmake:      /usr/local/fltk2
/opt/local/share/cmake-2.6/Modules/FindFLTK2.cmake:      /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindFLTK2.cmake:      /usr/local/fltk2/lib
/opt/local/share/cmake-2.6/Modules/FindFreetype.cmake:  /usr/local/X11R6/include
/opt/local/share/cmake-2.6/Modules/FindFreetype.cmake:  /usr/local/X11/include
/opt/local/share/cmake-2.6/Modules/FindFreetype.cmake:  /usr/local/X11R6/include
/opt/local/share/cmake-2.6/Modules/FindFreetype.cmake:  /usr/local/X11/include
/opt/local/share/cmake-2.6/Modules/FindFreetype.cmake:  /usr/local/X11R6
/opt/local/share/cmake-2.6/Modules/FindFreetype.cmake:  /usr/local/X11
/opt/local/share/cmake-2.6/Modules/FindGIF.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindGTK.cmake:    /usr/local/include/glib12
/opt/local/share/cmake-2.6/Modules/FindGTK.cmake:    /usr/local/lib/glib/include
/opt/local/share/cmake-2.6/Modules/FindITK-3.12.cmake:    /usr/local/lib/InsightToolkit
/opt/local/share/cmake-2.6/Modules/FindITK.cmake:    /usr/local/lib/InsightToolkit
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/lib/java/jre/lib/i386
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/share/java/jre/lib/i386
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/lib/java/jre/lib/amd64
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/share/java/jre/lib/amd64
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/lib/java/jre/lib/ppc
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/share/java/jre/lib/ppc
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/lib/java/include
/opt/local/share/cmake-2.6/Modules/FindJNI.cmake:  /usr/local/share/java/include
/opt/local/share/cmake-2.6/Modules/FindJava.cmake:  /usr/local/bin
/opt/local/share/cmake-2.6/Modules/FindJava.cmake:  /usr/local/java/bin
/opt/local/share/cmake-2.6/Modules/FindJava.cmake:  /usr/local/java/share/bin
/opt/local/share/cmake-2.6/Modules/FindKDE3.cmake:  /usr/local/include/kde
/opt/local/share/cmake-2.6/Modules/FindLAPACK.cmake:    PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
/opt/local/share/cmake-2.6/Modules/FindLAPACK.cmake:    PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
/opt/local/share/cmake-2.6/Modules/FindLua50.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindLua50.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindLua50.cmake:    /usr/local
/opt/local/share/cmake-2.6/Modules/FindLua51.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindLua51.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindMPEG.cmake:  /usr/local/livid
/opt/local/share/cmake-2.6/Modules/FindMPEG.cmake:  /usr/local/livid/mpeg2dec/libmpeg2/.libs
/opt/local/share/cmake-2.6/Modules/FindMPEG.cmake:  /usr/local/livid/mpeg2dec/libvo/.libs
/opt/local/share/cmake-2.6/Modules/FindMPEG2.cmake:  /usr/local/livid
/opt/local/share/cmake-2.6/Modules/FindMPEG2.cmake:  /usr/local/livid/mpeg2dec/libmpeg2/.libs
/opt/local/share/cmake-2.6/Modules/FindMPEG2.cmake:  /usr/local/livid/mpeg2dec/libvo/.libs
/opt/local/share/cmake-2.6/Modules/FindMPI.cmake:    /usr/local/include 
/opt/local/share/cmake-2.6/Modules/FindMPI.cmake:    /usr/local/mpi/include
/opt/local/share/cmake-2.6/Modules/FindMPI.cmake:    PATHS /usr/lib /usr/local/lib /usr/local/mpi/lib
/opt/local/share/cmake-2.6/Modules/FindMPI.cmake:    PATHS /usr/lib /usr/local/lib /usr/local/mpi/lib
/opt/local/share/cmake-2.6/Modules/FindMatlab.cmake:      /usr/local/matlab-7sp1/bin/glnx86/
/opt/local/share/cmake-2.6/Modules/FindMatlab.cmake:      /usr/local/matlab-7sp1/bin/glnxa64/
/opt/local/share/cmake-2.6/Modules/FindMatlab.cmake:    "/usr/local/matlab-7sp1/extern/include/"
/opt/local/share/cmake-2.6/Modules/FindOpenAL.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindOpenAL.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindPHP4.cmake:  /usr/local/include/php4
/opt/local/share/cmake-2.6/Modules/FindPHP4.cmake:  /usr/local/include/php
/opt/local/share/cmake-2.6/Modules/FindPHP4.cmake:  /usr/local/apache/php
/opt/local/share/cmake-2.6/Modules/FindPNG.cmake:  /usr/local/include/libpng             # OpenBSD
/opt/local/share/cmake-2.6/Modules/FindPhysFS.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindPhysFS.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindPike.cmake:  /usr/local/include/pike/*)
/opt/local/share/cmake-2.6/Modules/FindProducer.cmake:    /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindProducer.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindQt.cmake:FILE(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-3*/bin/qmake)
/opt/local/share/cmake-2.6/Modules/FindQt.cmake:FILE(GLOB GLOB_TEMP_VAR /usr/local/qt-x11-commercial-4*/bin/qmake)
/opt/local/share/cmake-2.6/Modules/FindQt.cmake:FILE(GLOB GLOB_TEMP_VAR /usr/local/Trolltech/Qt-4*/bin/qmake)
/opt/local/share/cmake-2.6/Modules/FindQt.cmake:  /usr/local/qt/include/Qt
/opt/local/share/cmake-2.6/Modules/FindQt.cmake:  /usr/local/include/Qt
/opt/local/share/cmake-2.6/Modules/FindQt.cmake:  /usr/local/qt/include
/opt/local/share/cmake-2.6/Modules/FindQt.cmake:  /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindQt3.cmake:  /usr/local/qt/include
/opt/local/share/cmake-2.6/Modules/FindQt3.cmake:    /usr/local/qt/lib
/opt/local/share/cmake-2.6/Modules/FindQt3.cmake:    /usr/local/qt/lib
/opt/local/share/cmake-2.6/Modules/FindQt3.cmake:  /usr/local/qt/lib
/opt/local/share/cmake-2.6/Modules/FindQt3.cmake:  /usr/local/qt/bin
/opt/local/share/cmake-2.6/Modules/FindQt3.cmake:  /usr/local/qt/bin
/opt/local/share/cmake-2.6/Modules/FindSDL.cmake:  /usr/local/include/SDL
/opt/local/share/cmake-2.6/Modules/FindSDL.cmake:  /usr/local/include/SDL12
/opt/local/share/cmake-2.6/Modules/FindSDL.cmake:  /usr/local/include/SDL11 # FreeBSD ports
/opt/local/share/cmake-2.6/Modules/FindSDL.cmake:  /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindSDL.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindSDL.cmake:      /usr/local
/opt/local/share/cmake-2.6/Modules/FindSDL_image.cmake:  /usr/local/include/SDL
/opt/local/share/cmake-2.6/Modules/FindSDL_image.cmake:  /usr/local/include/SDL12
/opt/local/share/cmake-2.6/Modules/FindSDL_image.cmake:  /usr/local/include/SDL11 # FreeBSD ports
/opt/local/share/cmake-2.6/Modules/FindSDL_image.cmake:  /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindSDL_image.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindSDL_mixer.cmake:  /usr/local/include/SDL
/opt/local/share/cmake-2.6/Modules/FindSDL_mixer.cmake:  /usr/local/include/SDL12
/opt/local/share/cmake-2.6/Modules/FindSDL_mixer.cmake:  /usr/local/include/SDL11 # FreeBSD ports
/opt/local/share/cmake-2.6/Modules/FindSDL_mixer.cmake:  /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindSDL_mixer.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindSDL_net.cmake:  /usr/local/include/SDL
/opt/local/share/cmake-2.6/Modules/FindSDL_net.cmake:  /usr/local/include/SDL12
/opt/local/share/cmake-2.6/Modules/FindSDL_net.cmake:  /usr/local/include/SDL11 # FreeBSD ports
/opt/local/share/cmake-2.6/Modules/FindSDL_net.cmake:  /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindSDL_net.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:  /usr/local/include/SDL
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:  /usr/local/include/SDL12
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:  /usr/local/include/SDL11 # FreeBSD ports
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:  /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:  /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:         /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:         /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:         /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:         /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:         /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:         /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:         /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindSDL_sound.cmake:           /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindSDL_ttf.cmake:  /usr/local/include/SDL
/opt/local/share/cmake-2.6/Modules/FindSDL_ttf.cmake:  /usr/local/include/SDL12
/opt/local/share/cmake-2.6/Modules/FindSDL_ttf.cmake:  /usr/local/include/SDL11 # FreeBSD ports
/opt/local/share/cmake-2.6/Modules/FindSDL_ttf.cmake:  /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindSDL_ttf.cmake:  /usr/local
/opt/local/share/cmake-2.6/Modules/FindSelfPackers.cmake:  /usr/local/bin
/opt/local/share/cmake-2.6/Modules/FindSelfPackers.cmake:  /usr/local/bin
/opt/local/share/cmake-2.6/Modules/FindSquish.cmake:    #/usr/local/squish
/opt/local/share/cmake-2.6/Modules/FindTCL.cmake:  /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindTCL.cmake:  /usr/local/include
/opt/local/share/cmake-2.6/Modules/FindTclStub.cmake:  /usr/local/lib
/opt/local/share/cmake-2.6/Modules/FindUnixCommands.cmake:  /usr/local/bin
/opt/local/share/cmake-2.6/Modules/FindUnixCommands.cmake:  /usr/local/bin
/opt/local/share/cmake-2.6/Modules/FindUnixCommands.cmake:  /usr/local/bin
/opt/local/share/cmake-2.6/Modules/FindUnixCommands.cmake:  /usr/local/bin
/opt/local/share/cmake-2.6/Modules/FindUnixCommands.cmake:  /usr/local/bin
/opt/local/share/cmake-2.6/Modules/FindUnixCommands.cmake:  /usr/local/bin
/opt/local/share/cmake-2.6/Modules/FindVTK.cmake:    /usr/local/lib/vtk
/opt/local/share/cmake-2.6/Modules/GetPrerequisites.cmake:    "/usr/local/bin"

Please see the post-destroot phase for my cmake Portfile at:

https://trac.macports.org/browser/users/dweber/devel/cmake/Portfile

There are some reinplace commands that *add* the MacPorts /opt/local prefix to the VTK and ITK cmake modules. Those modifications could be abstracted into a foreach loop that runs over most, if not all, of the modules listed above. When the MacPorts $prefix is added to the search path with the right precedence, this simple solution could fix this problem for all ports in MacPorts. The cmake port is the right place to make this change.

If I get time, I will see about testing further modifications that will modify all the module .cmake files listed above. There may be some specific requirements for particular ports, where they use install paths that are not simply a replacement of /usr/local/ for /opt/local/.

Darren

comment:7 Changed 15 years ago by dweber@…

Description: modified (diff)
Note: See TracTickets for help on using tickets.