Skip to content

Commit 9f0888a

Browse files
committed
cmake: don't find_package if target already present
Better for super build integration (#4543)
1 parent 92b17b8 commit 9f0888a

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

cmake/check_deps.cmake

-5
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ if(USE_SCIP)
109109
set(SCIP_DEPS SCIP::libscip)
110110
endif()
111111

112-
# Check optional Dependencies
113-
if(USE_CPLEX AND NOT TARGET CPLEX::CPLEX)
114-
message(FATAL_ERROR "Target CPLEX::CPLEX not available.")
115-
endif()
116-
117112
# CXX Test
118113
if(BUILD_TESTING)
119114
if(NOT TARGET GTest::gtest_main)

cmake/system_deps.cmake

+43-31
Original file line numberDiff line numberDiff line change
@@ -22,93 +22,105 @@ find_package(Threads REQUIRED)
2222
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
2323

2424
# libprotobuf force us to depends on ZLIB::ZLIB target
25-
if(NOT BUILD_ZLIB)
25+
if(NOT BUILD_ZLIB AND NOT TARGET ZLIB::ZLIB)
2626
find_package(ZLIB REQUIRED)
2727
endif()
2828

29-
if(NOT BUILD_absl)
29+
if(NOT BUILD_absl AND NOT TARGET absl::base)
3030
find_package(absl REQUIRED)
3131
endif()
3232

33-
if(NOT BUILD_Protobuf)
33+
if(NOT BUILD_Protobuf AND NOT TARGET protobuf::libprotobuf)
3434
find_package(Protobuf REQUIRED)
3535
endif()
3636

37-
if(NOT BUILD_Eigen3)
37+
if(NOT BUILD_Eigen3 AND NOT TARGET Eigen3::Eigen)
3838
find_package(Eigen3 REQUIRED)
3939
endif()
4040

4141
if(NOT BUILD_re2 AND NOT TARGET re2::re2)
4242
find_package(re2 REQUIRED)
4343
endif()
4444

45+
# Third Party Solvers
4546
if(USE_COINOR)
46-
if(NOT BUILD_CoinUtils)
47+
if(NOT BUILD_CoinUtils AND NOT TARGET Coin::CoinUtils)
4748
find_package(CoinUtils REQUIRED)
4849
endif()
4950

50-
if(NOT BUILD_Osi)
51+
if(NOT BUILD_Osi AND NOT TARGET Coin::Osi)
5152
find_package(Osi REQUIRED)
5253
endif()
5354

54-
if(NOT BUILD_Clp)
55+
if(NOT BUILD_Clp AND NOT TARGET Coin::ClpSolver)
5556
find_package(Clp REQUIRED)
5657
endif()
5758

58-
if(NOT BUILD_Cgl)
59+
if(NOT BUILD_Cgl AND NOT TARGET Coin::Cgl)
5960
find_package(Cgl REQUIRED)
6061
endif()
6162

62-
if(NOT BUILD_Cbc)
63+
if(NOT BUILD_Cbc AND NOT TARGET Coin::CbcSolver)
6364
find_package(Cbc REQUIRED)
6465
endif()
6566
endif()
6667

67-
if(USE_GLPK AND NOT BUILD_GLPK)
68-
find_package(GLPK REQUIRED)
68+
if(USE_CPLEX)
69+
if(NOT TARGET CPLEX::CPLEX)
70+
find_package(CPLEX REQUIRED)
71+
endif()
6972
endif()
7073

71-
if(USE_HIGHS AND NOT BUILD_HIGHS)
72-
find_package(HIGHS REQUIRED)
74+
if(USE_GLPK)
75+
if(NOT BUILD_GLPK AND NOT TARGET GLPK::GLPK)
76+
find_package(GLPK REQUIRED)
77+
endif()
7378
endif()
7479

75-
if(USE_PDLP AND NOT BUILD_PDLP)
76-
find_package(PDLP REQUIRED)
80+
if(USE_HIGHS)
81+
if(NOT BUILD_HIGHS AND NOT TARGET highs::highs)
82+
find_package(HIGHS REQUIRED)
83+
endif()
7784
endif()
7885

79-
if(USE_SCIP AND NOT BUILD_SCIP)
80-
find_package(SCIP REQUIRED)
86+
if(USE_PDLP)
87+
if(NOT BUILD_PDLP)
88+
find_package(PDLP REQUIRED)
89+
endif()
8190
endif()
8291

83-
# Check optional Dependencies
84-
if(USE_CPLEX)
85-
find_package(CPLEX REQUIRED)
92+
if(USE_SCIP)
93+
if(NOT BUILD_SCIP AND NOT TARGET SCIP::libscip)
94+
find_package(SCIP REQUIRED)
95+
endif()
8696
endif()
8797

8898
# CXX Test
89-
if(BUILD_TESTING AND NOT BUILD_googletest)
90-
find_package(GTest REQUIRED)
91-
endif()
99+
if(BUILD_TESTING)
100+
if(NOT BUILD_googletest AND NOT TARGET GTest::gtest_main)
101+
find_package(GTest REQUIRED)
102+
endif()
92103

93-
if(BUILD_TESTING AND NOT BUILD_benchmark)
94-
find_package(benchmark REQUIRED)
95-
endif()
104+
if(NOT BUILD_benchmark AND NOT TARGET benchmark::benchmark)
105+
find_package(benchmark REQUIRED)
106+
endif()
96107

97-
if(BUILD_TESTING AND NOT BUILD_fuzztest)
98-
find_package(fuzztest REQUIRED)
108+
if(NOT BUILD_fuzztest AND NOT TARGET fuzztest::fuzztest)
109+
find_package(fuzztest REQUIRED)
110+
endif()
99111
endif()
100112

101113
# Check language Dependencies
102114
if(BUILD_PYTHON)
103-
if(NOT BUILD_pybind11)
115+
if(NOT BUILD_pybind11 AND NOT TARGET pybind11::pybind11_headers)
104116
find_package(pybind11 REQUIRED)
105117
endif()
106118

107-
if(NOT BUILD_pybind11_abseil)
119+
if(NOT BUILD_pybind11_abseil AND NOT TARGET pybind11_abseil::absl_casters)
108120
find_package(pybind11_abseil REQUIRED)
109121
endif()
110122

111-
if(NOT BUILD_pybind11_protobuf)
123+
if(NOT BUILD_pybind11_protobuf AND NOT TARGET pybind11_native_proto_caster)
112124
find_package(pybind11_protobuf REQUIRED)
113125
endif()
114126
endif()

0 commit comments

Comments
 (0)