forked from ampl/gsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.cmake
92 lines (83 loc) · 3.12 KB
/
init.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# CMake initialization code that should be run before the project command.
include(CMakeParseArguments)
# Joins arguments and sets the result to <var>.
# Usage:
# join(<var> [<arg>...])
function (join var)
unset(result)
foreach (arg ${ARGN})
if (DEFINED result)
set(result "${result} ${arg}")
else ()
set(result "${arg}")
endif ()
endforeach ()
set(${var} "${result}" PARENT_SCOPE)
endfunction ()
# Sets cache variable <var> to the value <value>. The arguments
# following <type> are joined into a single docstring which allows
# breaking long documentation into smaller strings.
# Usage:
# set_cache(<var> <value> <type> docstring... [FORCE])
function (set_cache var value type)
cmake_parse_arguments(set_cache FORCE "" "" ${ARGN})
unset(force)
if (set_cache_FORCE)
set(force FORCE)
endif ()
join(docstring ${set_cache_UNPARSED_ARGUMENTS})
set(${var} ${value} CACHE ${type} "${docstring}" ${force})
endfunction ()
if (NOT CMAKE_BUILD_TYPE)
# Set the default CMAKE_BUILD_TYPE to Release.
# This should be done before the project command since the latter sets
# CMAKE_BUILD_TYPE itself.
set_cache(CMAKE_BUILD_TYPE Release STRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or"
"CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
endif ()
function (override var file)
if (EXISTS "${file}")
set(${var} ${file} PARENT_SCOPE)
endif ()
endfunction ()
# Set compiler options (MSVC)
# This should be done before the project command.
override(CMAKE_USER_MAKE_RULES_OVERRIDE
${CMAKE_CURRENT_LIST_DIR}/c_flag_overrides.cmake)
override(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
${CMAKE_CURRENT_LIST_DIR}/cxx_flag_overrides.cmake)
if (MP_WINSDK)
# Find Windows SDK.
set(winsdk_key
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows")
find_program(MP_SETENV NAMES SetEnv.cmd
PATHS "[${winsdk_key};CurrentInstallFolder]/bin")
if (MP_SETENV)
if (NOT CMAKE_GENERATOR MATCHES Win64)
set(setenv_arg "/x86")
endif ()
# Call SetEnv.cmd and set environment variables accordingly.
message(STATUS "Found SetEnv: ${MP_SETENV}")
set(run_setenv "CMakeFiles\\run-setenv.bat")
file(WRITE ${run_setenv} "call %*\nset\n")
execute_process(COMMAND ${run_setenv} "${MP_SETENV}" "${setenv_arg}"
OUTPUT_VARIABLE out ERROR_VARIABLE err)
string(REPLACE ";" "\;" out "${out}")
string(REGEX MATCHALL "[^\n]+\n" out "${out}")
foreach (env ${out})
if (env MATCHES "([^=]+)=(.*)\n")
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
endif ()
endforeach ()
# If Microsoft SDK is installed create script run-msbuild.bat that
# calls SetEnv.cmd to set up build environment and runs msbuild.
# It is useful when building Visual Studio projects with the SDK
# toolchain rather than Visual Studio.
# Set FrameworkPathOverride to get rid of MSB3644 warnings.
file(WRITE "${CMAKE_BINARY_DIR}/run-msbuild.bat" "
call \"${MP_SETENV}\" ${setenv_arg}
msbuild -p:FrameworkPathOverride=^\"C:\\Program Files^
\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0^\" %*")
endif ()
endif ()