scs 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/LICENSE.txt +18 -18
  4. data/README.md +12 -7
  5. data/lib/scs/ffi.rb +30 -13
  6. data/lib/scs/solver.rb +32 -14
  7. data/lib/scs/version.rb +1 -1
  8. data/vendor/scs/CITATION.cff +39 -0
  9. data/vendor/scs/CMakeLists.txt +272 -0
  10. data/vendor/scs/Makefile +24 -15
  11. data/vendor/scs/README.md +8 -216
  12. data/vendor/scs/include/aa.h +67 -23
  13. data/vendor/scs/include/cones.h +17 -17
  14. data/vendor/scs/include/glbopts.h +98 -32
  15. data/vendor/scs/include/linalg.h +2 -4
  16. data/vendor/scs/include/linsys.h +58 -44
  17. data/vendor/scs/include/normalize.h +3 -3
  18. data/vendor/scs/include/rw.h +8 -2
  19. data/vendor/scs/include/scs.h +293 -133
  20. data/vendor/scs/include/util.h +3 -15
  21. data/vendor/scs/linsys/cpu/direct/private.c +220 -224
  22. data/vendor/scs/linsys/cpu/direct/private.h +13 -7
  23. data/vendor/scs/linsys/cpu/indirect/private.c +177 -110
  24. data/vendor/scs/linsys/cpu/indirect/private.h +8 -4
  25. data/vendor/scs/linsys/csparse.c +87 -0
  26. data/vendor/scs/linsys/csparse.h +34 -0
  27. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +1 -1
  28. data/vendor/scs/linsys/external/amd/amd_internal.h +1 -1
  29. data/vendor/scs/linsys/external/qdldl/changes +2 -0
  30. data/vendor/scs/linsys/external/qdldl/qdldl.c +29 -46
  31. data/vendor/scs/linsys/external/qdldl/qdldl.h +33 -41
  32. data/vendor/scs/linsys/external/qdldl/qdldl_types.h +11 -3
  33. data/vendor/scs/linsys/gpu/gpu.c +58 -21
  34. data/vendor/scs/linsys/gpu/gpu.h +66 -28
  35. data/vendor/scs/linsys/gpu/indirect/private.c +368 -154
  36. data/vendor/scs/linsys/gpu/indirect/private.h +26 -12
  37. data/vendor/scs/linsys/scs_matrix.c +498 -0
  38. data/vendor/scs/linsys/scs_matrix.h +70 -0
  39. data/vendor/scs/scs.mk +13 -9
  40. data/vendor/scs/src/aa.c +384 -109
  41. data/vendor/scs/src/cones.c +440 -353
  42. data/vendor/scs/src/ctrlc.c +15 -5
  43. data/vendor/scs/src/linalg.c +84 -28
  44. data/vendor/scs/src/normalize.c +22 -64
  45. data/vendor/scs/src/rw.c +161 -22
  46. data/vendor/scs/src/scs.c +768 -561
  47. data/vendor/scs/src/scs_version.c +9 -3
  48. data/vendor/scs/src/util.c +37 -106
  49. data/vendor/scs/test/minunit.h +17 -8
  50. data/vendor/scs/test/problem_utils.h +176 -14
  51. data/vendor/scs/test/problems/degenerate.h +130 -0
  52. data/vendor/scs/test/problems/hs21_tiny_qp.h +124 -0
  53. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +116 -0
  54. data/vendor/scs/test/problems/infeasible_tiny_qp.h +100 -0
  55. data/vendor/scs/test/problems/qafiro_tiny_qp.h +199 -0
  56. data/vendor/scs/test/problems/random_prob +0 -0
  57. data/vendor/scs/test/problems/random_prob.h +45 -0
  58. data/vendor/scs/test/problems/rob_gauss_cov_est.h +188 -31
  59. data/vendor/scs/test/problems/small_lp.h +13 -14
  60. data/vendor/scs/test/problems/test_fails.h +43 -0
  61. data/vendor/scs/test/problems/unbounded_tiny_qp.h +82 -0
  62. data/vendor/scs/test/random_socp_prob.c +54 -53
  63. data/vendor/scs/test/rng.h +109 -0
  64. data/vendor/scs/test/run_from_file.c +19 -10
  65. data/vendor/scs/test/run_tests.c +27 -3
  66. metadata +25 -97
  67. data/vendor/scs/linsys/amatrix.c +0 -305
  68. data/vendor/scs/linsys/amatrix.h +0 -36
  69. data/vendor/scs/linsys/amatrix.o +0 -0
  70. data/vendor/scs/linsys/cpu/direct/private.o +0 -0
  71. data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
  72. data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
  73. data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
  74. data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
  75. data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
  76. data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
  77. data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
  78. data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
  79. data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
  80. data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
  81. data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
  82. data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
  83. data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
  84. data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
  85. data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
  86. data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
  87. data/vendor/scs/src/aa.o +0 -0
  88. data/vendor/scs/src/cones.o +0 -0
  89. data/vendor/scs/src/ctrlc.o +0 -0
  90. data/vendor/scs/src/linalg.o +0 -0
  91. data/vendor/scs/src/normalize.o +0 -0
  92. data/vendor/scs/src/rw.o +0 -0
  93. data/vendor/scs/src/scs.o +0 -0
  94. data/vendor/scs/src/scs_version.o +0 -0
  95. data/vendor/scs/src/util.o +0 -0
  96. data/vendor/scs/test/data/small_random_socp +0 -0
  97. data/vendor/scs/test/problems/small_random_socp.h +0 -33
  98. data/vendor/scs/test/run_tests +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6336ca9d1433f92e77c259062923fa2ce96888d215a6070b5e780730b621571a
