]> OCCT Git - occt.git/commitdiff
0032921: require minimum CMAKE version 3.1 (for enabling CMAKE_CXX_STANDARD)
authorddzama <dmitry.dzama@opencascade.com>
Fri, 8 Apr 2022 11:43:59 +0000 (14:43 +0300)
committerddzama <ddzama@opencascade.com>
Mon, 29 Aug 2022 09:47:38 +0000 (12:47 +0300)
If we require CMAKE minimal version 3.1, rather than 2.8,
by default new policies are employed:
from CMP0024 to CMP0054.
Unique problematic policy is CMP0054:
`Only interpret if() arguments as variables or keywords when unquoted.`

Requiring of 3.1 as minimal version without preserving old behavior of 54th policy breaks MSVC compilation.
If we require cmake_policy (SET CMP0054 OLD), compilation finishs without errors.
New behavior of CMP0054 leads to changes in next target MSVC vcxproj files:
 - TKV3d
 - TKOpenGl
 - TKOpenGlTest
 - TKOpenGles
 - TKOpenGlesTest
Difference is absense of HAVE_OPENGL/HAVE_OPENGLES definitions.
So, source of error has been localizedin file occt_toolkit.cmake, in lines ~325 and ~327.
In accordance with old CMP0054 policy "CSF_OpenGlLibs" interprets as variable CSF_OpenGlLibs, rather than just a string.
Contrary, new policy interpret "CSF_OpenGlLibs" as a string.
To employ new policy, began since CMAKE 3.1 we should replace "CSF_OpenGlLibs" to "${CSF_OpenGlLibs}"
and "CSF_OpenGlesLibs" to "${CSF_OpenGlesLibs}".

P.S.

When cmake policy CMP0054 is set to NEW
expression
  "${CURRENT_CSF}" STREQUAL "CSF_OpenGlLibs"
is false,
while if policy CMP0054 is set to OLD
expression
  "${CURRENT_CSF}" STREQUAL "CSF_OpenGlLibs"
is true.
If replace "CSF_OpenGlLibs" to "${CSF_OpenGlLibs}"
expression is true independent on CMP0054 policy.
Notice, that OLD policy had beed taken place by default on master before
this ticket integration.

14 files changed:
CMakeLists.txt
adm/cmake/cotire.cmake
adm/cmake/occt_defs_flags.cmake
adm/cmake/occt_macros.cmake
adm/cmake/occt_toolkit.cmake
samples/glfw/CMakeLists.txt
samples/java/jniviewer/app/src/main/jni/CMakeLists.txt
samples/mfc/standard/01_Geometry/CMakeLists.txt
samples/mfc/standard/02_Modeling/CMakeLists.txt
samples/mfc/standard/03_ImportExport/CMakeLists.txt
samples/mfc/standard/04_HLR/CMakeLists.txt
samples/mfc/standard/mfcsample/CMakeLists.txt
samples/webgl/CMakeLists.txt
tools/CMakeLists.txt

index feaff8d4ee9c4fce04e0a9eca6db0d907bf93a1e..6106dff8021d25fdbd05e01a9d9f7c07033935da 100644 (file)
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
+cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
 
 set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/adm/cmake")
 
index a63f3ceaf3980eaf8d59683e404c27a7d1f0ad94..b8b98a71196abceb39fed5d09470fd916a31c8af 100644 (file)
@@ -32,15 +32,13 @@ if(__COTIRE_INCLUDED)
 endif()
 set(__COTIRE_INCLUDED TRUE)
 
-# call cmake_minimum_required, but prevent modification of the CMake policy stack in include mode
-# cmake_minimum_required also sets the policy version as a side effect, which we have to avoid
-if (NOT CMAKE_SCRIPT_MODE_FILE)
-       cmake_policy(PUSH)
-endif()
-cmake_minimum_required(VERSION 2.8.12)
-if (NOT CMAKE_SCRIPT_MODE_FILE)
-       cmake_policy(POP)
-endif()
+# Caution! Be careful, when increase minimal cmake version:
+# using of newer version may leads (by default) to applying
+# of some new policies. It may break compilation.
+# For canceling of applying new policies use:
+# cmake_policy(PUSH) before `cmake_minimum_required`
+# and cmake_policy(POP) after.
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 
 set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}")
 set (COTIRE_CMAKE_MODULE_VERSION "1.7.9")
index 8da7008322da563ff0ca720fd2692e743028ad85..601782366a99c8dc5b3fd34c20f806a4e7b590eb 100644 (file)
@@ -144,6 +144,7 @@ elseif ("${BUILD_CPP_STANDARD}" STREQUAL "C++23")
 else ()
   message (FATAL_ERROR, "misprint in c++ standard name")
 endif()
+set (CMAKE_CXX_STANDARD_REQUIRED ON)
 
 if ("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang")
   if (APPLE)
