From 31863e4ddae528b30ce3b259587c9b4eb7bbb3a3 Mon Sep 17 00:00:00 2001 From: Amit Prakash Ambasta Date: Mon, 3 Jul 2017 15:42:24 +0530 Subject: [PATCH] Added flags to force rebuild of all dependencies, created hierarchy b/w python and C++ projects when the C++ project is being built --- CMakeLists.txt | 8 +++++++- cmake/cpp.cmake | 14 +++++++++++--- cmake/python.cmake | 8 ++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e6cb41284..d2eb8578a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ ENDIF() SET(BUILD_CXX OFF CACHE BOOL "Build C++ library") SET(BUILD_PY OFF CACHE BOOL "Build Python library") +SET(BUILD_DEPS OFF CACHE BOOL "Force re-build of all dependencies") SET(DOWNLOAD_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/downloads" CACHE PATH "Location where external projects will be downloaded.") MARK_AS_ADVANCED(DOWNLOAD_LOCATION) @@ -52,9 +53,14 @@ ENDIF() FIND_PACKAGE(Threads REQUIRED) FIND_PACKAGE(Protobuf ${Protobuf_VERSION}) +IF(BUILD_DEPS) + SET(Protobuf_FOUND False) +ENDIF() IF(NOT Protobuf_FOUND) - MESSAGE(STATUS "Did not find system protobuf. Building as an external project") + MESSAGE(STATUS "Did not find system protobuf or forced build. Building as an external project") INCLUDE(cmake/external/protobuf.cmake) +ELSE() + MESSAGE("Protobuf_FOUND: ${Protobuf_FOUND}") ENDIF() INCLUDE_DIRECTORIES(${Protobuf_INCLUDE_DIRS}) SET(PROTOBUF_IMPORT_DIRS ${PROJECT_SOURCE_DIR}) diff --git a/cmake/cpp.cmake b/cmake/cpp.cmake index f778d069fb..e4a1945f49 100644 --- a/cmake/cpp.cmake +++ b/cmake/cpp.cmake @@ -1,12 +1,18 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}) FIND_PACKAGE(gflags ${gflags_VERSION}) +IF(BUILD_DEPS) + SET(gflags_FOUND False) +ENDIF() IF(NOT gflags_FOUND) - MESSAGE(STATUS "Did not find system gflags. Building as an external project") - INCLUDE(external/gflags.cmake) + MESSAGE(STATUS "Did not find system gflags or forced build. Building as an external project") + INCLUDE(cmake/external/gflags.cmake) ENDIF() INCLUDE_DIRECTORIES(${gflags_INCLUDE_DIRS}) FIND_PACKAGE(glog ${glog_VERSION}) +IF(BUILD_DEPS) + SET(glog_FOUND False) +ENDIF() IF(NOT glog_FOUND) MESSAGE(STATUS "Did not find system glog. Building as an external project.") INCLUDE(cmake/external/glog.cmake) @@ -14,6 +20,9 @@ ENDIF() INCLUDE_DIRECTORIES(${glog_INCLUDE_DIRS}) FIND_PACKAGE(Cbc ${Cbc_VERSION}) +IF(BUILD_DEPS) + SET(Cbc_FOUND False) +ENDIF() IF(NOT Cbc_FOUND) IF(NOT MSVC) MESSAGE(STATUS "Did not find system coin-cbc. Building as an external project.") @@ -33,7 +42,6 @@ ENDIF() FILE(GLOB_RECURSE proto_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "ortools/*.proto") PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${proto_files}) ADD_CUSTOM_TARGET(${PROJECT_NAME}ProtoSources ALL DEPENDS ${PROTO_SRCS}) - ADD_LIBRARY(${PROJECT_NAME}Proto OBJECT ${PROTO_SRCS} ${PROTO_HDRS}) IF(NOT Cbc_FOUND) diff --git a/cmake/python.cmake b/cmake/python.cmake index 9ef2908ca2..6b28ea703f 100644 --- a/cmake/python.cmake +++ b/cmake/python.cmake @@ -5,6 +5,10 @@ LIST(REMOVE_ITEM py_proto_files "ortools/constraint_solver/demon_profiler.proto" PROTOBUF_GENERATE_PYTHON(PROTO_PY_SRCS ${py_proto_files}) ADD_CUSTOM_TARGET(Py${PROJECT_NAME}proto ALL DEPENDS ${PROTO_PY_SRCS}) +IF(BUILD_CXX) + ADD_DEPENDENCIES(Py${PROJECT_NAME}proto ${PROJECT_NAME}) +ENDIF() + IF(${PYTHON_VERSION_STRING} VERSION_GREATER 3) SET(CMAKE_SWIG_FLAGS "-py3;-DPY3") ENDIF() @@ -66,4 +70,8 @@ ADD_CUSTOM_COMMAND( COMMAND ${CMAKE_COMMAND} -E touch ${PY_OUTPUT} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ortools/__init__.py) ADD_CUSTOM_TARGET(py${PROJECT_NAME} ALL DEPENDS ${PY_OUTPUT}) + +IF(BUILD_CXX) + ADD_DEPENDENCIES(py${PROJECT_NAME} ${PROJECT_NAME}) +ENDIF() INSTALL(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)")