4
- data.tar.gz: 264f3030f2ddf34565c33dba5d1af5dc6ac8bc11f7ef1f4cf9130646825b48b5
3
+ metadata.gz: 9e9285e6e364ac8096c960ae6a00f5b62c6c4790bbd8ca067af9ca35c3652385
4
+ data.tar.gz: 457069e09fe911cb688fcdd8c251dfc3282de4700aa04aadf8d1873528c8efea
5
5
  SHA512:
6
- metadata.gz: 6a8ffbd1707be25370186a84542eec3b37f13e452a7f202b04c1386c11fb0df05ccadf86d4268a926cae2266e6b21daf3f19925731bf71eb934360e5772f7b9a
7
- data.tar.gz: 850a9e91d62bade7ac1e644745f7eb3b9194d09f894ed6e54f29ab3923d746a8f6ee641c99789f9a0768563e280654b585293ff9bbd9ada09a9f613d4155434a
6
+ metadata.gz: af56c89f3a6cd61f89967da3521e79fab543b66bd57d66df42800b3bbcd600ed8acd8d3390e31d4dbc94d15e55d31743685622388029fa9be6906c6a041945c8
7
+ data.tar.gz: e888d39ba02de61ae2fb4f166502de4442743608bea769d8fd01b9f08537ddb3ca6ac2790a49a73ed3900a983419c899ea28cf7a35a544b610a46ac68408fd38
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 0.3.1 (2021-10-08)
2
+
3
+ - Fixed installation on Linux
4
+
5
+ ## 0.3.0 (2021-10-05)
6
+
7
+ - Updated SCS to 3.0.0
8
+
9
+ ## 0.2.3 (2021-09-09)
10
+
11
+ - Updated SCS to 2.1.4
12
+
13
+ ## 0.2.2 (2020-07-21)
14
+
15
+ - Updated SCS to 2.1.2
16
+
1
17
  ## 0.2.1 (2019-11-29)
2
18
 
