Tyler Roscoe wrote:
On Wed, Oct 14, 2009 at 04:59:17PM +0200, Theodore Papadopoulo wrote:
We have a project which can be built either with static or dynamic libraries. The toggle is defined via an option named BUILD_SHARED which has some default value (let's say static).

Unfortunately, after the first "configure" in ccmake all the libraries are set to their values corresponding to the default static choice (typically .a files) and then changing the BUILD_SHARED option to shared
never recomputes the proper library names (still the .a files).

I think we'll need to see some code from your CMakeLists, but are you
familiar with set(... CACHE)?
Not enough apparently.... Anyway thanks for the answer, it opened some perspectives.
Here is some simple CMakeList.txt at the end of this mail.

After the first configure the library selected is liblapack.so, then if you change the value of the option BUILD_SHARED and re-configure, the library remains liblapack.so instead of the
expected liblapack.a.

Uncommenting the commented line, indeed forces the discovery of the libraries at each configure, but we were wondering whether there is a way of doing so only if eg CMAKE_FIND_LIBRARY_SUFFIXES
is changed, hence the original question. I hope that this is now clearer.

Inserting something along the lines of:

   IF ( BUILD_SHARED )
       SET(LIB_TYPE SHARED)
   ELSE ( BUILD_SHARED )
       SET(LIB_TYPE STATIC)
   ENDIF ( BUILD_SHARED )

STRING(COMPARE NOTEQUAL "${BUILD_SHARED_STATUS}" "" BUILD_SHARED_STATUS_NOT_EMPTY)
   IF(BUILD_SHARED_STATUS_NOT_EMPTY)
STRING(COMPARE NOTEQUAL "${BUILD_SHARED_STATUS}" "${BUILD_SHARED}" RESET)
       IF(${RESET})
           # MESSAGE("Reset")
SET(LAPACK_ATLAS_LIB NOTFOUND CACHE STRING "Atlas Lib" FORCE)
       ENDIF()
   ENDIF()

   # Store in cache previous value of BUILD_SHARED
SET(BUILD_SHARED_STATUS "${BUILD_SHARED}" CACHE STRING "Build shared status (do not modify)" FORCE)
   MARK_AS_ADVANCED(BUILD_SHARED_STATUS)

Seems not work but is not very elegant and there is the risk that some user using the advanced toggle plays with the BUILD_SHARED_STATUS variable. So I wondered whether there is a better solution. Obviously, ideally, FIND_LIBRARY would detect that CMAKE_FIND_LIBRARY_SUFFIXES has changed and would update the libraries,
but I probably demand too much

Thank's for any hint.

   Theo.

PROJECT(Test)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

OPTION(BUILD_SHARED "BUILD_SHARED" ON)

IF(BUILD_SHARED)
   SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
ELSE ()
   SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
ENDIF()

#SET(TEST_LIB NOTFOUND CACHE STRING "Lib" FORCE)

FIND_LIBRARY(TEST_LIB lapack)

MESSAGE(${TEST_LIB})
_______________________________________________
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 via email to