Skip to content

Commit

Permalink
Vcpkg: MinGW buildfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhmm committed Sep 27, 2024
1 parent 80fb779 commit f97d52e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
56 changes: 30 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ set(_BOOST_USED_COMPONENTS
CACHE STRING "Components" FORCE)
if(OPENMIND_USE_VCPKG)
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
boost
compute
multiprecision
CACHE STRING "Components" FORCE)
Expand All @@ -197,7 +196,7 @@ if(BUILD_TESTS OR OPENMIND_BUILD_TESTS OR _IS_DEBUG OR NOT CMAKE_BUILD_TYPE)
enable_testing()
if(OPENMIND_USE_VCPKG)
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
unit_test_framework
test
CACHE STRING "Components" FORCE)
else(OPENMIND_USE_VCPKG)
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
Expand Down Expand Up @@ -236,18 +235,28 @@ elseif(OPENMIND_USE_CONAN)
endif()
endif()

find_package(Boost ${OPENMIND_PREFERRED_BOOST_VERSION}
CONFIG
HINTS C:/Boost
COMPONENTS ${BOOST_USED_COMPONENTS}
)
if(NOT Boost_FOUND)
find_package(Boost ${OPENMIND_REQUIRED_BOOST_VERSION}
CONFIG
HINTS C:/Boost
COMPONENTS ${BOOST_USED_COMPONENTS}
if (NOT Boost_FOUND)
if (OPENMIND_USE_VCPKG)
include(vcpkg)
unset(Boost_DIR CACHE)
unset(Boost_INCLUDE_DIR CACHE)
message("BOOST_USED_COMPONENTS=${BOOST_USED_COMPONENTS}")
find_package(Boost CONFIG REQUIRED COMPONENTS ${BOOST_USED_COMPONENTS})
else()
find_package(Boost ${OPENMIND_PREFERRED_BOOST_VERSION}
CONFIG
HINTS C:/Boost
COMPONENTS ${BOOST_USED_COMPONENTS}
)
endif()
if(NOT Boost_FOUND)
find_package(Boost ${OPENMIND_REQUIRED_BOOST_VERSION}
CONFIG
HINTS C:/Boost
COMPONENTS ${BOOST_USED_COMPONENTS}
)
endif()
endif ()
endif ()
add_custom_target(prerequisites)
set_target_properties(prerequisites PROPERTIES FOLDER "util")

Expand Down Expand Up @@ -289,7 +298,7 @@ find_package(OpenMP)
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
#endif()

if (Boost_FOUND OR OPENMIND_USE_CONAN)
if (Boost_FOUND OR OPENMIND_USE_CONAN OR OPENMIND_USE_VCPKG)
if(NOT TARGET boost)
add_custom_target(boost)
endif()
Expand Down Expand Up @@ -384,18 +393,13 @@ if(NOT MSVC OR Boost_VERSION VERSION_LESS 1.80.0)
set(BOOST_LINK_LIBS ${BOOST_LINK_LIBS}
Boost::thread)
endif()
if(OPENMIND_USE_VCPKG)
set(BOOST_LINK_LIBS ${BOOST_LINK_LIBS}
Boost::headers
)
set(BOOST_TEST_LINK_LIBS ${BOOST_LINK_LIBS}
Boost::test
)
else()
set(BOOST_TEST_LINK_LIBS ${BOOST_LINK_LIBS}
Boost::test_exec_monitor
Boost::unit_test_framework
)

set(BOOST_TEST_LINK_LIBS
${BOOST_LINK_LIBS}
Boost::unit_test_framework
)
if(NOT MSVC AND NOT OPENMIND_USE_VCPKG AND NOT OPENMIND_USE_CONAN)
list(APPEND BOOST_TEST_LINK_LIBS Boost::test_exec_monitor)
endif()

IF (Boost_FOUND)
Expand Down
25 changes: 13 additions & 12 deletions cmake/vcpkg.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@

function(prepend_toolchain_file)
if(EXISTS ${CMAKE_TOOLCHAIN_FILE})
list(PREPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${CMAKE_TOOLCHAIN_FILE}")
set(${CMAKE_PROJECT_TOP_LEVEL_INCLUDES} "${${CMAKE_PROJECT_TOP_LEVEL_INCLUDES}}" PARENT_SCOPE)
list(PREPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PROJECT_TOP_LEVEL_INCLUDES)
set(${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} "${${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}}" PARENT_SCOPE)
endif()
endfunction()

macro(find_vcpkg)
if(NOT EXISTS ${CMAKE_TOOLCHAIN_FILE})
if(NOT EXISTS ${VCPKG_EXECUTABLE})
Expand All @@ -19,8 +29,7 @@ macro(find_vcpkg)

if(EXISTS ${CMAKE_TOOLCHAIN_FILE})
set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG toolchain file found ${CMAKE_TOOLCHAIN_FILE}" FORCE)
list(PREPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${CMAKE_TOOLCHAIN_FILE}")
list(PREPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PROJECT_TOP_LEVEL_INCLUDES)
#prepend_toolchain_file()
else()
set(VCPKG_FOUND FALSE CACHE BOOL "VCPKG not found" FORCE)
endif()
Expand Down Expand Up @@ -59,6 +68,8 @@ endmacro()

if(NOT VCPKG_FOUND)
find_vcpkg()
else()
# prepend_toolchain_file()
endif()

option(OPENMIND_USE_VCPKG "Use vcpkg" ${VCPKG_FOUND})
Expand All @@ -76,14 +87,4 @@ if(OPENMIND_USE_VCPKG)
if(NOT VCPKG_FOUND)
message(WARNING "Vcpkg not found")
endif()
if(VCPKG_EXECUTABLE)
execute_process(
COMMAND ${VCPKG_EXECUTABLE} install
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE VCPKG_RESULT
)
if(NOT VCPKG_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to install dependencies using vcpkg")
endif()
endif()
endif()

0 comments on commit f97d52e

Please sign in to comment.