Skip to content

Respect caller CMake settings while retaining the C++11 minimum - #465

Merged
bsergean merged 3 commits into
machinezone:masterfrom
hotwatermorning:use-cmake-cache-variables
Nov 9, 2026
Merged

bsergean merged 3 commits into
machinezone:masterfrom
hotwatermorning:use-cmake-cache-variables

Conversation

@hotwatermorning

@hotwatermorning hotwatermorning commented May 7, 2023 •

Copy link
Copy Markdown
Contributor

IXWebSocket unconditionally reset the caller's C++ standard to 11, including in the CLI and test directories. The original proposed boolean settings also omitted CACHE, producing list values instead of valid boolean defaults.

Use conditional defaults that respect command-line cache values and normal variables inherited through add_subdirectory. Keep C++11 as the library's default and minimum, reject C++98 explicitly, and correct the CMAKE_CXX_STANDARD_REQUIRED variable name. The CLI and tests now inherit the selected standard; the vendored test framework retains its existing C++14 minimum.

Default compile-command export before project() initializes that cache entry, while honoring explicit cache, parent-project, and environment settings. No global caller settings are forced into the cache.

Merged current master and added a configure-time regression test that embeds the library with C++17, STANDARD_REQUIRED=OFF, EXTENSIONS=ON, and compile-command export OFF, then verifies the library, CLI, and a test target retain those settings. Document the supported options.

Validation:

  • Default C++11 library/CLI build: full suite 23/23 passing.
  • Explicit C++17/OpenSSL build, GNU extensions ON, STANDARD_REQUIRED=OFF, compile-command export OFF: full suite 26/26 passing.
  • Linux GCC C++17 unity build without TLS/zlib: full suite 23/23 passing.
  • C++20 library/CLI build passes.
  • C++98 configuration fails with the expected minimum-standard diagnostic.
  • Compile database enabled by default; cache, parent-project, and environment OFF settings respected.
  • Strict compiler warnings enabled for the C++11/C++17 builds; git diff --check passes.

@hotwatermorning hotwatermorning changed the title Use cmake cache variables to customize Use cmake cache variables to customize build settings May 8, 2023
Use cache variables in CMakeLists.txt to customize build settings.
@hotwatermorning
hotwatermorning force-pushed the use-cmake-cache-variables branch from 0d4f63d to e400619 Compare September 3, 2023 18:03
@rh101

rh101 commented Dec 8, 2024

Copy link
Copy Markdown
Contributor

How about this instead?

set(_IXWEBSOCKET_MIN_CXX_STD 11)
if (NOT DEFINED CMAKE_CXX_STANDARD)
    set(CMAKE_CXX_STANDARD ${_IXWEBSOCKET_MIN_CXX_STD})
endif()
if (CMAKE_CXX_STANDARD LESS ${_IXWEBSOCKET_MIN_CXX_STD})
    message(FATAL_ERROR "IXWebsocket requires c++ std >= ${_IXWEBSOCKET_MIN_CXX_STD}")
endif()

if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

if(NOT DEFINED CMAKE_CXX_EXTENSIONS)
    set(CMAKE_CXX_EXTENSIONS OFF)
endif()

@bsergean bsergean changed the title Use cmake cache variables to customize build settings Respect caller CMake settings while retaining the C++11 minimum Nov 9, 2026
@bsergean
bsergean merged commit dd00aab into machinezone:master Nov 9, 2026
13 checks passed
@bsergean

bsergean commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

thanks @rh101 and @hotwatermorning ; finally merged this with a small change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants