From e22405b45843fdec63981bca5b846d344a57aee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ke=C3=9Fler?= Date: Wed, 26 Nov 2025 18:40:00 +0100 Subject: [PATCH 1/4] Cleanup CMakeLists.txt --- CMakeLists.txt | 55 ++++++++++++++----------------------------- README.md | 17 +++++++++++++ bison/CMakeLists.txt | 2 +- common/CMakeLists.txt | 2 +- flex/CMakeLists.txt | 2 +- 5 files changed, 38 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92e5563..ff94991 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,76 +1,57 @@ -cmake_minimum_required(VERSION 3.10 FATAL_ERROR) - -project(winflexbison VERSION 2.5.25 LANGUAGES C) +cmake_minimum_required(VERSION 3.21.0) # cmake 3.31+ - enable `install` destination paths normalization. if(POLICY CMP0177) cmake_policy(SET CMP0177 OLD) endif() +project(winflexbison VERSION 2.5.25 LANGUAGES C) + if(NOT MSVC) message(WARNING "Only Visual Studio Build is officially supported right now") endif() add_definitions(-D_CRT_SECURE_NO_WARNINGS) - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-D_DEBUG) -endif() - # next line needed for compile in C (nor CPP) mode (ucrt headers bug) add_definitions(-Dinline=__inline) # next line needed for VS2017 only add_definitions(-Drestrict=__restrict) -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W3 /MD /Od /Zi /EHsc") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W3 /GL /Od /Oi /Gy /Zi /EHsc") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /EHsc") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL /Oi /Gy") # Define Release by default set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type") - # Only apply to MSVC frontend (not clang frontends) if (MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") - # Make __extension__ expand to nothing on MSVC (so GCC/Clang keep the keyword) - add_compile_definitions("__extension__=") + # Make __extension__ expand to nothing on MSVC (so GCC/Clang keep the keyword) + add_compile_definitions("__extension__=") endif() -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + +if(PROJECT_IS_TOP_LEVEL) # Output Variables - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_LIST_DIR}/bin/Debug") - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_LIST_DIR}/bin/Release") - - #------------------------------------------------------------------------ - # Static Windows Runtime - # Option to statically link to the Windows runtime. Maybe only - # applies to WIN32/MSVC. - #------------------------------------------------------------------------ + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/bin/Debug") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/bin/Release") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_BINARY_DIR}/bin/RelWithDebInfo") if (MSVC) add_compile_options("/source-charset:utf-8") option( USE_STATIC_RUNTIME "Set ON to change /MD(DLL) to /MT(static)" OFF ) if (USE_STATIC_RUNTIME) - set(CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() - message(STATUS "Using /MT STATIC runtime") + # /MT or /MTd depending on config + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + else () + # /MD or /MDd depending on config + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") endif () endif () endif () - - add_subdirectory(common) add_subdirectory(flex) add_subdirectory(bison) -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) +if(PROJECT_IS_TOP_LEVEL) # CPACK if(CMAKE_BUILD_TYPE STREQUAL "Debug") install(DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}/" DESTINATION "./") diff --git a/README.md b/README.md index 68f21d0..e41c3d5 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,23 @@ The release page includes the full Changelog but you may also see the [changelog * Visual Studio 2017 or newer * CMake +* Clang-cl or Visual Studio 2017 and newer +* CMake +* Ninja (optional, recommended) + +## Build instructions Visual Studio 15 2017 + +mkdir CMakeBuildVS2017 +cd CMakeBuildVS2017 +cmake .. -G "Visual Studio 15 2017" +cmake --build . --config "Release" --target package + +## Build instructions clang-cl + +mkdir CMakeBuildClangCl +cd CMakeBuildClangCl +cmake .. -G"Ninja Multi-Config" -DCMAKE_C_COMPILER=clang-cl.exe +cmake --build . --config "Release" --target package ## HowTo diff --git a/bison/CMakeLists.txt b/bison/CMakeLists.txt index 8e341ff..f4912b5 100644 --- a/bison/CMakeLists.txt +++ b/bison/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21.0) project(win_bison LANGUAGES C) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 92535dc..8273f40 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21.0) project(winflexbison_common LANGUAGES C) diff --git a/flex/CMakeLists.txt b/flex/CMakeLists.txt index a51eb18..95fb432 100644 --- a/flex/CMakeLists.txt +++ b/flex/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21.0) project(win_flex LANGUAGES C) From 8d25cc88a649215ad245b903464725fe8829f8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ke=C3=9Fler?= Date: Wed, 26 Nov 2025 21:25:33 +0100 Subject: [PATCH 2/4] Be more strict, regarding project specific options, when build as subproject. --- CMakeLists.txt | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff94991..53e761a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,33 +17,35 @@ add_definitions(-Dinline=__inline) # next line needed for VS2017 only add_definitions(-Drestrict=__restrict) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /EHsc") -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL /Oi /Gy") - # Define Release by default set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type") + # Only apply to MSVC frontend (not clang frontends) +# Make __extension__ expand to nothing on MSVC (so GCC/Clang keeps the keyword) if (MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") - # Make __extension__ expand to nothing on MSVC (so GCC/Clang keep the keyword) add_compile_definitions("__extension__=") endif() +# Only change those variables for top-level project else use parent values +if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/$/bin") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/$/bin") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_BINARY_DIR}/$/bin") + if(MSVC AND DEFINED USE_STATIC_RUNTIME) + # Legacy compatibility for top-level builds + option(WINFLEXBISON_USE_STATIC_RUNTIME "Set ON to change /MD(DLL) to /MT(static)" USE_STATIC_RUNTIME) + endif() +endif() -if(PROJECT_IS_TOP_LEVEL) - # Output Variables - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/bin/Debug") - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/bin/Release") - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_BINARY_DIR}/bin/RelWithDebInfo") - if (MSVC) - add_compile_options("/source-charset:utf-8") - option( USE_STATIC_RUNTIME "Set ON to change /MD(DLL) to /MT(static)" OFF ) - if (USE_STATIC_RUNTIME) - # /MT or /MTd depending on config - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - else () - # /MD or /MDd depending on config - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") - endif () +if (MSVC) + add_compile_options("/source-charset:utf-8") + option(WINFLEXBISON_USE_STATIC_RUNTIME "Set ON to change /MD(DLL) to /MT(static)" Off) + if (WINFLEXBISON_USE_STATIC_RUNTIME) + # /MT or /MTd depending on config + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + else () + # /MD or /MDd depending on config + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") endif () endif () From 5cb7749ac75a2fa5003749a4eece5e32ba49d594 Mon Sep 17 00:00:00 2001 From: Febbe Date: Thu, 19 Mar 2026 10:05:42 +0100 Subject: [PATCH 3/4] Update README.md Suggest more modern cmake commands. Co-authored-by: jonnysoe <84360198+jonnysoe@users.noreply.github.com> --- README.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e41c3d5..feea0a3 100644 --- a/README.md +++ b/README.md @@ -38,17 +38,13 @@ The release page includes the full Changelog but you may also see the [changelog ## Build instructions Visual Studio 15 2017 -mkdir CMakeBuildVS2017 -cd CMakeBuildVS2017 -cmake .. -G "Visual Studio 15 2017" -cmake --build . --config "Release" --target package +cmake -B CMakeBuildVS2017 -G "Visual Studio 15 2017" +cmake --build CMakeBuildVS2017 --config "Release" --target package ## Build instructions clang-cl -mkdir CMakeBuildClangCl -cd CMakeBuildClangCl -cmake .. -G"Ninja Multi-Config" -DCMAKE_C_COMPILER=clang-cl.exe -cmake --build . --config "Release" --target package +cmake -B CMakeBuildClangCl -G "Ninja Multi-Config" -DCMAKE_C_COMPILER=clang-cl.exe +cmake --build CMakeBuildClangCl --config "Release" --target package ## HowTo From 6247a9ae2834085efe980dce6d19661cb51faa06 Mon Sep 17 00:00:00 2001 From: Febbe Date: Mon, 23 Mar 2026 16:09:03 +0100 Subject: [PATCH 4/4] Update README.md Co-authored-by: jonnysoe <84360198+jonnysoe@users.noreply.github.com> --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index feea0a3..c94a12b 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,6 @@ The release page includes the full Changelog but you may also see the [changelog ## Build requirements -* Visual Studio 2017 or newer -* CMake - * Clang-cl or Visual Studio 2017 and newer * CMake * Ninja (optional, recommended)