Skip to content

Commit 8f62877

Browse files
committed
init: rework it for MSVC
1 parent 09d97c1 commit 8f62877

File tree

5 files changed

+55
-31
lines changed

5 files changed

+55
-31
lines changed

ortools/init/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ package(default_visibility = ["//visibility:public"])
1616
cc_library(
1717
name = "init",
1818
hdrs = ["init.h"],
19+
srcs = ["init.cc"],
1920
deps = [
2021
"//ortools/base",
2122
"//ortools/gurobi:environment",
2223
"//ortools/sat:cp_model_solver",
24+
"//ortools/sat:cp_model_solver_helpers",
2325
"@com_google_absl//absl/flags:flag",
2426
"@com_google_absl//absl/log",
2527
"@com_google_absl//absl/log:globals",

ortools/init/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
file(GLOB _SRCS "*.h")
14+
file(GLOB _SRCS "*.h" "*.cc")
1515
set(NAME ${PROJECT_NAME}_init)
1616

1717
# Will be merge in libortools.so

ortools/init/init.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2010-2025 Google LLC
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
#include "ortools/init/init.h"
15+
16+
#include "absl/flags/flag.h"
17+
#include "absl/flags/usage.h"
18+
#include "absl/log/globals.h"
19+
#include "absl/log/initialize.h"
20+
#include "ortools/gurobi/environment.h"
21+
#include "ortools/sat/cp_model_solver.h"
22+
#include "ortools/sat/cp_model_solver_helpers.h"
23+
24+
namespace operations_research {
25+
void CppBridge::InitLogging(const std::string& usage) {
26+
absl::SetProgramUsageMessage(usage);
27+
absl::InitializeLog();
28+
}
29+
30+
void CppBridge::SetFlags(const CppFlags& flags) {
31+
absl::SetFlag(&FLAGS_stderrthreshold, flags.stderrthreshold);
32+
absl::EnableLogPrefix(flags.log_prefix);
33+
if (!flags.cp_model_dump_prefix.empty()) {
34+
absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix);
35+
}
36+
absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models);
37+
absl::SetFlag(&FLAGS_cp_model_dump_submodels,
38+
flags.cp_model_dump_submodels);
39+
absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response);
40+
}
41+
42+
bool CppBridge::LoadGurobiSharedLibrary(const std::string& full_library_path) {
43+
return LoadGurobiDynamicLibrary({full_library_path}).ok();
44+
}
45+
46+
} // namespace operations_research

ortools/init/init.h

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,9 @@
1818
#include <string>
1919
#include <vector>
2020

21-
#include "absl/flags/flag.h"
22-
#include "absl/flags/usage.h"
23-
#include "absl/log/globals.h"
24-
#include "absl/log/initialize.h"
2521
#include "ortools/base/logging.h"
2622
#include "ortools/base/version.h"
27-
#include "ortools/gurobi/environment.h"
28-
#include "ortools/sat/cp_model_solver.h"
29-
30-
ABSL_DECLARE_FLAG(std::string, cp_model_dump_prefix);
31-
ABSL_DECLARE_FLAG(bool, cp_model_dump_models);
32-
ABSL_DECLARE_FLAG(bool, cp_model_dump_submodels);
33-
ABSL_DECLARE_FLAG(bool, cp_model_dump_response);
34-
ABSL_DECLARE_FLAG(int, stderrthreshold);
23+
#include "ortools/sat/cp_model_solver_helpers.h"
3524

3625
namespace operations_research {
3726

@@ -97,10 +86,7 @@ class CppBridge {
9786
*
9887
* This must be called once before any other library from OR-Tools are used.
9988
*/
100-
static void InitLogging(const std::string& usage) {
101-
absl::SetProgramUsageMessage(usage);
102-
absl::InitializeLog();
103-
}
89+
static void InitLogging(const std::string& usage);
10490

10591
/**
10692
* Shutdown the C++ logging layer.
@@ -115,17 +101,7 @@ class CppBridge {
115101
/**
116102
* Sets all the C++ flags contained in the CppFlags structure.
117103
*/
118-
static void SetFlags(const CppFlags& flags) {
119-
absl::SetFlag(&FLAGS_stderrthreshold, flags.stderrthreshold);
120-
absl::EnableLogPrefix(flags.log_prefix);
121-
if (!flags.cp_model_dump_prefix.empty()) {
122-
absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix);
123-
}
124-
absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models);
125-
absl::SetFlag(&FLAGS_cp_model_dump_submodels,
126-
flags.cp_model_dump_submodels);
127-
absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response);
128-
}
104+
static void SetFlags(const CppFlags& flags);
129105

130106
/**
131107
* Load the gurobi shared library.
@@ -135,9 +111,7 @@ class CppBridge {
135111
* You need to pass the full path, including the shared library file.
136112
* It returns true if the library was found and correctly loaded.
137113
*/
138-
static bool LoadGurobiSharedLibrary(const std::string& full_library_path) {
139-
return LoadGurobiDynamicLibrary({full_library_path}).ok();
140-
}
114+
static bool LoadGurobiSharedLibrary(const std::string& full_library_path);
141115

142116
/**
143117
* Delete a temporary C++ byte array.

ortools/sat/cp_model_solver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "ortools/sat/model.h"
2222
#include "ortools/sat/sat_parameters.pb.h"
2323

24+
ABSL_DECLARE_FLAG(bool, cp_model_dump_response);
25+
2426
namespace operations_research {
2527
namespace sat {
2628

0 commit comments

Comments
 (0)