View Issue Details

IDProjectCategoryView StatusLast Update
0032921Open CASCADEOCCT:Configurationpublic2022-05-25 13:15
Reporterddzama Assigned Toddzama  
Status assignedResolutionopen 
PlatformWindowsOSVC++ 2019 
Target Version7.7.0 
Summary0032921: Configuration, CMake - allow selecting C++ standard
DescriptionMicrosoft Visual Studio Professional 2019
Version 16.11.11

Make C++ standard to be enable from cmake settings:

Now, user can choose standard by setting cmake variable CPP_STANDARD.

Available next standard items:
Steps To ReproduceNot required
TagsNo tags attached.
Test case numberN/A


child of 0032887 assignedddzama Coding - Problem of compilation on VS2019/C++20 



2022-04-07 14:21

administrator   ~0107681

Branch CR32921 has been created by ddzama.

SHA-1: cafb923ca794c56fe8e69d75852d991b74c48b7b

Detailed log of new commits:

Author: Dmitry DZAMA
Date: Tue Mar 29 16:33:45 2022 +0300

    0032921: Make C++ standard to be enable from cmake settings
    Microsoft Visual Studio Professional 2019
    Version 16.11.11
    Make C++ standard to be enable from cmake settings:
    Now, user can choose standard by setting cmake variable CPP_STANDARD.
    Availabale next standard itemd:


2022-04-07 14:44

administrator   ~0107706

Branch CR32921 has been updated forcibly by ddzama.

SHA-1: 8b963c1d75a0d097249cb5f715b6ae8fc4dbbfc8


2022-04-08 01:45

developer   ~0107735

+# Set desired C++ standard
+if     ("${CPP_STANDARD}" STREQUAL "C++11")

According to documentation:
> CMAKE_CXX_STANDARD - New in version 3.1.

While CMakeLists.txt in OCCT specifies:
> cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)

Either we need to increase minimal requirements to CMake, or fallback should be applied for older CMake versions (passing C++11 to compiler flags as before).


2022-04-08 10:00

developer   ~0107740

Now, different libs have different requirement to CMAKE version:

adm/cmake/cotire.cmake:cmake_minimum_required(VERSION 2.8.12)
CMakeLists.txt:cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
samples/glfw/CMakeLists.txt:cmake_minimum_required(VERSION 3.2)
samples/java/jniviewer/app/src/main/jni/CMakeLists.txt:cmake_minimum_required(VERSION 3.4.1)
samples/mfc/standard/01_Geometry/CMakeLists.txt:cmake_minimum_required (VERSION 2.6)
samples/mfc/standard/02_Modeling/CMakeLists.txt:cmake_minimum_required (VERSION 2.6)
samples/mfc/standard/03_ImportExport/CMakeLists.txt:cmake_minimum_required (VERSION 2.6)
samples/mfc/standard/04_HLR/CMakeLists.txt:cmake_minimum_required (VERSION 2.6)
samples/mfc/standard/mfcsample/CMakeLists.txt:cmake_minimum_required (VERSION 2.6)
samples/webgl/CMakeLists.txt:cmake_minimum_required(VERSION 3.2)
samples/xaml/CMakeLists.txt:cmake_minimum_required(VERSION 3.4.0)
tools/CMakeLists.txt:cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)

Maybe use unique requirement to CMAKE version, set in main cmake file?


2022-04-08 14:23

developer   ~0107754

Last edited: 2022-04-08 14:24


I don't see how CMake requirements to build some sample depend on CMake requirements for building OCCT.
Samples could be built using OCCT pre-built on another computer with another CMake version and without using CMake at all.
And a particular sample might indeed require a higher CMake version than OCCT itself - but OCCT users are not required to build all these samples.

But there is another issue with the patch - it is unclear which consequences could be building OCCT and projects (samples, OCC Products) with mixed/incompatible versions of C++ standard.
So that I guess C++ version selection should be propagated to all samples and OCC Products (could be done in dedicated bug/patch).


2022-04-08 14:44

administrator   ~0107755

Branch CR32921 has been updated by ddzama.

SHA-1: 18738b72e9fa73afc791b44094d73b49d2bf7862

Detailed log of new commits:

Author: ddzama
Date: Fri Apr 8 14:43:59 2022 +0300

    require minimum CMAKE version 3.1 (for enabling CMAKE_CXX_STANDARD)


2022-04-20 11:14

administrator   ~0108038

Branch CR32921 has been updated forcibly by ddzama.

SHA-1: 73e424210859e0303f5ed4da04d46a2940aed41e


2022-04-25 15:35

administrator   ~0108152

Branch CR32921 has been updated by ddzama.

