diff --git a/.gitignore b/.gitignore index 6370522..959fb59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +#vscode +.vscode + # User-specific files *.suo *.user diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c9f7e0..1ad71f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,22 @@ -cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21.0) +if(POLICY CMP0177) + cmake_policy(SET CMP0177 NEW) +endif() -project (winflexbison) +project (winflexbison C) if(NOT MSVC) - message( WARNING "Visual Studio Build supported only" ) + message(FATAL_ERROR "Visual Studio Build supported only" ) 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. if(NOT CMAKE_BUILD_TYPE) @@ -26,44 +24,35 @@ if(NOT CMAKE_BUILD_TYPE) message(STATUS "Build type not specified: Use Release by default.") 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. - #------------------------------------------------------------------------ - if (MSVC) - add_compile_definitions("__extension__") - 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 () - endif () -endif () - + 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") +endif() + # 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__=") +endif() +#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() +#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/bison/CMakeLists.txt b/bison/CMakeLists.txt index 55de8a1..a523047 100644 --- a/bison/CMakeLists.txt +++ b/bison/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21.0) set(PROJECT_NAME win_bison) diff --git a/bison/src/config.h b/bison/src/config.h index 184c57b..76562ce 100644 --- a/bison/src/config.h +++ b/bison/src/config.h @@ -19,4 +19,5 @@ extern char* _stpcpy(char *yydest, const char *yysrc); extern int strverscmp(const char* s1, const char* s2); +struct obstack; extern int obstack_printf(struct obstack* obs, const char* format, ...); \ No newline at end of file diff --git a/buildClangCl.bat b/buildClangCl.bat new file mode 100644 index 0000000..a683814 --- /dev/null +++ b/buildClangCl.bat @@ -0,0 +1,5 @@ +mkdir CMakeBuildClangCl +cd CMakeBuildClangCl +cmake .. -G"Ninja Multi-Config" -DCMAKE_C_COMPILER=clang-cl.exe +cmake --build . --config "Release" --target package +cd .. \ No newline at end of file diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 4b57c62..d0b8311 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.20.0) set(PROJECT_NAME winflexbison_common) diff --git a/common/m4/lib/clean-temp.h b/common/m4/lib/clean-temp.h index f5697b6..1c727b2 100644 --- a/common/m4/lib/clean-temp.h +++ b/common/m4/lib/clean-temp.h @@ -136,9 +136,10 @@ extern int cleanup_temp_subdir (struct temp_dir *dir, Return 0 upon success, or -1 if there was some problem. */ extern int cleanup_temp_dir_contents (struct temp_dir *dir); -#if !defined (__GNUC__) && !defined (__clang__) +#ifndef _MODE_T_ +#define _MODE_T_ typedef int mode_t; -#endif +#endif /* _MODE_T_ */ /* ================== Opening and closing temporary files ================== */ diff --git a/flex/CMakeLists.txt b/flex/CMakeLists.txt index f634f81..13e6dd2 100644 --- a/flex/CMakeLists.txt +++ b/flex/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.20.0) set(PROJECT_NAME win_flex)