Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake_minimum_required and sub-projects

Tags:

I really enjoy having my top-level project, driving compilation of my sub-projects. I currently have a tree such as:

gdcm -- cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR)
├── Utilities
│   ├── gdcmcharls -- cmake_minimum_required(VERSION 2.8.7)

I'd like to keep this as close as possible to each different upstream projects I have a convienent copy of. However when I'd like to test a new feature of CMake, I cannot simply change the top-level CMakeList.txt file and hope that new policies will be transmitted to individual sub-project (by definition of the nested command cmake_minimum_required).

Is there an idiom to say something like:

if(TOPLEVEL PROJECT)
cmake_minimum_required(VERSION 2.8.7)
else()
cmake_minimum_required(VERSION ${INHERITED_VERSION})
endif()
like image 213
malat Avatar asked Dec 05 '18 21:12

malat


1 Answers

Something like this should work:

if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION)
  cmake_minimum_required(VERSION 2.8.7)
endif()

I would not call cmake_minimum_required if it's already defined, since this will overwrite the policies that you manually set in your main project.

like image 52
Daniele E. Domenichelli Avatar answered Nov 15 '22 05:11

Daniele E. Domenichelli