SHA-1: 0e3d7c4cbdfce581e8a359a7a281a93f8e6461e7

Detailed log of new commits:

Author: ddzama
Date: Mon Apr 25 12:16:14 2022 +0300

    0032921: Preserve cmake policies.


2022-04-25 17:37

administrator   ~0108166

Branch CR32921 has been updated by ddzama.

SHA-1: e76e6b90dfc427439bc381da20df8765e1245e81

Detailed log of new commits:

Author: ddzama
Date: Mon Apr 25 17:37:13 2022 +0300

    Revert "0032921: Fix `if()` contents for employing new cmake policy `CMP0054`, started since version 3.1."
    This reverts commit 73e424210859e0303f5ed4da04d46a2940aed41e.


2022-04-26 02:13

administrator   ~0108178

Branch CR32921 has been updated forcibly by ddzama.

SHA-1: 6b480960d6af94baf41c94f9c5bd9d2d732463a1


2022-04-26 21:47

developer   ~0108200

+# For moving from minimal cmake version 2.8.12 to 3.1,
+# we, nevertheless, have to use 2.8.12 cmake policies
+cmake_policy(VERSION 2.8)
+# Set cmake version, but preserve cmake policies
+cmake_minimum_required (VERSION 3.1 FATAL_ERROR)

There is no way to use new polices from CMake 3.1 without warnings?
They are useless and step in a wrong direction?


2022-04-26 22:02

developer   ~0108201

Last edited: 2022-04-26 22:03

+else ()

Why "else" means "23"? Shouldn't be there an error in case of unknown string?

--- a/adm/genproj.tcl
+++ b/adm/genproj.tcl

I don't think modifications of Code::Blocks generator have been actually tested and are necessary in scope of this patch.
If we would like to expose C++ standard selection with 'genproj.bat' - at first, Visual Studio project files should be updated and selection should be exposed to `genconf.tcl`.
This could be postponed to a dedicated patch.

> Availabale next standard itemd:

Two misprints.

> Microsoft Visual Studio Professional 2019
> Version 16.11.11
> std=c++20

This text looks unrelated to commit message.

> Now, user can choose standard by setting cmake variable CPP_STANDARD.

Documentation should be updated to mention new CMake parameter.


2022-04-26 22:05

developer   ~0108202

Consider renaming new CMake variable to have `BUILD_` prefix for better grouping.


2022-05-04 15:12

developer   ~0108304

Last edited: 2022-05-04 15:15

@kgv, yes.
If moving cmake minimum required version from 2.8 to 3.1, the list of new policies is applied by default (if not preserve policies, as proposed above).
If not preserve policies, compilation on Windows will cause errors.

Introduced in 3.0
CMP0050: Disallow add_custom_command SOURCE signatures.
CMP0049: Do not expand variables in target source entries.
CMP0048: project() command manages VERSION variables.
CMP0047: Use QCC compiler id for the qcc drivers on QNX.
CMP0046: Error on non-existent dependency in add_dependencies.
CMP0045: Error on non-existent target in get_target_property.
CMP0044: Case sensitive Lang_COMPILER_ID generator expressions.
CMP0043: Ignore COMPILE_DEFINITIONS_Config properties.
CMP0042: MACOSX_RPATH is enabled by default.
CMP0041: Error on relative include with generator expression.
CMP0040: The target in the TARGET signature of add_custom_command() must exist.
CMP0039: Utility targets may not have link dependencies.
CMP0038: Targets may not link directly to themselves.
CMP0037: Target names should not be reserved and should match a validity pattern.
CMP0036: The build_name command should not be called.
CMP0035: The variable_requires command should not be called.
CMP0034: The utility_source command should not be called.
CMP0033: The export_library_dependencies command should not be called.
CMP0032: The output_required_files command should not be called.
CMP0031: The load_command command should not be called.
CMP0030: The use_mangled_mesa command should not be called.
CMP0029: The subdir_depends command should not be called.
CMP0028: Double colon in target name means ALIAS or IMPORTED target.
CMP0027: Conditionally linked imported targets with missing include directories.
CMP0026: Disallow use of the LOCATION target property.
CMP0025: Compiler id for Apple Clang is now AppleClang.
CMP0024: Disallow include export result.

And introduced in 3.1
CMP0054: Only interpret if() arguments as variables or keywords when unquoted.
CMP0053: Simplify variable reference and escape sequence evaluation.
CMP0052: Reject source and build dirs in installed INTERFACE_INCLUDE_DIRECTORIES.
CMP0051: List TARGET_OBJECTS in SOURCES target property.


2022-05-04 15:16

administrator   ~0108305

