Skip to content

Commit

Permalink
Simplify incompatible build option prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed Jul 8, 2024
1 parent bd63126 commit d6bc2cc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 96 deletions.
103 changes: 7 additions & 96 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ endif()
set(WPILIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

include(CPack)
include(OptionValidation)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Expand Down Expand Up @@ -85,28 +86,6 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE)
endif()

if(WITH_JAVA AND NOT BUILD_SHARED_LIBS)
message(
FATAL_ERROR
"
FATAL: Cannot build static libs with Java enabled.
Static libs requires both BUILD_SHARED_LIBS=OFF and
WITH_JAVA=OFF
"
)
endif()

if(WITH_SIMULATION_MODULES AND NOT BUILD_SHARED_LIBS)
message(
FATAL_ERROR
"
FATAL: Cannot build static libs with simulation modules enabled.
Static libs requires both BUILD_SHARED_LIBS=OFF and
WITH_SIMULATION_MODULES=OFF
"
)
endif()

if(NOT WITH_JAVA OR NOT WITH_CSCORE)
if(NOT "${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "")
message(
Expand All @@ -119,85 +98,17 @@ It will be ignored.
endif()
endif()

if(NOT WITH_WPILIB AND WITH_SIMULATION_MODULES)
message(
FATAL_ERROR
"
FATAL: Cannot build simulation modules with wpilib disabled.
Enable wpilib by setting WITH_WPILIB=ON
"
)
endif()

if(NOT WITH_NTCORE AND WITH_CSCORE)
message(
FATAL_ERROR
"
FATAL: Cannot build cameraserver without ntcore.
Enable ntcore by setting WITH_NTCORE=ON
"
)
endif()

if(NOT WITH_NTCORE AND WITH_GUI)
message(
FATAL_ERROR
"
FATAL: Cannot build GUI modules without ntcore.
Enable ntcore by setting WITH_NTCORE=ON
"
)
endif()
wpilib_config(OPTIONS WITH_JAVA REQUIRES BUILD_SHARED_LIBS)

if(NOT WITH_NTCORE AND WITH_SIMULATION_MODULES)
message(
FATAL_ERROR
"
FATAL: Cannot build simulation modules without ntcore.
Enable ntcore by setting WITH_NTCORE=ON
"
)
endif()
wpilib_config(OPTIONS WITH_SIMULATION_MODULES REQUIRES BUILD_SHARED_LIBS WITH_WPILIB WITH_NTCORE)

if(NOT WITH_NTCORE AND WITH_WPILIB)
message(
FATAL_ERROR
"
FATAL: Cannot build wpilib without ntcore.
Enable ntcore by setting WITH_NTCORE=ON
"
)
endif()
wpilib_config(OPTIONS WITH_CSCORE REQUIRES WITH_NTCORE)

if(NOT WITH_WPIMATH AND WITH_WPILIB)
message(
FATAL_ERROR
"
FATAL: Cannot build wpilib without wpimath.
Enable wpimath by setting WITH_WPIMATH=ON
"
)
endif()
wpilib_config(OPTIONS WITH_GUI REQUIRES WITH_NTCORE WITH_WPIMATH)

if(NOT WITH_WPIMATH AND WITH_GUI)
message(
FATAL_ERROR
"
FATAL: Cannot build GUI modules without wpimath.
Enable wpimath by setting WITH_WPIMATH=ON
"
)
endif()
wpilib_config(OPTIONS WITH_WPILIB REQUIRES WITH_NTCORE WITH_WPIMATH)

if(NOT WITH_WPIUNITS AND WITH_WPIMATH AND WITH_JAVA)
message(
FATAL_ERROR
"
FATAL: Cannot build Java wpimath without wpiunits.
Enable wpiunits by setting WITH_WPIUNITS=ON or disable the Java build by setting WITH_JAVA=OFF
"
)
endif()
wpilib_config(OPTIONS WITH_WPIMATH WITH_JAVA REQUIRES WITH_WPIUNITS)

set(include_dest include)
set(java_lib_dest java)
Expand Down
29 changes: 29 additions & 0 deletions cmake/modules/OptionValidation.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function(wpilib_config)
cmake_parse_arguments(config "" "" "OPTIONS;REQUIRES" ${ARGN})
foreach(opt ${config_OPTIONS})
if(NOT ${opt})
return()
endif()
endforeach()
foreach(required_opt ${config_REQUIRES})
if(NOT ${required_opt})
list(JOIN config_OPTIONS " and " options_list)
list(LENGTH config_OPTIONS option_len)
if(option_len GREATER 1)
set(requires require)
set(option_msg "one of the listed options")
else()
set(requires requires)
set(option_msg ${options_list})
endif()

message(
FATAL_ERROR
"
FATAL: ${options_list} ${requires} ${required_opt}.
Either enable ${required_opt} or disable ${option_msg}.
"
)
endif()
endforeach()
endfunction()

0 comments on commit d6bc2cc

Please sign in to comment.