From fadb4e755f16bbc61879a926a689cf472bd4a76b Mon Sep 17 00:00:00 2001 From: spo Date: Fri, 25 Dec 2015 11:56:03 +0300 Subject: [PATCH] Add CMake flags DEFAULT_SOLVER, NO_SolveSpace & NO_PlaneGCS to switch solvers. --- src/Config/CMakeLists.txt | 40 +++++++++++++++++++++- src/Config/{plugins.xml => plugins.xml.in} | 6 ++-- src/SketchSolver/CMakeLists.txt | 17 ++++++--- 3 files changed, 56 insertions(+), 7 deletions(-) rename src/Config/{plugins.xml => plugins.xml.in} (91%) diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index e43622f80..75cb09703 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -45,7 +45,7 @@ SET(PROJECT_SOURCES ) SET(XML_RESOURCES - plugins.xml + ${CMAKE_CURRENT_BINARY_DIR}/plugins.xml dataModel.xml ) @@ -64,5 +64,43 @@ ADD_LIBRARY(Config SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES} TARGET_LINK_LIBRARIES(Config ${PROJECT_LIBRARIES}) +# Prepare plugins.xml + +# the solver to activate after installation +SET(DEFAULT_SOLVER "SolveSpace") + +# the list of all solvers +SET(SOLVERS "SolveSpace" "PlaneGCS") + +# apply NO_ variables +FOREACH(solver IN LISTS SOLVERS) + IF(NO_${solver}) + LIST(REMOVE_ITEM SOLVERS ${solver}) + ENDIF() +ENDFOREACH() + +# check default solver in the list of solvers +LIST(FIND SOLVERS ${DEFAULT_SOLVER} INDEX) +IF(${INDEX} GREATER -1) + MESSAGE(STATUS "Default solver: ${DEFAULT_SOLVER}") +ELSE() + MESSAGE(FATAL_ERROR "Default solver: ${DEFAULT_SOLVER} is switched off.\nUnset NO_${DEFAULT_SOLVER} variable or define another default solver DEFAULT_SOLVER= from the list: ${SOLVERS}.") +ENDIF() + +# prepare variables for configuration +SET(DEFAULT_SOLVER " ") +FOREACH(solver IN LISTS SOLVERS) + IF(DEFINED ALL_SOLVERS) + SET(ALL_SOLVERS "${ALL_SOLVERS}\n") + ENDIF() + SET(ALL_SOLVERS "${ALL_SOLVERS} ") +ENDFOREACH() + +# configuration +CONFIGURE_FILE( + "${CMAKE_CURRENT_SOURCE_DIR}/plugins.xml.in" + "${CMAKE_CURRENT_BINARY_DIR}/plugins.xml" + ) + INSTALL(TARGETS Config DESTINATION bin) INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) diff --git a/src/Config/plugins.xml b/src/Config/plugins.xml.in similarity index 91% rename from src/Config/plugins.xml rename to src/Config/plugins.xml.in index 77422df32..af91d8fb2 100644 --- a/src/Config/plugins.xml +++ b/src/Config/plugins.xml.in @@ -11,8 +11,10 @@ - - +@DEFAULT_SOLVER@ + diff --git a/src/SketchSolver/CMakeLists.txt b/src/SketchSolver/CMakeLists.txt index 25c5a8c26..91cfe6c82 100644 --- a/src/SketchSolver/CMakeLists.txt +++ b/src/SketchSolver/CMakeLists.txt @@ -77,10 +77,19 @@ INSTALL(TARGETS SketchSolver DESTINATION plugins) # Include specific solvers -FIND_FILE(SSPath "SolveSpaceSolver/CMakeLists.txt" PATHS "${CMAKE_CURRENT_SOURCE_DIR}") -STRING(COMPARE NOTEQUAL ${SSPath} "SSPath-NOTFOUND" SSPath_FOUND) -FIND_FILE(GCSPath "PlaneGCSSolver/CMakeLists.txt" PATHS "${CMAKE_CURRENT_SOURCE_DIR}") -STRING(COMPARE NOTEQUAL ${GCSPath} "GCSPath-NOTFOUND" GCSPath_FOUND) +IF(NO_SolveSpace) + SET(SSPath_FOUND FALSE) +ELSE() + FIND_FILE(SSPath "SolveSpaceSolver/CMakeLists.txt" PATHS "${CMAKE_CURRENT_SOURCE_DIR}") + STRING(COMPARE NOTEQUAL ${SSPath} "SSPath-NOTFOUND" SSPath_FOUND) +ENDIF() + +IF(NO_PlaneGCS) + SET(GCSPath_FOUND FALSE) +ELSE() + FIND_FILE(GCSPath "PlaneGCSSolver/CMakeLists.txt" PATHS "${CMAKE_CURRENT_SOURCE_DIR}") + STRING(COMPARE NOTEQUAL ${GCSPath} "GCSPath-NOTFOUND" GCSPath_FOUND) +ENDIF() IF(${SSPath_FOUND} OR ${GCSPath_FOUND}) IF(${SSPath_FOUND}) -- 2.39.2