Branch CR32921 has been updated forcibly by ddzama.

SHA-1: 0bdb1002364e321ab155c14e869890f6ad974765


2022-05-04 15:21

administrator   ~0108308

Branch CR32921 has been updated forcibly by ddzama.

SHA-1: 32bda6940ed830a337c9431121a14d97d9bcb656


2022-05-04 15:29

developer   ~0108309

@ddzama, my question was different - policies in CMake looks like a compatibility hacks, and I'm not sure that the old policies will not be removed in some newer CMake release.
So the question is actually - is it possible update our CMake scripts so that they will be compatible with new CMake policies without playing with policies?


2022-05-04 15:48

developer   ~0108314

@kgv, i think it is, but, firstly - i should define what particular new policy(s) breaks compilation.
And second - find out, how to fix it.
And, yes, old policies may be removed in newer version of CMake software.
Will i do this work now in current ticket?


2022-05-05 15:02

administrator   ~0108349

Branch CR32921 has been updated forcibly by ddzama.

SHA-1: b3bba91506387d8d50ab30fbd8618d845265ca40


2022-05-06 12:51

developer   ~0108365

@kgv, new policies (one or more from them) breaks compilation on MacOS.
I try to find out the cause by comparing successed build directory with failed build directory, but until current moment unsuccessful.


2022-05-06 16:13

administrator   ~0108379

Branch CR32921 has been updated forcibly by ddzama.

SHA-1: 82da07e44807cce3bba190d55a29f6d9c5f9d191


2022-05-07 01:08

developer   ~0108381

@kgv, the problem on MacOs was in naming of cxx compilator.
This is strange, but if we use cmake minimal 2.8 it called Clang, when we require 3.1 as minimal version - AppleClang. So, I fixed it by replace more strength STREQUAL operator to MATCHES one and just in case make it case insensitive.

Successfully finished jenkins:


2022-05-13 00:28

developer   ~0108419

> if we use cmake minimal 2.8 it called Clang, when we require 3.1 as minimal version - AppleClang.
Interesting to know. I guess CMake developers decided to introduce "AppleClang" to distinguish this CLang fork coming with XCode.
As these compilers have independent and inconsistent versioning, specific bugs and features sets, tracking them as the same one complicated handling some corner cases.


2022-05-18 11:07

developer   ~0108480

@ddzama, if patch is ready for review, please don't forget to switch bug into appropriate state.


2022-05-20 05:41

developer   ~0108504

Last edited: 2022-05-20 12:58

@kgv, sorry for my late response. My activity in this direction has been suspended by other projects, and I do not understend entirely your last remark -should I change installatin direcory for occt, depending on cmake variable CMAKE_COMPILER_ID, and, therefore, for IFC, because IFC should receive the same installation directory. By other words, should we install occt in AppleClang/ directory or clang/ directory is stay fine?


2022-05-20 12:25

developer   ~0108509

@ddzama, I didn't put any remark related to AppleClang - just put a comment.

