-
Notifications
You must be signed in to change notification settings - Fork 141
Cleanup CMake even more #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
| cmake_policy(SET CMP0177 OLD) | ||
| endif() | ||
|
|
||
| project(winflexbison VERSION 2.5.25 LANGUAGES C) | ||
|
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) | ||
|
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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't experimented this myself, why separate them, is the single
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This multiple option for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 "./") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.