error.huntergate.before.project¶
What happens¶
CMake fatal error with message:
[hunter ** FATAL ERROR **] Please set HunterGate *before* project command
Explanation¶
- Hunter designed to set some internal stuff like
CMAKE_CXX_COMPILER. Such variables must be modified beforeprojectcommand to work correctly
What to do¶
In general sequence must looks like this (see also error.hunteraddpackage.after.project):
# Check CMake version before any commands cmake_minimum_required(VERSION 3.2) # Load HunterGate module include("cmake/HunterGate.cmake") # Use HunterGate module before first `project` command HunterGate( URL ... SHA1 ... ) # Your project (must exist, see note below) project(Foo) # Use hunter_add_package after project command hunter_add_package(Boo)
Note that if there is no
projectcommand inCMakeLists.txtthen CMake will setPROJECT_NAMEtoProjectwhich is same side-effect as callingproject(Project)beforeHunterGate. It means there must be at least oneprojectcall inCMakeLists.txt(which usually quite normal requirement). Related: https://github.com/ruslo/hunter/issues/285. Quite the same will happen ifprojectcommand is in subdirectory so next code will not work too:# CMakeLists.txt cmake_minimum_required(VERSION 3.2) include("cmake/HunterGate.cmake") HunterGate(URL ... SHA1 ...) add_subdirectory(subdir1)
# subdir1/CMakeLists.txt project(Foo)
Fix is to place
projectin topCMakeLists.txtbeforeadd_subdirectory:# CMakeLists.txt cmake_minimum_required(VERSION 3.2) include("cmake/HunterGate.cmake") HunterGate(URL ... SHA1 ...) project(Foo) # <--------------- before add_subdirectory add_subdirectory(subdir1)