3
19
  - Fixed installation on Windows
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2019 Andrew Kane
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2012 Brendan O'Donoghue (bodonoghue85@gmail.com)
4
+ Copyright (c) 2019-2021 Andrew Kane
4
5
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
12
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
15
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  :fire: Supports many different [problem types](https://www.cvxpy.org/tutorial/advanced/index.html#choosing-a-solver)
6
6
 
7
- [![Build Status](https://travis-ci.org/ankane/scs.svg?branch=master)](https://travis-ci.org/ankane/scs) [![Build status](https://ci.appveyor.com/api/projects/status/wyn0cbgs0k5vg5tq/branch/master?svg=true)](https://ci.appveyor.com/project/ankane/scs/branch/master)
7
+ [![Build Status](https://github.com/ankane/scs/workflows/build/badge.svg?branch=master)](https://github.com/ankane/scs/actions)
8
8
 
9
9
  ## Installation
10
10
 
@@ -39,16 +39,21 @@ Default values shown
39
39
  ```ruby
40
40
  solver.solve(data, cone, {
41
41
  normalize: true, # heuristic data rescaling
42
- scale: 1.0, # if normalized, rescales by this factor
43
- rho_x: 1e-3, # x equality constraint scaling
44
- max_iters: 5000, # maximum iterations to take
45
- eps: 1e-5, # convergence tolerance
42
+ scale: 0.1, # if normalized, rescales by this factor
43
+ adaptive_scale: true, # heuristically adapt dual scale through the solve
44
+ rho_x: 1e-6, # x equality constraint scaling
45
+ max_iters: 1e5, # maximum iterations to take
46
+ eps_abs: 1e-4, # absolute feasibility tolerance
47
+ eps_rel: 1e-4, # relative feasibility tolerance
48
+ eps_infeas: 1e-7, # infeasibility tolerance
46
49
  alpha: 1.5, # relaxation parameter
47
- cg_rate: 2.0, # for indirect, tolerance goes down like (1/iter)^cg_rate
50
+ time_limit_secs: nil, # time limit for solve run in seconds
48
51
  verbose: true, # write out progress
49
52
  warm_start: false, # warm start
50
53
  acceleration_lookback: 10, # memory for acceleration
51
- write_data_filename: nil # filename to write data if set
54
+ acceleration_interval: 10, # iterations to run Anderson acceleration
55
+ write_data_filename: nil, # filename to write data if set
56
+ log_csv_filename: nil # write csv logs of various quantities
52
57
  })
53
58
  ```
54
59
 
data/lib/scs/ffi.rb CHANGED
@@ -41,14 +41,17 @@ module SCS
41
41
  "scs_int m",
42
42
  "scs_int n",
43
43
  "ScsMatrix *a",
44
+ "ScsMatrix *p",
44
45
  "scs_float *b",
45
46
  "scs_float *c",
46
- "ScsSettings *stgs"
47
47
  ]
48
48
 
49
49
  m::Cone = struct [
50
- "scs_int f",
50
+ "scs_int z",
51
51
  "scs_int l",
52
+ "scs_float *bu",
53
+ "scs_float *bl",
54
+ "scs_int *bsize",
52
55
  "scs_int *q",
53
56
  "scs_int qsize",
54
57
  "scs_int *s",
@@ -67,31 +70,45 @@ module SCS
67
70
 
68
71
  m::Info = struct [
69
72
  "scs_int iter",
70
- "char status[32]",
73
+ "char status[128]",
71
74
  "scs_int status_val",
75
+ "scs_int scale_updates",
72
76
  "scs_float pobj",
73
77
  "scs_float dobj",
74
78
  "scs_float res_pri",
75
79
  "scs_float res_dual",
80
+ "scs_float gap",
76
81
  "scs_float res_infeas",
77
- "scs_float res_unbdd",
78
- "scs_float rel_gap",
82
+ "scs_float res_unbdd_a",
83
+ "scs_float res_unbdd_p",
79
84
  "scs_float setup_time",
80
- "scs_float solve_time"
85
+ "scs_float solve_time",
86
+ "scs_float scale",
87
+ "scs_float comp_slack",
88
+ "scs_int rejected_accel_steps",
89
+ "scs_int accepted_accel_steps",
90
+ "scs_float lin_sys_time",
91
+ "scs_float cone_time",
92
+ "scs_float accel_time"
81
93
  ]
82
94
 
83
95
  m::Settings = struct [
84
96
  "scs_int normalize",
85
97
  "scs_float scale",
98
+ "scs_int adaptive_scale",
86
99
  "scs_float rho_x",
87
100
  "scs_int max_iters",
88
- "scs_float eps",
101
+ "scs_float eps_abs",
102
+ "scs_float eps_rel",
103
+ "scs_float eps_infeas",
89
104
  "scs_float alpha",
90
- "scs_float cg_rate",
105
+ "scs_float time_limit_secs",
91
106
  "scs_int verbose",
92
107
  "scs_int warm_start",
93
108
  "scs_int acceleration_lookback",
94
- "const char* write_data_filename"
109
+ "scs_int acceleration_interval",
110
+ "const char* write_data_filename",
111
+ "const char *log_csv_filename"
95
112
  ]
96
113
 
97
114
  m::Matrix = struct [
@@ -103,14 +120,14 @@ module SCS
103
120
  ]
104
121
 
105
122
  # scs.h
106
- extern "ScsWork *scs_init(const ScsData *d, const ScsCone *k, ScsInfo *info)"
107
- extern "scs_int scs_solve(ScsWork *w, const ScsData *d, const ScsCone *k, ScsSolution *sol, ScsInfo *info)"
123
+ extern "ScsWork *scs_init(const ScsData *d, const ScsCone *k, const ScsSettings *stgs)"
124
+ extern "scs_int scs_solve(ScsWork *w, ScsSolution *sol, ScsInfo *info)"
108
125
  extern "void scs_finish(ScsWork *w)"
109
- extern "scs_int scs(const ScsData *d, const ScsCone *k, ScsSolution *sol, ScsInfo *info)"
126
+ extern "scs_int scs(const ScsData *d, const ScsCone *k, const ScsSettings *stgs, ScsSolution *sol, ScsInfo *info)"
110
127
  extern "const char *scs_version(void)"
111
128
 
112
129
  # utils.h
113
- extern "void scs_set_default_settings(ScsData *d)"
130
+ extern "void scs_set_default_settings(ScsSettings *stgs)"
114
131
  end
115
132
  end
116
133
  end
data/lib/scs/solver.rb CHANGED
@@ -6,13 +6,13 @@ module SCS
6
6
 
7
7
  def solve(data, cone, **settings)
8
8
  cdata = create_data(data)
9
- set_settings(cdata, settings)
9
+ settings = create_settings(settings)
10
10
  ccone = create_cone(cone)
11
11
 
12
12
  solution = calloc(ffi::Solution.size) # alloc clear memory
13
13
  info = ffi::Info.malloc
14
14
 
15
- ffi.scs(cdata, ccone, solution, info)
15
+ ffi.scs(cdata, ccone, settings, solution, info)
16
16
 
17
17
  solution = ffi::Solution.new(solution)
18
18
  x = read_float_array(solution.x, cdata.n)
@@ -26,15 +26,24 @@ module SCS
26
26
  iter: info.iter,
27
27
  status: read_string(info.status),
28
28
  status_val: info.status_val,
29
+ scale_updates: info.scale_updates,
29
30
  pobj: info.pobj,
30
31
  dobj: info.dobj,
31
32
  res_pri: info.res_pri,
32
33
  res_dual: info.res_dual,
34
+ gap: info.gap,
33
35
  res_infeas: info.res_infeas,
34
- res_unbdd: info.res_unbdd,
35
- rel_gap: info.rel_gap,
36
+ res_unbdd_a: info.res_unbdd_a,
37
+ res_unbdd_p: info.res_unbdd_p,
36
38
  setup_time: info.setup_time,
37
- solve_time: info.solve_time
39
+ solve_time: info.solve_time,
40
+ scale: info.scale,
41
+ comp_slack: info.comp_slack,
42
+ rejected_accel_steps: info.rejected_accel_steps,
43
+ accepted_accel_steps: info.accepted_accel_steps,
44
+ lin_sys_time: info.lin_sys_time,
45
+ cone_time: info.cone_time,
46
+ accel_time: info.accel_time
38
47
  }
39
48
  end
40
49
 
@@ -44,11 +53,6 @@ module SCS
44
53
  raise Error, "Error code #{ret}" if ret != 0
45
54
  end
46
55
 
47
- def read_string(char_ptr)
48
- idx = char_ptr.index { |v| v == 0 }
49
- char_ptr[0, idx].map(&:chr).join
50
- end
51
-
52
56
  def float_array(arr)
53
57
  # SCS float = double
54
58
  Fiddle::Pointer[arr.to_a.pack("d*")]
@@ -119,15 +123,30 @@ module SCS
119
123
  cdata.m = m
120
124
  cdata.n = n
121
125
  cdata.a = csc_matrix(data[:a])
126
+
127
+ if data[:p]
128
+ raise ArgumentError, "Bad p shape" if shape(data[:p]) != [n, n]
129
+ cdata.p = csc_matrix(data[:p])
130
+ end
131
+
132
+ raise ArgumentError, "Bad b size" if data[:b].to_a.size != m
122
133
  cdata.b = float_array(data[:b])
134
+
135
+ raise ArgumentError, "Bad c size" if data[:c].to_a.size != n
123
136
  cdata.c = float_array(data[:c])
124
137
  cdata
125
138
  end
126
139
 
127
140
  def create_cone(cone)
128
141
  ccone = ffi::Cone.malloc
129
- ccone.f = cone[:f].to_i
142
+ ccone.z = cone[:z].to_i
130
143
  ccone.l = cone[:l].to_i
144
+ ccone.bu = float_array(cone[:bu])
145
+ ccone.bl = float_array(cone[:bl])
146
+ if cone[:bu].to_a.size != cone[:bl].to_a.size
147
+ raise ArgumentError, "Expected bu and bl size to match"
148
+ end
149
+ ccone.bsize = cone[:bu].to_a.size
131
150
  ccone.q = int_array(cone[:q])
132
151
  ccone.qsize = cone[:q].to_a.size
133
152
  ccone.s = int_array(cone[:s])
@@ -139,10 +158,9 @@ module SCS
139
158
  ccone
140
159
  end
141
160
 
142
- def set_settings(data, settings)
161
+ def create_settings(settings)
143
162
  set = ffi::Settings.malloc
144
- data.stgs = set
145
- ffi.scs_set_default_settings(data)
163
+ ffi.scs_set_default_settings(set)
146
164
 
147
165
  # hack for setting members with []=
148
166
  # safer than send("#{k}=", v)
data/lib/scs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SCS
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -0,0 +1,39 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below."
3
+ authors:
4
+ - family-names: "O'Donoghue"
5
+ given-names: "Brendan"
6
+ - family-names: "Chu"
7
+ given-names: "Eric"
8
+ - family-names: "Parikh"
9
+ given-names: "Neal"
10
+ - family-names: "Boyd"
11
+ given-names: "Stephen"
12
+ title: "SCS: Spltting Conic Solver"
13
+ version: 3.0.0
14
+ date-released: 2021
15
+ url: "https://github.com/cvxgrp/scs"
16
+
17
+ # Original SCS paper:
18
+ preferred-citation:
19
+ type: article
20
+ authors:
21
+ - family-names: "O'Donoghue"
22
+ given-names: "Brendan"
23
+ - family-names: "Chu"
24
+ given-names: "Eric"
25
+ - family-names: "Parikh"
26
+ given-names: "Neal"
27
+ - family-names: "Boyd"
28
+ given-names: "Stephen"
29
+ journal: "Journal of Optimization Theory and Applications"
30
+ month: 6
31
+ start: 1042 # Start pages
32
+ end: 1068 # End pages
33
+ title: "Conic Optimization via Operator Splitting and Homogeneous Self-Dual Embedding"
34
+ issue: 3
35
+ volume: 169
36
+ year: 2016
37
+ doi: 10.1007/s10957-016-0892-3
38
+ url: https://dx.doi.org/10.1007/s10957-016-0892-3
39
+
@@ -0,0 +1,272 @@
1
+ # CMakeLists.txt file for scs
2
+ # This software may be modified and distributed under the terms of the MIT License
3
+
4
+ cmake_minimum_required(VERSION 3.5)
5
+
6
+ project(scs
7
+ LANGUAGES C
8
+ VERSION 2.1.4)
9
+
10
+ # Defines the CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_BINDIR and many other useful macros.
11
+ # See https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
12
+ include(GNUInstallDirs)
13
+
14
+ # Control where libraries and executables are placed during the build.
15
+ # With the following settings executables are placed in <the top level of the
16
+ # build tree>/bin and libraries/archives in <top level of the build tree>/lib.
17
+ # This is particularly useful to run ctests on libraries built on Windows
18
+ # machines: tests, which are executables, are placed in the same folders of
19
+ # dlls, which are treated as executables as well, so that they can properly
20
+ # find the libraries to run. This is a because of missing RPATH on Windows.
21
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
22
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
23
+ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
24
+
25
+ # To build shared libraries in Windows, we set CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS to TRUE.
26
+ # See https://cmake.org/cmake/help/v3.4/variable/CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS.html
27
+ # See https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/
28
+ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
29
+
30
+ # Under MSVC, we set CMAKE_DEBUG_POSTFIX to "d" to add a trailing "d" to library
31
+ # built in debug mode. In this Windows user can compile, build and install the
32
+ # library in both Release and Debug configuration avoiding naming clashes in the
33
+ # installation directories.
34
+ if(MSVC)
35
+ set(CMAKE_DEBUG_POSTFIX "d")
36
+ endif()
37
+
38
+ # Build position independent code.
39
+ # Position Independent Code (PIC) is commonly used for shared libraries so that
40
+ # the same shared library code can be loaded in each program address space in a
41
+ # location where it will not overlap with any other uses of such memory.
42
+ # In particular, this option avoids problems occurring when a process wants to
43
+ # load more than one shared library at the same virtual address.
44
+ # Since shared libraries cannot predict where other shared libraries could be
45
+ # loaded, this is an unavoidable problem with the traditional shared library
46
+ # concept.
47
+ # Generating position-independent code is often the default behavior for most
48
+ # modern compilers.
49
+ # Moreover linking a static library that is not built with PIC from a shared
50
+ # library will fail on some compiler/architecture combinations.
51
+ # Further details on PIC can be found here:
52
+ # https://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/
53
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
54
+
55
+ # Disable C and C++ compiler extensions.
56
+ # C/CXX_EXTENSIONS are ON by default to allow the compilers to use extended
57
+ # variants of the C/CXX language.
58
+ # However, this could expose cross-platform bugs in user code or in the headers
59
+ # of third-party dependencies and thus it is strongly suggested to turn
60
+ # extensions off.
61
+ set(CMAKE_C_EXTENSIONS OFF)
62
+ set(CMAKE_CXX_EXTENSIONS OFF)
63
+ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
64
+
65
+ ### Options
66
+ # Shared/Dynamic or Static library?
67
+ option(BUILD_SHARED_LIBS "Build libraries as shared as opposed to static" ON)
68
+
69
+ # Enable RPATH support for installed binaries and libraries
70
+ include(AddInstallRPATHSupport)
71
+ add_install_rpath_support(BIN_DIRS "${CMAKE_INSTALL_FULL_BINDIR}"
72
+ LIB_DIRS "${CMAKE_INSTALL_FULL_LIBDIR}"
73
+ INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}"
74
+ USE_LINK_PATH)
75
+
76
+ # Encourage user to specify a build type (e.g. Release, Debug, etc.), otherwise set it to Release.
77
+ if(NOT CMAKE_CONFIGURATION_TYPES)
78
+ if(NOT CMAKE_BUILD_TYPE)
79
+ message(STATUS "Setting build type to 'Release' as none was specified.")
80
+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE "Release")
81
+ endif()
82
+ endif()
83
+
84
+
85
+ # Build test related commands?
86
+ option(BUILD_TESTING "Create tests using CMake" OFF)
87
+ if(BUILD_TESTING)
88
+ enable_testing()
89
+ endif()
90
+
91
+ ### Some variables useful for sampling the building process
92
+ # Note that the GPU profile is not compiled.
93
+ set(LINSYS linsys)
94
+ set(DIRSRC ${LINSYS}/cpu/direct)
95
+ set(INDIRSRC ${LINSYS}/cpu/indirect)
96
+ set(EXTERNAL ${LINSYS}/external)
97
+
98
+
99
+ # Common source files
100
+ set(${PROJECT_NAME}_SRC
101
+ src/aa.c
102
+ src/cones.c
103
+ src/ctrlc.c
104
+ src/linalg.c
105
+ src/normalize.c
106
+ src/rw.c
107
+ src/scs.c
108
+ src/scs_version.c
109
+ src/util.c
110
+ ${LINSYS}/csparse.c
111
+ ${LINSYS}/scs_matrix.c)
112
+
113
+ # Common header files
114
+ set(${PROJECT_NAME}_HDR
115
+ include/aa.h
116
+ include/cones.h
117
+ include/ctrlc.h
118
+ include/glbopts.h
119
+ include/linalg.h
120
+ include/linsys.h
121
+ include/normalize.h
122
+ include/rw.h
123
+ include/scs.h
124
+ include/scs_blas.h
125
+ include/util.h
126
+ ${LINSYS}/csparse.h
127
+ ${LINSYS}/scs_matrix.h)
128
+
129
+ # get all the c file in amd/external
130
+ file(GLOB ${PROJECT_NAME}_AMD_EXTERNAL_SRC
131
+ ${EXTERNAL}/amd/*.c
132
+ )
133
+
134
+ # get all the h file in amd/external
135
+ file(GLOB ${PROJECT_NAME}_AMD_EXTERNAL_HDR
136
+ ${EXTERNAL}/amd/*.h
137
+ )
138
+
139
+ # get all the c file in amd/external
140
+ file(GLOB ${PROJECT_NAME}_LDL_EXTERNAL_HDR
141
+ ${EXTERNAL}/qdldl/*.h
142
+ )
143
+
144
+ ### Direct method
145
+ # Here we compile the direct method library
146
+ set(${PROJECT_NAME}_DIRECT ${PROJECT_NAME}dir)
147
+ add_library(${${PROJECT_NAME}_DIRECT}
148
+ ${${PROJECT_NAME}_HDR}
149
+ ${${PROJECT_NAME}_SRC}
150
+ ${DIRSRC}/private.c
151
+ ${DIRSRC}/private.h
152
+ ${EXTERNAL}/qdldl/qdldl.c
153
+ ${${PROJECT_NAME}_AMD_EXTERNAL_SRC}
154
+ ${${PROJECT_NAME}_AMD_EXTERNAL_HDR}
155
+ ${${PROJECT_NAME}_LDL_EXTERNAL_HDR})
156
+
157
+ target_include_directories(${${PROJECT_NAME}_DIRECT} PRIVATE
158
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${EXTERNAL}/amd;${CMAKE_CURRENT_SOURCE_DIR}/${EXTERNAL}/qdldl;${CMAKE_CURRENT_SOURCE_DIR}/${DIRSRC};${CMAKE_CURRENT_SOURCE_DIR}/${LINSYS}>")
159
+
160
+ target_include_directories(${${PROJECT_NAME}_DIRECT} PUBLIC
161
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
162
+ "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/scs>")
163
+
164
+ # Compiled with blas and lapack, can solve LPs, SOCPs, SDPs, ECPs, and PCPs
165
+ target_compile_definitions(${${PROJECT_NAME}_DIRECT} PRIVATE -DUSE_LAPACK -DCOPYAMATRIX -DCTRLC)
166
+
167
+ # The library depends on math (m) blas and lapack
168
+ target_link_libraries(${${PROJECT_NAME}_DIRECT} PRIVATE
169
+ m
170
+ blas
171
+ lapack)
172
+
173
+ # Set some properties
174
+ set_target_properties(${${PROJECT_NAME}_DIRECT} PROPERTIES
175
+ VERSION ${scs_VERSION}
176
+ PUBLIC_HEADER "${${PROJECT_NAME}_HDR}")
177
+
178
+ add_library(scs::${${PROJECT_NAME}_DIRECT} ALIAS ${${PROJECT_NAME}_DIRECT})
179
+
180
+ # Install the library
181
+ install(TARGETS ${${PROJECT_NAME}_DIRECT}
182
+ EXPORT ${PROJECT_NAME}
183
+ COMPONENT runtime
184
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
185
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib
186
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
187
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/scs")
188
+
189
+ # Add the direct method to the set of the compiled targets
190
+ set_property(GLOBAL APPEND PROPERTY scs_TARGETS ${${PROJECT_NAME}_DIRECT})
191
+
192
+ ### Indirect method
193
+ # Here we compile the indirect method library
194
+ set(${PROJECT_NAME}_INDIRECT ${PROJECT_NAME}indir)
195
+ add_library(${${PROJECT_NAME}_INDIRECT}
196
+ ${${PROJECT_NAME}_HDR}
197
+ ${${PROJECT_NAME}_SRC}
198
+ ${INDIRSRC}/private.c
199
+ ${INDIRSRC}/private.h
200
+ ${${${PROJECT_NAME}_INDIRECT}_HDR}
201
+ )
202
+
203
+
204
+ target_include_directories(${${PROJECT_NAME}_INDIRECT} PRIVATE
205
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${EXTERNAL}/amd;${CMAKE_CURRENT_SOURCE_DIR}/${EXTERNAL}/qdldl;${CMAKE_CURRENT_SOURCE_DIR}/${INDIRSRC};${CMAKE_CURRENT_SOURCE_DIR}/${LINSYS}>")
206
+
207
+ target_include_directories(${${PROJECT_NAME}_INDIRECT} PUBLIC
208
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
209
+ "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/scs>")
210
+
211
+ # Compiled with blas and lapack, can solve LPs, SOCPs, SDPs, ECPs, and PCPs
212
+ target_compile_definitions(${${PROJECT_NAME}_INDIRECT} PRIVATE -DUSE_LAPACK -DCOPYAMATRIX -DCTRLC -DINDIRECT)
213
+
214
+ # The library depends on math (m) blas and lapack
215
+ target_link_libraries(${${PROJECT_NAME}_INDIRECT} PUBLIC
216
+ m
217
+ blas
218
+ lapack)
219
+
220
+ # Set some properties
221
+ set_target_properties(${${PROJECT_NAME}_INDIRECT} PROPERTIES
222
+ VERSION ${scs_VERSION}
223
+ PUBLIC_HEADER "${${${PROJECT_NAME}_INDIRECT}_HDR}")
224
+
225
+ add_library(scs::${${PROJECT_NAME}_INDIRECT} ALIAS ${${PROJECT_NAME}_INDIRECT})
226
+
227
+ # Install the library
228
+ install(TARGETS ${${PROJECT_NAME}_INDIRECT}
229
+ EXPORT ${PROJECT_NAME}
230
+ COMPONENT runtime
231
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
232
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib
233
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
234
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/scs")
235
+
236
+ # Add the indirect method to the set of the compiled targets
237
+ set_property(GLOBAL APPEND PROPERTY scs_TARGETS ${${PROJECT_NAME}_INDIRECT})
238
+
239
+ ### Install the .cmake file.
240
+ # Thanks to thanks file it will be possible to link scs to consumer libraries
241
+ include(InstallBasicPackageFiles)
242
+ install_basic_package_files(${PROJECT_NAME}
243
+ NAMESPACE scs::
244
+ VERSION ${${PROJECT_NAME}_VERSION}
245
+ TARGETS_PROPERTY scs_TARGETS
246
+ COMPATIBILITY SameMajorVersion
247
+ VARS_PREFIX ${PROJECT_NAME}
248
+ NO_CHECK_REQUIRED_COMPONENTS_MACRO)
249
+
250
+ ### Add the tests
251
+ if(BUILD_TESTING)
252
+ add_executable(run_tests_direct test/run_tests.c)
253
+ target_link_libraries(run_tests_direct PRIVATE
254
+ scs::scsdir)
255
+ target_include_directories(run_tests_direct PRIVATE
256
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test;${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_SOURCE_DIR}/${LINSYS}>")
257
+
258
+ add_test(NAME run_tests_direct
259
+ COMMAND run_tests_direct
260
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
261
+
262
+ add_executable(run_tests_indirect test/run_tests.c)
263
+ target_link_libraries(run_tests_indirect PRIVATE
264
+ scs::scsindir)
265
+ target_include_directories(run_tests_indirect PRIVATE
266
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test;${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_SOURCE_DIR}/${LINSYS}>")
267
+
268
+ add_test(NAME run_tests_indirect
269
+ COMMAND run_tests_indirect
270
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
271
+
272
+ endif()