From dde7d8f65751eee916c586e2e03dd8f74bf5f95d Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 28 Nov 2019 12:29:04 +0100 Subject: [PATCH 1/2] Improve Gflags building --- CMakeLists.txt | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31a221e0f..455b0eb83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -645,7 +645,7 @@ if(NOT (GNURADIO_VERSION VERSION_LESS 3.8) AND LOG4CPP_READY_FOR_CXX17) TYPE OPTIONAL ) if(${FILESYSTEM_FOUND}) - if(CMAKE_VERSION VERSION_LESS 3.12) + if(CMAKE_VERSION VERSION_LESS 3.13) set(CMAKE_CXX_STANDARD 17) else() set(CMAKE_CXX_STANDARD 20) @@ -1096,6 +1096,9 @@ if(NOT GFLAGS_FOUND) if(CMAKE_GENERATOR STREQUAL Xcode) set(GFLAGS_BUILD_COMMAND "xcodebuild" "-configuration" "${CMAKE_BUILD_TYPE}") endif() + if(MSVC) + set(GFLAGS_BUILD_COMMAND "cmake" "--build" "${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}" "--config" "${CMAKE_BUILD_TYPE}") + endif() if(CMAKE_VERSION VERSION_LESS 3.2) ExternalProject_Add(gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} @@ -1104,7 +1107,7 @@ if(NOT GFLAGS_FOUND) GIT_TAG v${GNSSSDR_GFLAGS_LOCAL_VERSION} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/gflags/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} - CMAKE_ARGS -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DBUILD_gflags_nothreads_LIB=OFF -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DBUILD_gflags_LIB=ON -DBUILD_gflags_nothreads_LIB=OFF -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} BUILD_COMMAND ${GFLAGS_BUILD_COMMAND} UPDATE_COMMAND "" PATCH_COMMAND "" @@ -1117,7 +1120,7 @@ if(NOT GFLAGS_FOUND) GIT_TAG v${GNSSSDR_GFLAGS_LOCAL_VERSION} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/gflags/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} - CMAKE_ARGS -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DBUILD_gflags_nothreads_LIB=OFF -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DBUILD_gflags_LIB=ON -DBUILD_gflags_nothreads_LIB=OFF -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} BUILD_COMMAND ${GFLAGS_BUILD_COMMAND} BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gflags${CMAKE_STATIC_LIBRARY_SUFFIX} UPDATE_COMMAND "" @@ -1140,6 +1143,11 @@ if(NOT GFLAGS_FOUND) "${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}/lib/${CMAKE_BUILD_TYPE}/${CMAKE_FIND_LIBRARY_PREFIXES}gflags${GFLAGS_DEBUG_POSTFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}" ) endif() + if(MSVC) + set(GFlags_LIBS + "${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}/lib/${CMAKE_BUILD_TYPE}/gflags_static.lib" + ) + endif() if(NOT TARGET Gflags::gflags) file(MAKE_DIRECTORY ${GFlags_INCLUDE_DIRS}) @@ -1154,6 +1162,10 @@ if(NOT GFLAGS_FOUND) ) endif() + if(MSVC) + target_link_libraries(Gflags::gflags INTERFACE shlwapi.lib) + endif() + set(LOCAL_GFLAGS TRUE CACHE STRING "GFlags downloaded and built automatically" FORCE) set_package_properties(GFLAGS PROPERTIES PURPOSE "Gflags v${GNSSSDR_GFLAGS_LOCAL_VERSION} will be downloaded and built when doing '${CMAKE_MAKE_PROGRAM_PRETTY_NAME}'." @@ -1194,6 +1206,9 @@ if(NOT GLOG_FOUND OR ${LOCAL_GFLAGS}) if(CMAKE_GENERATOR STREQUAL Xcode) set(GLOG_MAKE_PROGRAM "xcodebuild" "-configuration" "${CMAKE_BUILD_TYPE}") endif() + if(MSVC) + set(GLOG_MAKE_PROGRAM "cmake" "--build" "${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION}" "--config" "${CMAKE_BUILD_TYPE}") + endif() if(CMAKE_BUILD_TYPE MATCHES Debug) set(GLOG_DEBUG_POSTFIX "d") endif() @@ -1355,7 +1370,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glog/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/c endif() add_dependencies(glog-${GNSSSDR_GLOG_LOCAL_VERSION} Gflags::gflags) - if(CMAKE_GENERATOR STREQUAL Xcode) + if((CMAKE_GENERATOR STREQUAL Xcode) OR MSVC) set(GLOG_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/${CMAKE_BUILD_TYPE}/${CMAKE_FIND_LIBRARY_PREFIXES}glog${GLOG_DEBUG_POSTFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} ) @@ -1374,6 +1389,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glog/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/c INTERFACE_INCLUDE_DIRECTORIES "${GLOG_INCLUDE_DIRS}" INTERFACE_LINK_LIBRARIES "${GLOG_LIBRARIES}" ) + target_link_libraries(Glog::glog INTERFACE Gflags::gflags) endif() set(LOCAL_GLOG TRUE CACHE STRING "Glog downloaded and built automatically" FORCE) From 67e70093c0f3b6c962ec6dba67d017f8a88e4a39 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 28 Nov 2019 15:20:57 +0100 Subject: [PATCH 2/2] Fix Debug building with Ninja --- CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 455b0eb83..06570975d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1099,6 +1099,9 @@ if(NOT GFLAGS_FOUND) if(MSVC) set(GFLAGS_BUILD_COMMAND "cmake" "--build" "${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}" "--config" "${CMAKE_BUILD_TYPE}") endif() + if((CMAKE_BUILD_TYPE MATCHES Debug) AND (CMAKE_VERSION VERSION_GREATER "3.0.2")) + set(GFLAGS_DEBUG_POSTFIX "_debug") + endif() if(CMAKE_VERSION VERSION_LESS 3.2) ExternalProject_Add(gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} @@ -1117,24 +1120,23 @@ if(NOT GFLAGS_FOUND) ExternalProject_Add(gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} GIT_REPOSITORY git://github.com/gflags/gflags.git - GIT_TAG v${GNSSSDR_GFLAGS_LOCAL_VERSION} + GIT_TAG master #v${GNSSSDR_GFLAGS_LOCAL_VERSION} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/gflags/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION} CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DBUILD_gflags_LIB=ON -DBUILD_gflags_nothreads_LIB=OFF -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} BUILD_COMMAND ${GFLAGS_BUILD_COMMAND} - BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gflags${CMAKE_STATIC_LIBRARY_SUFFIX} + BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gflags${GFLAGS_DEBUG_POSTFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} UPDATE_COMMAND "" PATCH_COMMAND "" INSTALL_COMMAND "" ) endif() + # Note: -DBUILD_gflags_nothreads_LIB=ON is required as a workaround to a bug in gflags 2.2.2. This is fixed in gflags master branch set(GFlags_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}/include CACHE PATH "Local Gflags headers" ) - if((CMAKE_BUILD_TYPE MATCHES Debug) AND (CMAKE_VERSION VERSION_GREATER "3.0.2")) - set(GFLAGS_DEBUG_POSTFIX "_debug") - endif() + set(GFlags_LIBS "${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}/lib/${CMAKE_FIND_LIBRARY_PREFIXES}gflags${GFLAGS_DEBUG_POSTFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}" ) @@ -1145,7 +1147,7 @@ if(NOT GFLAGS_FOUND) endif() if(MSVC) set(GFlags_LIBS - "${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}/lib/${CMAKE_BUILD_TYPE}/gflags_static.lib" + "${CMAKE_CURRENT_BINARY_DIR}/gflags-${GNSSSDR_GFLAGS_LOCAL_VERSION}/lib/${CMAKE_BUILD_TYPE}/gflags_static${GFLAGS_DEBUG_POSTFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}" ) endif()