Skip to content

Commit

Permalink
cmake: Split math_opt into sub library
Browse files Browse the repository at this point in the history
XCode do not support object library with several file with the same name
since it use a flat directory, Xcode "fix" using a UID but CMake can't catch it.

math_opt also use a parameters.proto which conflict with the
glop/parameters.proto -> need to split the proto to .cc generation in
two libraries
  • Loading branch information
Mizux committed Sep 25, 2023
1 parent a42814c commit d8634ab
Show file tree
Hide file tree
Showing 36 changed files with 634 additions and 213 deletions.
335 changes: 199 additions & 136 deletions cmake/cpp.cmake

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ortools/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ target_link_libraries(${NAME} PRIVATE
absl::memory
absl::str_format
protobuf::libprotobuf
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::algorithms ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::algorithms ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ target_link_libraries(${NAME} PRIVATE
absl::strings
absl::str_format
protobuf::libprotobuf
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::base ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::base ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/bop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ target_link_libraries(${NAME} PRIVATE
absl::synchronization
absl::str_format
protobuf::libprotobuf
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::bop ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::bop ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/constraint_solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ target_link_libraries(${NAME} PRIVATE
absl::strings
absl::str_format
protobuf::libprotobuf
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::constraint_solver ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::constraint_solver ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/glop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ target_link_libraries(${NAME} PRIVATE
absl::strings
absl::str_format
protobuf::libprotobuf
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::glop ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::glop ALIAS ${NAME})
2 changes: 1 addition & 1 deletion ortools/glpk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ target_link_libraries(${NAME} PRIVATE
absl::strings
absl::str_format
$<$<BOOL:${USE_GLPK}>:GLPK::GLPK>)
#add_library(${PROJECT_NAME}::glpk ALIAS ${NAME})
#add_library(${PROJECT_NAMESPACE}::glpk ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ target_link_libraries(${NAME} PRIVATE
absl::strings
absl::str_format
protobuf::libprotobuf
${PROJECT_NAME}::proto
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto
$<$<BOOL:${USE_COINOR}>:Coin::Cbc>)
#add_library(${PROJECT_NAME}::graph ALIAS ${NAME})
#add_library(${PROJECT_NAMESPACE}::graph ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/gscip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ target_link_libraries(${NAME} PRIVATE
absl::str_format
protobuf::libprotobuf
$<$<BOOL:${USE_SCIP}>:libscip>
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::gscip ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::gscip ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/gurobi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ target_link_libraries(${NAME} PRIVATE
absl::strings
absl::str_format
protobuf::libprotobuf
${PROJECT_NAME}::proto
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto
$<$<BOOL:${USE_COINOR}>:Coin::Cbc>)
#add_library(${PROJECT_NAME}::gurobi ALIAS ${NAME})
#add_library(${PROJECT_NAMESPACE}::gurobi ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/init/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ target_link_libraries(${NAME} PRIVATE
absl::flags
absl::strings
protobuf::libprotobuf
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::init ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::init ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/linear_solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ target_link_libraries(${NAME} PRIVATE
$<$<BOOL:${USE_PDLP}>:Eigen3::Eigen>
$<$<BOOL:${USE_SCIP}>:libscip>
$<$<BOOL:${USE_XPRESS}>:XPRESS::XPRESS>
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::linear_solver ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::linear_solver ALIAS ${NAME})

# solve
add_executable(solve)
Expand Down
5 changes: 2 additions & 3 deletions ortools/linear_solver/proto_solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ target_link_libraries(${NAME} PRIVATE
absl::strings
absl::status
absl::str_format
protobuf::libprotobuf
$<$<BOOL:${USE_PDLP}>:Eigen3::Eigen>
$<$<BOOL:${USE_SCIP}>:libscip>
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::linear_solver ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::linear_solver_proto_solver ALIAS ${NAME})
5 changes: 2 additions & 3 deletions ortools/linear_solver/wrappers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ target_include_directories(${NAME} PRIVATE
${PROJECT_BINARY_DIR})
target_link_libraries(${NAME} PRIVATE
absl::status
protobuf::libprotobuf
$<$<BOOL:${USE_SCIP}>:libscip>
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::_linear_solver_wrappers ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::linear_solver_wrappers ALIAS ${NAME})
4 changes: 2 additions & 2 deletions ortools/lp_data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ target_link_libraries(${NAME} PRIVATE
absl::str_format
protobuf::libprotobuf
${RE2_DEPS}
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::lp_data ALIAS ${NAME})
${PROJECT_NAMESPACE}::${PROJECT_NAME}_proto)
#add_library(${PROJECT_NAMESPACE}::lp_data ALIAS ${NAME})
56 changes: 22 additions & 34 deletions ortools/math_opt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,27 @@ if(NOT BUILD_MATH_OPT)
return()
endif()

file(GLOB_RECURSE _SRCS "*.h" "*.cc")
list(FILTER _SRCS EXCLUDE REGEX "/[^/]*_test\\.cc$")
list(FILTER _SRCS EXCLUDE REGEX "/c_api/.*example")
list(FILTER _SRCS EXCLUDE REGEX "/tools/")
list(FILTER _SRCS EXCLUDE REGEX "/samples/")

if(NOT USE_GLPK)
list(FILTER _SRCS EXCLUDE REGEX "/glpk/")
list(FILTER _SRCS EXCLUDE REGEX "/glpk_.*.h$")
list(FILTER _SRCS EXCLUDE REGEX "/glpk_.*.cc$")
endif()

if(NOT USE_SCIP)
list(FILTER _SRCS EXCLUDE REGEX "/gscip/")
list(FILTER _SRCS EXCLUDE REGEX "/gscip_.*.h$")
list(FILTER _SRCS EXCLUDE REGEX "/gscip_.*.cc$")
endif()
add_subdirectory(core)
add_subdirectory(constraints)
add_subdirectory(cpp)
add_subdirectory(io)
add_subdirectory(labs)
add_subdirectory(solvers)
add_subdirectory(storage)
add_subdirectory(validators)

set(NAME ${PROJECT_NAME}_math_opt)

# Will be merge in libortools.so
#add_library(${NAME} STATIC ${_SRCS})
add_library(${NAME} OBJECT ${_SRCS})
set_target_properties(${NAME} PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
target_include_directories(${NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
target_link_libraries(${NAME} PRIVATE
absl::strings
protobuf::libprotobuf
$<$<BOOL:${USE_GLPK}>:GLPK::GLPK>
$<$<BOOL:${USE_SCIP}>:libscip>
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::math_opt ALIAS ${NAME})
add_library(${NAME} OBJECT)
target_sources(${NAME} PUBLIC
$<TARGET_OBJECTS:${NAME}_core>
$<TARGET_OBJECTS:${NAME}_cpp>
$<TARGET_OBJECTS:${NAME}_io>
$<TARGET_OBJECTS:${NAME}_labs>
$<TARGET_OBJECTS:${NAME}_solvers>
$<TARGET_OBJECTS:${NAME}_storage>
$<TARGET_OBJECTS:${NAME}_validators>
)
target_link_libraries(${NAME} INTERFACE
${NAME}_constraints
)
install(TARGETS ${PROJECT_NAME}_math_opt EXPORT ${PROJECT_NAME}Targets)
29 changes: 29 additions & 0 deletions ortools/math_opt/constraints/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_subdirectory(indicator)
add_subdirectory(quadratic)
add_subdirectory(second_order_cone)
add_subdirectory(sos)
add_subdirectory(util)

set(NAME ${PROJECT_NAME}_math_opt_constraints)
add_library(${NAME} OBJECT)
target_sources(${NAME} PUBLIC
$<TARGET_OBJECTS:${NAME}_indicator>
$<TARGET_OBJECTS:${NAME}_quadratic>
$<TARGET_OBJECTS:${NAME}_second_order_cone>
$<TARGET_OBJECTS:${NAME}_sos>
$<TARGET_OBJECTS:${NAME}_util>
)
install(TARGETS ${PROJECT_NAME}_math_opt_constraints EXPORT ${PROJECT_NAME}Targets)
26 changes: 26 additions & 0 deletions ortools/math_opt/constraints/indicator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(NAME ${PROJECT_NAME}_math_opt_constraints_indicator)
add_library(${NAME} OBJECT)

file(GLOB _SRCS "*.h" "*.cc")
target_sources(${NAME} PRIVATE ${_SRCS})
set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
target_link_libraries(${NAME} PRIVATE
absl::strings
${PROJECT_NAMESPACE}::math_opt_proto)
#install(TARGETS ${PROJECT_NAME}_math_opt_constraints_indicator EXPORT ${PROJECT_NAME}Targets)
25 changes: 25 additions & 0 deletions ortools/math_opt/constraints/quadratic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(NAME ${PROJECT_NAME}_math_opt_constraints_quadratic)
add_library(${NAME} OBJECT)

file(GLOB _SRCS "*.h" "*.cc")
target_sources(${NAME} PRIVATE ${_SRCS})
set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
target_link_libraries(${NAME} PRIVATE
absl::strings
${PROJECT_NAMESPACE}::math_opt_proto)
25 changes: 25 additions & 0 deletions ortools/math_opt/constraints/second_order_cone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(NAME ${PROJECT_NAME}_math_opt_constraints_second_order_cone)
add_library(${NAME} OBJECT)

file(GLOB _SRCS "*.h" "*.cc")
target_sources(${NAME} PRIVATE ${_SRCS})
set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
target_link_libraries(${NAME} PRIVATE
absl::strings
${PROJECT_NAMESPACE}::math_opt_proto)
25 changes: 25 additions & 0 deletions ortools/math_opt/constraints/sos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(NAME ${PROJECT_NAME}_math_opt_constraints_sos)
add_library(${NAME} OBJECT)

file(GLOB _SRCS "*.h" "*.cc")
target_sources(${NAME} PRIVATE ${_SRCS})
set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
target_link_libraries(${NAME} PRIVATE
absl::strings
${PROJECT_NAMESPACE}::math_opt_proto)
25 changes: 25 additions & 0 deletions ortools/math_opt/constraints/util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(NAME ${PROJECT_NAME}_math_opt_constraints_util)
add_library(${NAME} OBJECT)

file(GLOB _SRCS "*.h" "*.cc")
target_sources(${NAME} PRIVATE ${_SRCS})
set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
target_link_libraries(${NAME} PRIVATE
absl::strings
${PROJECT_NAMESPACE}::math_opt_proto)
28 changes: 28 additions & 0 deletions ortools/math_opt/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_subdirectory(c_api)

file(GLOB _SRCS "*.h" "*.cc")
list(FILTER _SRCS EXCLUDE REGEX "/[^/]*_test\\.cc$")

set(NAME ${PROJECT_NAME}_math_opt_core)
add_library(${NAME} OBJECT ${_SRCS})
target_sources(${NAME} PRIVATE $<TARGET_OBJECTS:${NAME}_c_api>)
set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
target_link_libraries(${NAME} PRIVATE
absl::strings
${PROJECT_NAMESPACE}::math_opt_proto)
24 changes: 24 additions & 0 deletions ortools/math_opt/core/c_api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(NAME ${PROJECT_NAME}_math_opt_core_c_api)
add_library(${NAME} OBJECT)

target_sources(${NAME} PRIVATE solver.h solver.cc)
set_target_properties(${NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
target_link_libraries(${NAME} PRIVATE
absl::strings
${PROJECT_NAMESPACE}::math_opt_proto)
Loading

1 comment on commit d8634ab

@Mizux
Copy link
Collaborator Author

@Mizux Mizux commented on d8634ab Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix #3909

Please sign in to comment.