Skip to content

Commit c2cda58

Browse files
committed
Cleanup CMakeLists.txt
1 parent c277cfd commit c2cda58

5 files changed

Lines changed: 38 additions & 40 deletions

File tree

CMakeLists.txt

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,57 @@
1-
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
2-
3-
project(winflexbison VERSION 2.5.25 LANGUAGES C)
1+
cmake_minimum_required(VERSION 3.21.0)
42

53
# cmake 3.31+ - enable `install` destination paths normalization.
64
if(POLICY CMP0177)
75
cmake_policy(SET CMP0177 OLD)
86
endif()
97

8+
project(winflexbison VERSION 2.5.25 LANGUAGES C)
9+
1010
if(NOT MSVC)
1111
message(WARNING "Only Visual Studio Build is officially supported right now")
1212
endif()
1313

1414
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
15-
16-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
17-
add_definitions(-D_DEBUG)
18-
endif()
19-
2015
# next line needed for compile in C (nor CPP) mode (ucrt headers bug)
2116
add_definitions(-Dinline=__inline)
2217
# next line needed for VS2017 only
2318
add_definitions(-Drestrict=__restrict)
2419

25-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W3 /MD /Od /Zi /EHsc")
26-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W3 /GL /Od /Oi /Gy /Zi /EHsc")
20+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /EHsc")
21+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL /Oi /Gy")
2722

2823
# Define Release by default
2924
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type")
30-
3125
# Only apply to MSVC frontend (not clang frontends)
3226
if (MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
33-
# Make __extension__ expand to nothing on MSVC (so GCC/Clang keep the keyword)
34-
add_compile_definitions("__extension__=")
27+
# Make __extension__ expand to nothing on MSVC (so GCC/Clang keep the keyword)
28+
add_compile_definitions("__extension__=")
3529
endif()
3630

37-
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
31+
32+
if(PROJECT_IS_TOP_LEVEL)
3833
# Output Variables
39-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_LIST_DIR}/bin/Debug")
40-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_LIST_DIR}/bin/Release")
41-
42-
#------------------------------------------------------------------------
43-
# Static Windows Runtime
44-
# Option to statically link to the Windows runtime. Maybe only
45-
# applies to WIN32/MSVC.
46-
#------------------------------------------------------------------------
34+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_BINARY_DIR}/bin/Debug")
35+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_BINARY_DIR}/bin/Release")
36+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_BINARY_DIR}/bin/RelWithDebInfo")
4737
if (MSVC)
4838
add_compile_options("/source-charset:utf-8")
4939
option( USE_STATIC_RUNTIME "Set ON to change /MD(DLL) to /MT(static)" OFF )
5040
if (USE_STATIC_RUNTIME)
51-
set(CompilerFlags
52-
CMAKE_CXX_FLAGS
53-
CMAKE_CXX_FLAGS_DEBUG
54-
CMAKE_CXX_FLAGS_RELEASE
55-
CMAKE_C_FLAGS
56-
CMAKE_C_FLAGS_DEBUG
57-
CMAKE_C_FLAGS_RELEASE
58-
)
59-
foreach(CompilerFlag ${CompilerFlags})
60-
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
61-
endforeach()
62-
message(STATUS "Using /MT STATIC runtime")
41+
# /MT or /MTd depending on config
42+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
43+
else ()
44+
# /MD or /MDd depending on config
45+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
6346
endif ()
6447
endif ()
6548
endif ()
6649

67-
68-
6950
add_subdirectory(common)
7051
add_subdirectory(flex)
7152
add_subdirectory(bison)
7253

73-
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
54+
if(PROJECT_IS_TOP_LEVEL)
7455
# CPACK
7556
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
7657
install(DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}/" DESTINATION "./")

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ The release page includes the full Changelog but you may also see the [changelog
3232
* Visual Studio 2017 or newer
3333
* CMake
3434

35+
* Clang-cl or Visual Studio 2017 and newer
36+
* CMake
37+
* Ninja (optional, recommended)
38+
39+
## Build instructions Visual Studio 15 2017
40+
41+
mkdir CMakeBuildVS2017
42+
cd CMakeBuildVS2017
43+
cmake .. -G "Visual Studio 15 2017"
44+
cmake --build . --config "Release" --target package
45+
46+
## Build instructions clang-cl
47+
48+
mkdir CMakeBuildClangCl
49+
cd CMakeBuildClangCl
50+
cmake .. -G"Ninja Multi-Config" -DCMAKE_C_COMPILER=clang-cl.exe
51+
cmake --build . --config "Release" --target package
3552

3653
## HowTo
3754

bison/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.21.0)
22

33
project(win_bison LANGUAGES C)
44

common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.21.0)
22

33
project(winflexbison_common LANGUAGES C)
44

flex/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.21.0)
22

33
project(win_flex LANGUAGES C)
44

0 commit comments

Comments
 (0)