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 26, 2024
1 parent f93e23a commit 2dffeac
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 56 deletions.
76 changes: 54 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,25 @@ set(_BOOST_USED_COMPONENTS
system
thread
CACHE STRING "Components" FORCE)

if(OPENMIND_USE_VCPKG)
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
boost
compute
multiprecision
CACHE STRING "Components" FORCE)
endif(OPENMIND_USE_VCPKG)
if(BUILD_TESTS OR OPENMIND_BUILD_TESTS OR _IS_DEBUG OR NOT CMAKE_BUILD_TYPE)
enable_testing()
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
unit_test_framework
test_exec_monitor
CACHE STRING "Components" FORCE)
if(OPENMIND_USE_VCPKG)
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
unit_test_framework
CACHE STRING "Components" FORCE)
else(OPENMIND_USE_VCPKG)
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
unit_test_framework
test_exec_monitor
CACHE STRING "Components" FORCE)
endif(OPENMIND_USE_VCPKG)
endif()
list(REMOVE_DUPLICATES _BOOST_USED_COMPONENTS)
set(BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS} CACHE STRING "Components" FORCE)
Expand Down Expand Up @@ -224,18 +236,30 @@ 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)
find_package(Boost CONFIG REQUIRED
#COMPONENTS ${BOOST_USED_COMPONENTS}
)
endif()
endif()
if (NOT Boost_FOUND)
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}
)
endif()
endif ()
endif ()
add_custom_target(prerequisites)
set_target_properties(prerequisites PROPERTIES FOLDER "util")

Expand Down Expand Up @@ -274,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 @@ -369,11 +393,19 @@ if(NOT MSVC OR Boost_VERSION VERSION_LESS 1.80.0)
set(BOOST_LINK_LIBS ${BOOST_LINK_LIBS}
Boost::thread)
endif()
set(BOOST_TEST_LINK_LIBS
${BOOST_LINK_LIBS}
Boost::test_exec_monitor
Boost::unit_test_framework
)
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
)
endif()

IF (Boost_FOUND)
message("Boost_FOUND")
Expand Down
61 changes: 36 additions & 25 deletions cmake/vcpkg.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +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 @@ -7,16 +16,20 @@ macro(find_vcpkg)
"$ENV{USERPROFILE}$ENV{HOME}/vcpkg/"
)
endif()
if (EXISTS ${VCPKG_EXECUTABLE})
get_filename_component(dir ${VCPKG_EXECUTABLE} DIRECTORY)
set(CMAKE_TOOLCHAIN_FILE "${dir}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
endif ()
if(EXISTS ${CMAKE_TOOLCHAIN_FILE})
set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG toolchain file found ${CMAKE_TOOLCHAIN_FILE}")
list(APPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${CMAKE_TOOLCHAIN_FILE}")
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PROJECT_TOP_LEVEL_INCLUDES)
if (EXISTS ${VCPKG_EXECUTABLE})
message("VCPKG_EXECUTABLE=${VCPKG_EXECUTABLE}")
get_filename_component(VCPKG_ROOT ${VCPKG_EXECUTABLE} DIRECTORY)
set(VCPKG_ROOT "${VCPKG_ROOT}" CACHE PATH "Path to vcpkg installation" FORCE)
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file" FORCE)
endif()
endif()

if(EXISTS ${CMAKE_TOOLCHAIN_FILE})
set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG toolchain file found ${CMAKE_TOOLCHAIN_FILE}" FORCE)
#prepend_toolchain_file()
else()
set(VCPKG_FOUND FALSE CACHE BOOL "VCPKG not found" FORCE)
endif()
endmacro()

macro(fetch_vcpkg)
Expand All @@ -42,25 +55,23 @@ endmacro()

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

option(OPENMIND_USE_VCPKG "Use vcpkg" ${VCPKG_FOUND})

if(OPENMIND_USE_VCPKG)
if(NOT ${VCPKG_FOUND})
find_vcpkg()
endif()
if(NOT ${VCPKG_FOUND})
fetch_vcpkg()
find_vcpkg()
endif()
if(NOT ${VCPKG_FOUND})
message(FATAL_ERROR "VCPKG is required but not found")
endif()
if(VCPKG_EXECUTABLE)
execute_process(
COMMAND ${VCPKG_EXECUTABLE} install
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
endif (OPENMIND_USE_VCPKG)
if(NOT VCPKG_FOUND)
find_vcpkg()
if(NOT VCPKG_FOUND)
fetch_vcpkg()
if(NOT VCPKG_FOUND)
find_vcpkg()
endif()
endif()
endif()
if(NOT VCPKG_FOUND)
message(WARNING "Vcpkg not found")
endif()
endif()
32 changes: 23 additions & 9 deletions omnn/rt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@

set(DEPENDENCIES boost)
if(Boost_FOUND)
if(NOT MSVC OR OPENMIND_USE_CONAN)
set(DEPENDENCIES ${DEPENDENCIES} Boost::filesystem)
if(OPENMIND_BUILD_TESTS)
set(DEPENDENCIES ${DEPENDENCIES}
Boost::test_exec_monitor
Boost::unit_test_framework
if (OPENMIND_USE_VCPKG)
set(DEPENDENCIES
Boost::filesystem
Boost::multiprecision
Boost::system
)
if(OPENMIND_BUILD_TESTS)
list(APPEND DEPENDENCIES Boost::unit_test_framework)
endif()
else ()
set(DEPENDENCIES boost)
if(Boost_FOUND)
if(NOT MSVC OR OPENMIND_USE_CONAN)
list(APPEND DEPENDENCIES Boost::filesystem)
if(OPENMIND_BUILD_TESTS)
list(APPEND DEPENDENCIES
Boost::test_exec_monitor
Boost::unit_test_framework
)
endif()
endif()
endif()
endif()

if(OPENMIND_USE_OPENCL)
set(DEPENDENCIES ${DEPENDENCIES} OpenCL)
list(APPEND DEPENDENCIES OpenCL)
if (OPENMIND_USE_VCPKG)
list(APPEND DEPENDENCIES Boost::compute)
endif()
endif()

lib(${DEPENDENCIES})

0 comments on commit 2dffeac

Please sign in to comment.