-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.cmake
57 lines (55 loc) · 1.99 KB
/
utils.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
57
macro(set_precompiled_header PrecompiledHeader PrecompiledSource)
if (MSVC)
get_filename_component(PrecompiledBasename ${PrecompiledHeader} NAME_WE)
set(PrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${PrecompiledBasename}.pch")
set_source_files_properties(${PrecompiledSource}
PROPERTIES COMPILE_FLAGS "/Yc\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\""
OBJECT_OUTPUTS "${PrecompiledBinary}")
set_source_files_properties(${SOURCES}
PROPERTIES COMPILE_FLAGS "/Yu\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\""
OBJECT_DEPENDS "${PrecompiledBinary}")
endif()
list(APPEND HEADERS ${PrecompiledHeader})
list(APPEND SOURCES ${PrecompiledSource})
endmacro()
macro(configure_msvc_runtime link_type)
if(MSVC)
# Default to statically-linked runtime.
if("${link_type}" STREQUAL "")
set(link_type "static")
endif()
# Set compiler options.
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(${link_type} STREQUAL "static")
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
else()
message(STATUS "MSVC -> forcing use of dynamically-linked runtime.")
foreach(variable ${variables})
if(${variable} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
endif()
endforeach()
endif()
endif()
endmacro()
macro(make_version_file version PROJECT_DESCRIPTION)
string(REPLACE "." "," PROJECT_VERSION_RC "${PROJECT_VERSION}")
string(REPLACE "." "," PACKAGE_VERSION_RC "${CPACK_PACKAGE_VERSION}")
set(PROJECT_DESCRIPTION ${PROJECT_DESCRIPTION})
configure_file(${CMAKE_SOURCE_DIR}/version.h.in version.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
endmacro()