[CMake] Internal vs system version of a library

Antonio Valentino antonio.valentino at tiscali.it
Thu Aug 6 04:55:16 EDT 2009


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


More information about the CMake mailing list