CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

Unitialized variable warnings

Open FuturehomeDinoSaric opened this issue 3 years ago • 7 comments

When using the latest version of CPM.cmake (0.37.0) and configuring the cmake with flags --warn-unused-vars and --warn-uninitialized I get warnings:

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:105 (option):
  uninitialized variable 'CPM_USE_LOCAL_PACKAGES'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:108 (option):
  uninitialized variable 'CPM_LOCAL_PACKAGES_ONLY'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:111 (option):
  uninitialized variable 'CPM_DOWNLOAD_ALL'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:112 (option):
  uninitialized variable 'CPM_DONT_UPDATE_MODULE_PATH'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:115 (option):
  uninitialized variable 'CPM_DONT_CREATE_PACKAGE_LOCK'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:118 (option):
  uninitialized variable 'CPM_INCLUDE_ALL_IN_PACKAGE_LOCK'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:122 (option):
  uninitialized variable 'CPM_USE_NAMED_CACHE_DIRECTORIES'
Call Stack (most recent call first):
  test/CMakeLists.txt:1 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:622 (if):
  uninitialized variable 'CPM_Catch2_SOURCE'
Call Stack (most recent call first):
  test/CMakeLists.txt:3 (CPMAddPackage)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:639 (if):
  uninitialized variable 'CPM_DECLARATION_Catch2'
Call Stack (most recent call first):
  test/CMakeLists.txt:3 (CPMAddPackage)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- CPM: Adding package [email protected] (v3.3.1)
CMake Warning (dev) at cmake-build-debug-armv6/_deps/catch2-src/CMake/CatchConfigOptions.cmake:71 (set):
  uninitialized variable 'BUILD_SHARED_LIBS'
Call Stack (most recent call first):
  cmake-build-debug-armv6/_deps/catch2-src/CMakeLists.txt:55 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Performing Test HAVE_FLAG__ffile_prefix_map__home_lola_Desktop_future_home_core_vinculum_cmake_build_debug_armv6__deps_catch2_src__
-- Performing Test HAVE_FLAG__ffile_prefix_map__home_lola_Desktop_future_home_core_vinculum_cmake_build_debug_armv6__deps_catch2_src__ - Success
CMake Warning (dev) at cmake-build-debug-armv6/cmake/cpm/CPM.cmake:796 (if):
  uninitialized variable 'download_directory'
Call Stack (most recent call first):
  test/CMakeLists.txt:3 (CPMAddPackage)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done

FuturehomeDinoSaric avatar Jan 30 '23 15:01 FuturehomeDinoSaric

Hey, thanks for raising the issue! I wasn't aware of these checks and agree that CPM should not create warnings if possible. Once we manage to resolve it, probably it would be a good idea to add these checks in CI as well.

TheLartians avatar Feb 19 '23 14:02 TheLartians

I believe I'm having the same problem. I tried bumping CPM to v0.38.1 and using the SYSTEM keyword to resolve this but it did not. Would you expect that to fix this or is it a separate issue?

fng97 avatar May 12 '23 16:05 fng97

I don't think setting the SYSTEM keyword would help here, we rather should initialise the variables with reasonable defaults.

TheLartians avatar May 22 '23 18:05 TheLartians

I don't think setting the SYSTEM keyword would help here, we rather should initialise the variables with reasonable defaults.

Sorry, still very new to CMake. I'm not too sure what you mean by the above. However, the following fixed my problem. I suppressed the warning emitted by the dependency using target_compile_options. Does this seem appropriate to you?

CPMAddPackage("gh:pboettch/json-schema-validator#2.2.0")

target_compile_options(nlohmann_json_schema_validator PRIVATE -Wno-error=unused-const-variable)

fng97 avatar May 23 '23 13:05 fng97

@fng97 I think we're confusing warnings coming from CMake and the C / C++ compiler. From my understanding this issue is about CMake warning that CPM specific variables are not properly initialised in CMake. Your fix targets compiler options relevant for building the actual C / C++ source code.

TheLartians avatar May 29 '23 11:05 TheLartians

@TheLartians

@fng97 I think we're confusing warnings coming from CMake and the C / C++ compiler. From my understanding this issue is about CMake warning that CPM specific variables are not properly initialised in CMake. Your fix targets compiler options relevant for building the actual C / C++ source code.

Oops, I think you're right 😅

fng97 avatar May 30 '23 07:05 fng97