diff --git a/CMakeLists.txt b/CMakeLists.txt index 92e5563..53e761a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,76 +1,59 @@ -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") - # 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__=") + 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(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - # 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. - #------------------------------------------------------------------------ - 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") - 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 () - - 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..c94a12b 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,19 @@ The release page includes the full Changelog but you may also see the [changelog ## Build requirements -* Visual Studio 2017 or newer +* Clang-cl or Visual Studio 2017 and newer * CMake +* Ninja (optional, recommended) +## Build instructions Visual Studio 15 2017 + +cmake -B CMakeBuildVS2017 -G "Visual Studio 15 2017" +cmake --build CMakeBuildVS2017 --config "Release" --target package + +## Build instructions clang-cl + +cmake -B CMakeBuildClangCl -G "Ninja Multi-Config" -DCMAKE_C_COMPILER=clang-cl.exe +cmake --build CMakeBuildClangCl --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)