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 beforeproject
command 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
project
command inCMakeLists.txt
then CMake will setPROJECT_NAME
toProject
which is same side-effect as callingproject(Project)
beforeHunterGate
. It means there must be at least oneproject
call inCMakeLists.txt
(which usually quite normal requirement). Related: https://github.com/ruslo/hunter/issues/285. Quite the same will happen ifproject
command 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
project
in topCMakeLists.txt
beforeadd_subdirectory
:# CMakeLists.txt cmake_minimum_required(VERSION 3.2) include("cmake/HunterGate.cmake") HunterGate(URL ... SHA1 ...) project(Foo) # <--------------- before add_subdirectory add_subdirectory(subdir1)