Internal vs system version of a library

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Internal vs system version of a library

Antonio Valentino
Hi list,
I would like allow the user to choose whenever to use the system
version of a library or the developer provided one.

In the code snippet below the library is FFTW and its source archive is
bundled together with the project source in the COTS/FFTW sub-folder.

The problem is how to reset the cache variables once the user switches
between USE_INTERNAL_FFTW and NOT USE_INTERNAL_FFTW.

In the following code snippet there is my tentative solution.
It seems to work but it doesn't looks good to me.
In particular there is some code duplication and then I would like to
generalize it a little bit the code and put it into a MACRO or such.

I would like to receive comments/suggestions from some user more expert
than me.


# BEGIN CODE ######################
# cache reset
IF(DEFINED USE_INTERNAL_FFTW_GUARD)
    IF(USE_INTERNAL_FFTW_GUARD STREQUAL "${USE_INTERNAL_FFTW}")
        MESSAGE(STATUS "USE_INTERNAL_FFTW not changed")
    ELSE(USE_INTERNAL_FFTW_GUARD STREQUAL "${USE_INTERNAL_FFTW}")
        MESSAGE(STATUS "USE_INTERNAL_FFTW changed")

        IF(USE_INTERNAL_FFTW)
            # @TODO: rewrite
            SET(FFTWROOT ${COTS_BINARY_DIR}/FFTW/fftw-3.2.2)
            SET(FFTW_INCLUDE_PATH ${FFTWROOT}/api)
            SET(FFTWF_LIB ${FFTWROOT}/.libs/libfftw3f.so)
            SET(FFTWF_THREADS_LIB "FFTWF_THREADS_LIB-NOTFOUND")
        ELSE(USE_INTERNAL_FFTW)
            SET(USE_FFTWF true)
            SET(FFTW_INCLUDE_PATH "FFTW_INCLUDE_PATH-NOTFOUND")
            SET(FFTWF_LIB "FFTWF_LIB-NOTFOUND")
            SET(FFTWF_THREADS_LIB "FFTWF_THREADS_LIB-NOTFOUND")
            FIND_PACKAGE(FFTW REQUIRED)
        ENDIF(USE_INTERNAL_FFTW)

        SET(FFTW_INCLUDE_PATH ${FFTW_INCLUDE_PATH}
            CACHE PATH "FFTW include path."
            FORCE)
        SET(FFTWF_LIB ${FFTWF_LIB}
            CACHE FILEPATH "FFTW library path."
            FORCE)
        SET(FFTWF_THREADS_LIB ${FFTWF_THREADS_LIB}
            CACHE FILEPATH "FFTW threaded library path."
            FORCE)
    ENDIF(USE_INTERNAL_FFTW_GUARD STREQUAL "${USE_INTERNAL_FFTW}")
ENDIF(DEFINED USE_INTERNAL_FFTW_GUARD)

SET(USE_INTERNAL_FFTW_GUARD ${USE_INTERNAL_FFTW}
    CACHE INTERNAL "Guard for USE_INTERNAL_FFTW_GUARD")


IF(USE_INTERNAL_FFTW)
    # @TODO: rewrite
    SET(FFTWROOT ${COTS_BINARY_DIR}/FFTW/fftw-3.2.2)

    SET(FFTW_INCLUDE_PATH ${FFTWROOT}/api CACHE PATH "FFTW include
    path.") SET(FFTWF_LIB ${FFTWROOT}/.libs/libfftw3f.so
        CACHE FILEPATH "FFTW library path.")
    SET(FFTWF_THREADS_LIB "FFTWF_THREADS_LIB-NOTFOUND"
        CACHE FILEPATH "FFTW threaded library path.")

    INCLUDE_DIRECTORIES(BEFORE ${FFTW_INCLUDE_PATH})
ELSE(USE_INTERNAL_FFTW)
    SET(USE_FFTWF true)
    FIND_PACKAGE(FFTW REQUIRED)
ENDIF(USE_INTERNAL_FFTW)

# END CODE ######################

Thanks in advance.

--
Antonio Valentino
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Internal vs system version of a library

Hendrik Sattler
Zitat von Antonio Valentino <[hidden email]>:
> I would like allow the user to choose whenever to use the system
> version of a library or the developer provided one.
>
> In the code snippet below the library is FFTW and its source archive is
> bundled together with the project source in the COTS/FFTW sub-folder.
>
> The problem is how to reset the cache variables once the user switches
> between USE_INTERNAL_FFTW and NOT USE_INTERNAL_FFTW.

unset()

> In the following code snippet there is my tentative solution.
> It seems to work but it doesn't looks good to me.

The guard is good to detect a change in the user variable (which could  
be given using option().

HS


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Internal vs system version of a library

Antonio Valentino
Il giorno Thu, 06 Aug 2009 12:04:06 +0200
Hendrik Sattler <[hidden email]> ha scritto:

> Zitat von Antonio Valentino <[hidden email]>:
> > I would like allow the user to choose whenever to use the system
> > version of a library or the developer provided one.
> >
> > In the code snippet below the library is FFTW and its source
> > archive is bundled together with the project source in the
> > COTS/FFTW sub-folder.
> >
> > The problem is how to reset the cache variables once the user
> > switches between USE_INTERNAL_FFTW and NOT USE_INTERNAL_FFTW.
>
> unset()

The unset command seems to be undocumented in cmake 2.6.2 (the one
packaged in ubuntu jaunty).
Is it new?

> > In the following code snippet there is my tentative solution.
> > It seems to work but it doesn't looks good to me.
>
> The guard is good to detect a change in the user variable (which
> could be given using option().

Yes USE_INTERNAL_FFTW is defined as an option in another part of the
code.


thanks

--
Antonio Valentino
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Internal vs system version of a library

Tyler Roscoe
On Thu, Aug 06, 2009 at 12:43:05PM +0200, Antonio Valentino wrote:
> The unset command seems to be undocumented in cmake 2.6.2 (the one
> packaged in ubuntu jaunty).
> Is it new?

Newer than 2.6.2, yes. Not sure if it's different for cache variables
but you can use set(myVar) in 2.6.2 to get the same effect for regular
variables.

tyler
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Internal vs system version of a library

Antonio Valentino
Il giorno Thu, 6 Aug 2009 08:49:27 -0700
Tyler Roscoe <[hidden email]> ha scritto:

> On Thu, Aug 06, 2009 at 12:43:05PM +0200, Antonio Valentino wrote:
> > The unset command seems to be undocumented in cmake 2.6.2 (the one
> > packaged in ubuntu jaunty).
> > Is it new?
>
> Newer than 2.6.2, yes. Not sure if it's different for cache variables
> but you can use set(myVar) in 2.6.2 to get the same effect for regular
> variables.
>
> tyler

Hi Tyler,
I just made a couple of quick test and it seems to me that the
'set(myVar)' syntax is equivalent to 'set(myVar "")'.

This solution doesn't work in my case since variables are actually
reset but they are not correctly updated in the following code:
FFTW_INCLUDE_PATH, FFTWF_LIB and FFTWF_THREADS_LIB remain empty after
USE_INTERNAL_FFTW switch.

thanks.

--
Antonio Valentino
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake