Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 26 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Comment thread
Febbe marked this conversation as resolved.
cmake_policy(SET CMP0177 OLD)
endif()

project(winflexbison VERSION 2.5.25 LANGUAGES C)
Comment thread
GitMensch marked this conversation as resolved.

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)
Comment thread
GitMensch marked this conversation as resolved.
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}/$<CONFIG>/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/bin")
Comment on lines +31 to +33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't experimented this myself, why separate them, is the single CMAKE_RUNTIME_OUTPUT_DIRECTORY not working for some reason?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason, it was separated before I refactored it and was too tired to see that. Good catch.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This multiple option for WINFLEXBISON_USE_STATIC_RUNTIME will be a nightmare for maintenance, preferable to consolidate them into a single variable before setting it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also, don't expect anyone to dig through the PRs, please add a comments around the need for WINFLEXBISON_USE_STATIC_RUNTIME, I don't really know why at a glance, like its to prevent name clash with other code base that pull this in as a dependency if they use USE_STATIC_RUNTIME but we use this name previously so older scripts we missed will still work, etc.

if (WINFLEXBISON_USE_STATIC_RUNTIME)
# /MT or /MTd depending on config
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else ()
# /MD or /MDd depending on config
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>: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 "./")
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ 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)
Comment thread
Febbe marked this conversation as resolved.
Outdated

## 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

Expand Down
2 changes: 1 addition & 1 deletion bison/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
cmake_minimum_required(VERSION 3.21.0)

project(win_bison LANGUAGES C)

Expand Down
2 changes: 1 addition & 1 deletion common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
cmake_minimum_required(VERSION 3.21.0)

project(winflexbison_common LANGUAGES C)

Expand Down
2 changes: 1 addition & 1 deletion flex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
cmake_minimum_required(VERSION 3.21.0)

project(win_flex LANGUAGES C)

Expand Down
Loading