-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathSetCompilerFeatures.cmake
56 lines (41 loc) · 1.56 KB
/
SetCompilerFeatures.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Compiler features
# Choose C++ standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_EXTENSIONS ON)
# Configure Clang compiler options
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Clang C++ compiler should use libc++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
# Check for MSYS2 building environment
get_filename_component(CMAKE_MAKE_NAME ${CMAKE_MAKE_PROGRAM} NAME_WE)
if (MINGW AND CMAKE_MAKE_NAME STREQUAL "make")
set(MSYS 1)
endif()
# Configure MSYS2/MinGW-w64 compiler options
if(MINGW OR MSYS)
# MinGW-w64 increases the number of sections that an object file can contain
add_compile_options(-Wa,-mbig-obj)
# MinGW-w64 use static link std library
add_link_options(-static-libgcc -static-libstdc++)
endif()
# Configure Visual Studio compiler options
if(MSVC)
# Increase the number of sections that an object file can contain
add_compile_options(/bigobj)
# Specifies both the source character set and the execution character set as UTF-8
# https://docs.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8
add_compile_options(/utf-8)
# Visual Studio should correctly reports __cplusplus
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus
add_compile_options(/Zc:__cplusplus)
endif()
# Configure Unix compiler options
if(UNIX)
# Configure build in pthread library
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()