cellml / libcellml

Repository for libCellML development.
https://libcellml.org
Apache License 2.0
17 stars 21 forks source link

CMake: variables passed to `cmake` cannot be changed afterwards #963

Closed agarny closed 3 years ago

agarny commented 3 years ago

Say that I do the following:

cd /path/to/libcellml
mkdir build
cd build
ccmake -G Ninja .. -DBUILD_SHARED=OFF

After I configure libCellML, I will in my case get:

 LIBCELLML_BINDINGS_PYTHON       *ON
 LIBCELLML_BUILD_SHARED          *OFF
 LIBCELLML_BUILD_TYPE            *Debug
 LIBCELLML_CLANG_TIDY            *OFF
 LIBCELLML_COMPILER_CACHE        *ON
 LIBCELLML_COVERAGE              *ON
 LIBCELLML_ENABLE_UTILITIES      *OFF
 LIBCELLML_INSTALL_PREFIX        */usr/local
 LIBCELLML_LLVM_COVERAGE         *ON
 LIBCELLML_PYTHON_COVERAGE       *ON
 LIBCELLML_TREAT_WARNINGS_AS_ER  *ON
 LIBCELLML_UNIT_TESTS            *ON

From there, if I set LIBCELLML_BUILD_SHARED to ON and reconfigure, I still get the above output. In other words, LIBCELLML_BUILD_SHARED cannot be modified if a value for BUILD_SHARED has been passed to cmake/ccmake.

For what it is worth, this can be fixed by replacing:

set(_PARAM_ANNOTATION "Build shared libraries (so, dylib, DLLs).")
if (EMSCRIPTEN)
  set(LIBCELLML_BUILD_SHARED OFF CACHE INTERNAL "${_PARAM_ANNOTATION}")
else()
  set(LIBCELLML_BUILD_SHARED ON CACHE BOOL "${_PARAM_ANNOTATION}")
  if(DEFINED BUILD_SHARED)
    set(LIBCELLML_BUILD_SHARED ${BUILD_SHARED} CACHE BOOL "${_PARAM_ANNOTATION}" FORCE)
  endif()
  unset(BUILD_SHARED CACHE)
endif()

with:

if(NOT LIBCELLML_BUILD_SHARED_SET)
  set(_PARAM_ANNOTATION "Build shared libraries (so, dylib, DLLs).")
  if (EMSCRIPTEN)
    set(LIBCELLML_BUILD_SHARED OFF CACHE INTERNAL "${_PARAM_ANNOTATION}")
  else()
    set(LIBCELLML_BUILD_SHARED ON CACHE BOOL "${_PARAM_ANNOTATION}")
    if(DEFINED BUILD_SHARED)
      set(LIBCELLML_BUILD_SHARED ${BUILD_SHARED} CACHE BOOL "${_PARAM_ANNOTATION}" FORCE)
    endif()
  endif()
  set(LIBCELLML_BUILD_SHARED_SET ON CACHE INTERNAL "LIBCELLML_BUILD_SHARED has been set.")
endif()

(The same applies to the other libCellML-related variables.)

hsorby commented 3 years ago

ccmake is a GUI configuration application and the behaviour there is different. If you instead configure with cmake -G Ninja .. -DBUILD_SHARED=OFF and then use ccmake. You will get the desired behaviour. The behaviour that you see is the expected behaviour.

agarny commented 3 years ago

Hmm... fair point.