I don't know how it affects installation directory.
In my opinion all CLang checks in CMake scripts should be updated to treat both values - in the same way.
Save the parts, where AppleClang is supposed to be handled differently - I guess such places might be found in `if(APPLE)` cases in existing scripts (don't know if it worth changing these places).


2022-05-20 12:50

developer   ~0108510

Last edited: 2022-05-20 12:53

@kgv, ok
There would be one commit - now there is not any reason to preserve policies when requiring cmake_minimal_version (VERSION 3.1)


2022-05-25 07:35

administrator   ~0108601

Branch CR32921 has been updated forcibly by ddzama.

SHA-1: dc9e78147e5bef405480e433b7033a91f031ee5f


2022-05-25 07:41

developer   ~0108603

@kgv, sorry.
I think we should push before and pop after policies requiring cmake version outside main CMakeLists.txt, because it may be changed in future.
After achieving jenkins result, i move this ticket.


2022-05-25 11:14

developer   ~0108604

@msv, please comment if you have any remarks to proposed solution.


2022-05-25 12:49

developer   ~0108605

Last edited: 2022-05-25 12:54

When using the variable CMAKE_CXX_STANDARD to set standard to C++14 when building ASRV on Ubuntu 18.04 with gcc 7.5 and cmake 3.22.1, I faced with the problem that GCC indeed used the standard C++11. So, setting only that variable does not dictate cmake to use this standard mandatory.
I found the solution by setting the following:

So, I propose to include this setting in our scripts, too.


2022-05-25 12:51

developer   ~0108606

One more remark, I did not understand why we left the old policies in some samples' scripts? Is it possible to avoid this?


2022-05-25 12:53

developer   ~0108607

What about the same feature in occt-products repository? I think this ticket must include changes there, too.


2022-05-25 13:15

developer   ~0108609


Would this lead to failure building with default C++11 option on VS2019, as this compiler doesn't support this standard or this check validates only `>=`?

Issue History

Date Modified Username Field Change
2022-04-07 12:12 ddzama New Issue
2022-04-07 12:12 ddzama Assigned To => ddzama
2022-04-07 12:20 kgv Category OCCT:Coding => OCCT:Configuration
2022-04-07 12:20 kgv Summary Make C++ standard to be enable from cmake settings => Configuratiuon, CMake - allow selecting C++ standard
2022-04-07 12:20 kgv Description Updated
2022-04-07 12:20 kgv Relationship added child of 0032887
2022-04-07 14:21 git Note Added: 0107681
2022-04-07 14:44 git Note Added: 0107706
2022-04-07 14:51 ddzama Relationship deleted child of 0032887
2022-04-07 14:54 ddzama Relationship added child of 0032887
2022-04-08 01:45 kgv Note Added: 0107735
2022-04-08 10:00 ddzama Note Added: 0107740
2022-04-08 14:23 kgv Note Added: 0107754
2022-04-08 14:24 kgv Note Edited: 0107754
2022-04-08 14:44 git Note Added: 0107755
2022-04-20 11:14 git Note Added: 0108038
2022-04-25 15:35 git Note Added: 0108152
2022-04-25 17:37 git Note Added: 0108166
2022-04-26 02:13 git Note Added: 0108178
2022-04-26 11:30 ddzama Assigned To ddzama => bugmaster
2022-04-26 11:30 ddzama Status new => resolved
2022-04-26 11:30 ddzama Steps to Reproduce Updated
2022-04-26 16:47 kgv Assigned To bugmaster => kgv
2022-04-26 21:47 kgv Note Added: 0108200
2022-04-26 22:02 kgv Note Added: 0108201
2022-04-26 22:02 kgv Assigned To kgv => ddzama
2022-04-26 22:02 kgv Status resolved => assigned
2022-04-26 22:02 kgv Test case number => N/A
2022-04-26 22:03 kgv Note Edited: 0108201
2022-04-26 22:05 kgv Note Added: 0108202
2022-04-26 22:06 kgv Summary Configuratiuon, CMake - allow selecting C++ standard => Configuration, CMake - allow selecting C++ standard
2022-04-26 22:06 kgv Severity minor => feature
2022-04-26 22:06 kgv Product Version 7.7.0 =>
2022-05-04 15:12 ddzama Note Added: 0108304
2022-05-04 15:15 ddzama Note Edited: 0108304
2022-05-04 15:16 git Note Added: 0108305
2022-05-04 15:21 git Note Added: 0108308
2022-05-04 15:29 kgv Note Added: 0108309
2022-05-04 15:48 ddzama Note Added: 0108314
2022-05-05 15:02 git Note Added: 0108349
2022-05-06 12:51 ddzama Note Added: 0108365
2022-05-06 16:13 git Note Added: 0108379
2022-05-07 01:08 ddzama Note Added: 0108381
2022-05-13 00:28 kgv Note Added: 0108419
2022-05-18 11:07 kgv Note Added: 0108480
2022-05-20 05:41 ddzama Note Added: 0108504
2022-05-20 12:25 kgv Note Added: 0108509
2022-05-20 12:50 ddzama Note Added: 0108510
2022-05-20 12:51 ddzama Assigned To ddzama => bugmaster
2022-05-20 12:51 ddzama Status assigned => resolved
2022-05-20 12:51 ddzama Assigned To bugmaster => ddzama
2022-05-20 12:51 ddzama Status resolved => assigned
2022-05-20 12:53 ddzama Note Edited: 0108510
2022-05-20 12:58 ddzama Note Edited: 0108504
2022-05-25 07:35 git Note Added: 0108601
2022-05-25 07:41 ddzama Note Added: 0108603
2022-05-25 09:58 ddzama Assigned To ddzama => bugmaster
2022-05-25 09:58 ddzama Status assigned => resolved
2022-05-25 11:14 kgv Assigned To bugmaster => msv
2022-05-25 11:14 kgv Note Added: 0108604
2022-05-25 12:49 msv Note Added: 0108605
2022-05-25 12:51 msv Note Added: 0108606
2022-05-25 12:53 msv Note Added: 0108607
2022-05-25 12:53 msv Assigned To msv => ddzama
2022-05-25 12:53 msv Status resolved => assigned
2022-05-25 12:54 msv Note Edited: 0108605
2022-05-25 13:15 kgv Note Added: 0108609