index 0a38794527ef0d66421504f07482bdf015c7bbba..4a060665f698c73db6995d3fc3c8011c93e0137b 100644 (file)
@@ -80,9 +80,9 @@ macro (OCCT_MAKE_COMPILER_SHORT_NAME)
     set (COMPILER gcc)
   elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX)
     set (COMPILER gxx)
-  elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+  elseif (CMAKE_CXX_COMPILER_ID MATCHES "[Cc][Ll][Aa][Nn][Gg]")
     set (COMPILER clang)
-  elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
+  elseif (CMAKE_CXX_COMPILER_ID MATCHES "[Ii][Nn][Tt][Ee][Ll]")
     set (COMPILER icc)
   else()
     set (COMPILER ${CMAKE_GENERATOR})
@@ -589,9 +589,7 @@ macro (OCCT_UPDATE_TARGET_FILE)
   endif()
 
   install (CODE
-  "cmake_policy(PUSH)
-  cmake_policy(SET CMP0007 NEW)
-  string (TOLOWER \"\${CMAKE_INSTALL_CONFIG_NAME}\" CMAKE_INSTALL_CONFIG_NAME_LOWERCASE)
+  "string (TOLOWER \"\${CMAKE_INSTALL_CONFIG_NAME}\" CMAKE_INSTALL_CONFIG_NAME_LOWERCASE)
   file (GLOB ALL_OCCT_TARGET_FILES \"${INSTALL_DIR}/${INSTALL_DIR_CMAKE}/OpenCASCADE*Targets-\${CMAKE_INSTALL_CONFIG_NAME_LOWERCASE}.cmake\")
   foreach(TARGET_FILENAME \${ALL_OCCT_TARGET_FILES})
     file (STRINGS \"\${TARGET_FILENAME}\" TARGET_FILE_CONTENT)
@@ -600,8 +598,7 @@ macro (OCCT_UPDATE_TARGET_FILE)
       string (REGEX REPLACE \"[\\\\]?[\\\$]{OCCT_INSTALL_BIN_LETTER}\" \"\${OCCT_INSTALL_BIN_LETTER}\" line \"\${line}\")
       file (APPEND \"\${TARGET_FILENAME}\" \"\${line}\\n\")
     endforeach()
-  endforeach()
-  cmake_policy(POP)")
+  endforeach()")
 endmacro()
 
 macro (OCCT_INSERT_CODE_FOR_TARGET)
@@ -615,17 +612,14 @@ macro (OCCT_INSERT_CODE_FOR_TARGET)
 endmacro()
 
 macro (OCCT_UPDATE_DRAW_DEFAULT_FILE)
-  install(CODE "cmake_policy(PUSH)
-  cmake_policy(SET CMP0007 NEW)
-  set (DRAW_DEFAULT_FILE_NAME \"${INSTALL_DIR}/${INSTALL_DIR_RESOURCE}/DrawResources/DrawPlugin\")
+  install(CODE "set (DRAW_DEFAULT_FILE_NAME \"${INSTALL_DIR}/${INSTALL_DIR_RESOURCE}/DrawResources/DrawPlugin\")
   file (STRINGS \"\${DRAW_DEFAULT_FILE_NAME}\" DRAW_DEFAULT_CONTENT)
   file (REMOVE \"\${DRAW_DEFAULT_FILE_NAME}\")
   foreach (line IN LISTS DRAW_DEFAULT_CONTENT)
     string (REGEX MATCH \": TK\([a-zA-Z]+\)$\" IS_TK_LINE \"\${line}\")
     string (REGEX REPLACE \": TK\([a-zA-Z]+\)$\" \": TK\${CMAKE_MATCH_1}${BUILD_SHARED_LIBRARY_NAME_POSTFIX}\" line \"\${line}\")
     file (APPEND \"\${DRAW_DEFAULT_FILE_NAME}\" \"\${line}\\n\")
-  endforeach()
-  cmake_policy(POP)")
+  endforeach()")
 endmacro()
 
 macro (OCCT_CREATE_SYMLINK_TO_FILE LIBRARY_NAME LINK_NAME)
index ed5f142a1da090272ffa63e45eabcc683a6ef13e..9d1f16cdc11558f87c6700ac242400a11980d0db 100644 (file)
@@ -320,10 +320,10 @@ foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS})
       else() # get CSF_ value
         set (CURRENT_CSF ${${USED_ITEM}})
         if (NOT "x${CURRENT_CSF}" STREQUAL "x")
-          if ("${CURRENT_CSF}" STREQUAL "CSF_OpenGlLibs")
+          if ("${CURRENT_CSF}" STREQUAL "${CSF_OpenGlLibs}")
             add_definitions (-DHAVE_OPENGL)
           endif()
-          if ("${CURRENT_CSF}" STREQUAL "CSF_OpenGlesLibs")
+          if ("${CURRENT_CSF}" STREQUAL "${CSF_OpenGlesLibs}")
             add_definitions (-DHAVE_GLES2)
           endif()
 
index d40add62ce4276891e9df439020a064bb9a581a1..c647b135190961af0a5d4c0b5f18e28ee5e7409e 100644 (file)
@@ -4,7 +4,6 @@ project(glfw-occt-demo)
 
 set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/adm/cmake" ${CMAKE_MODULE_PATH})
 
-set(CMAKE_CXX_STANDARD 11)
 set(APP_VERSION_MAJOR 1)
 set(APP_VERSION_MINOR 0)
 set(APP_TARGET glfwocct)
index eb41dc6fa0d361add551715a97bdc93a3e65b06f..e399de76011b30f9d986db37e458488ffeb8bc44 100644 (file)
@@ -37,7 +37,7 @@ list(APPEND aLibDeps lib_FreeType)
 # system libraries
 list(APPEND aLibDeps EGL GLESv2 log android)
 
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${CMAKE_CXX_STANDARD} -Wall -frtti -fexceptions -fpermissive")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -frtti -fexceptions -fpermissive")
 
 add_library(TKJniSample SHARED ${SOURCE_FILES})
 target_link_libraries(TKJniSample ${aLibDeps})
index 62d612231f598c8eef9be31772d70ef653dd7ac5..0e4a25598ef604871e55dad452955619f4d92b7c 100644 (file)
@@ -1,4 +1,10 @@
-cmake_minimum_required (VERSION 2.6)
+# Caution! Be careful, when increase minimal cmake version:
+# using of newer version may leads (by default) to applying
+# of some new policies. It may break compilation.
+# For canceling of applying new policies use:
+# cmake_policy(PUSH) before `cmake_minimum_required`
+# and cmake_policy(POP) after.
+cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
 
 project (Geometry)
 
index 6a690ba8346f949c0f59722a0da2a03d6d7cade0..29b562d013549345e966f40433177c5615e58be8 100644 (file)
@@ -1,4 +1,10 @@
-cmake_minimum_required (VERSION 2.6)
+# Caution! Be careful, when increase minimal cmake version:
+# using of newer version may leads (by default) to applying
+# of some new policies. It may break compilation.
+# For canceling of applying new policies use:
+# cmake_policy(PUSH) before `cmake_minimum_required`
+# and cmake_policy(POP) after.
+cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
 
 project (Modeling)
 
index 93f728e36cabe2d4ff3320a0a24dcbeb9edf5013..c0e975516cfc6c4be9b327009e474d0ca37efcad 100644 (file)
@@ -1,4 +1,10 @@
-cmake_minimum_required (VERSION 2.6)
+# Caution! Be careful, when increase minimal cmake version:
+# using of newer version may leads (by default) to applying
+# of some new policies. It may break compilation.
+# For canceling of applying new policies use:
+# cmake_policy(PUSH) before `cmake_minimum_required`
+# and cmake_policy(POP) after.
+cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
 
 project (ImportExport)
 
index 68785a28cf2120bb8d99a41af580bf1392529f55..14c8cc38503add1df48472fc45725dad088bc1c2 100644 (file)
@@ -1,4 +1,10 @@
-cmake_minimum_required (VERSION 2.6)
+# Caution! Be careful, when increase minimal cmake version:
+# using of newer version may leads (by default) to applying
+# of some new policies. It may break compilation.
+# For canceling of applying new policies use:
+# cmake_policy(PUSH) before `cmake_minimum_required`
+# and cmake_policy(POP) after.
+cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
 
 project (HLR)
 
index 8b759a89d815241e7c7f088cf3869a0f89cf0053..55c6e49159d4514a8d9e53646e7ba396a53795d9 100644 (file)
@@ -1,4 +1,10 @@
-cmake_minimum_required (VERSION 2.6)
+# Caution! Be careful, when increase minimal cmake version:
+# using of newer version may leads (by default) to applying
+# of some new policies. It may break compilation.
+# For canceling of applying new policies use:
+# cmake_policy(PUSH) before `cmake_minimum_required`
+# and cmake_policy(POP) after.
+cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
 
 project (mfcsample)
 
index 5a2a323aa9737921784bd47a7a732effc864521a..4991d154e492d5f8c7b99fcd37f3f42bcf42810f 100644 (file)
@@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.2)
 
 project(occt-webgl-sample)
 
-set(CMAKE_CXX_STANDARD 11)
 set(APP_VERSION_MAJOR 1)
 set(APP_VERSION_MINOR 0)
 set(APP_TARGET occt-webgl-sample)
index f73a2d824b15c810c554b4db2a5db4b847165591..beb934f72081d8bd0dad2e096129c6f560fe7b0d 100644 (file)
@@ -1,4 +1,10 @@
-cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
+# Caution! Be careful, when increase minimal cmake version:
+# using of newer version may leads (by default) to applying
+# of some new policies. It may break compilation.
+# For canceling of applying new policies use:
+# cmake_policy(PUSH) before `cmake_minimum_required`
+# and cmake_policy(POP) after.
+cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
 
 set (ADDITIONAL_INLCUDE_DIR_DESCR "Additional directory to be added in the projects include section")
 if (NOT DEFINED ADDITIONAL_INLCUDE_DIR)