From: ddzama Date: Fri, 8 Apr 2022 11:43:59 +0000 (+0300) Subject: 0032921: require minimum CMAKE version 3.1 (for enabling CMAKE_CXX_STANDARD) X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=8271ac67280aa7a22828d619bd320e4af8701002;p=occt.git 0032921: require minimum CMAKE version 3.1 (for enabling CMAKE_CXX_STANDARD) 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. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index feaff8d4ee..6106dff802 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/adm/cmake/cotire.cmake b/adm/cmake/cotire.cmake index a63f3ceaf3..b8b98a7119 100644 --- a/adm/cmake/cotire.cmake +++ b/adm/cmake/cotire.cmake @@ -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") diff --git a/adm/cmake/occt_defs_flags.cmake b/adm/cmake/occt_defs_flags.cmake index 8da7008322..601782366a 100644 --- a/adm/cmake/occt_defs_flags.cmake +++ b/adm/cmake/occt_defs_flags.cmake @@ -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) diff --git a/adm/cmake/occt_macros.cmake b/adm/cmake/occt_macros.cmake index 0a38794527..4a060665f6 100644 --- a/adm/cmake/occt_macros.cmake +++ b/adm/cmake/occt_macros.cmake @@ -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) diff --git a/adm/cmake/occt_toolkit.cmake b/adm/cmake/occt_toolkit.cmake index ed5f142a1d..9d1f16cdc1 100644 --- a/adm/cmake/occt_toolkit.cmake +++ b/adm/cmake/occt_toolkit.cmake @@ -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() diff --git a/samples/glfw/CMakeLists.txt b/samples/glfw/CMakeLists.txt index d40add62ce..c647b13519 100644 --- a/samples/glfw/CMakeLists.txt +++ b/samples/glfw/CMakeLists.txt @@ -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) diff --git a/samples/java/jniviewer/app/src/main/jni/CMakeLists.txt b/samples/java/jniviewer/app/src/main/jni/CMakeLists.txt index eb41dc6fa0..e399de7601 100644 --- a/samples/java/jniviewer/app/src/main/jni/CMakeLists.txt +++ b/samples/java/jniviewer/app/src/main/jni/CMakeLists.txt @@ -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}) diff --git a/samples/mfc/standard/01_Geometry/CMakeLists.txt b/samples/mfc/standard/01_Geometry/CMakeLists.txt index 62d612231f..0e4a25598e 100644 --- a/samples/mfc/standard/01_Geometry/CMakeLists.txt +++ b/samples/mfc/standard/01_Geometry/CMakeLists.txt @@ -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) diff --git a/samples/mfc/standard/02_Modeling/CMakeLists.txt b/samples/mfc/standard/02_Modeling/CMakeLists.txt index 6a690ba834..29b562d013 100644 --- a/samples/mfc/standard/02_Modeling/CMakeLists.txt +++ b/samples/mfc/standard/02_Modeling/CMakeLists.txt @@ -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) diff --git a/samples/mfc/standard/03_ImportExport/CMakeLists.txt b/samples/mfc/standard/03_ImportExport/CMakeLists.txt index 93f728e36c..c0e975516c 100644 --- a/samples/mfc/standard/03_ImportExport/CMakeLists.txt +++ b/samples/mfc/standard/03_ImportExport/CMakeLists.txt @@ -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) diff --git a/samples/mfc/standard/04_HLR/CMakeLists.txt b/samples/mfc/standard/04_HLR/CMakeLists.txt index 68785a28cf..14c8cc3850 100644 --- a/samples/mfc/standard/04_HLR/CMakeLists.txt +++ b/samples/mfc/standard/04_HLR/CMakeLists.txt @@ -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) diff --git a/samples/mfc/standard/mfcsample/CMakeLists.txt b/samples/mfc/standard/mfcsample/CMakeLists.txt index 8b759a89d8..55c6e49159 100644 --- a/samples/mfc/standard/mfcsample/CMakeLists.txt +++ b/samples/mfc/standard/mfcsample/CMakeLists.txt @@ -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) diff --git a/samples/webgl/CMakeLists.txt b/samples/webgl/CMakeLists.txt index 5a2a323aa9..4991d154e4 100644 --- a/samples/webgl/CMakeLists.txt +++ b/samples/webgl/CMakeLists.txt @@ -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) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f73a2d824b..beb934f720 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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)