diff --git a/CMakeLists.txt b/CMakeLists.txt index c71815f7e..4b23b91e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,8 +147,8 @@ if(NOT WIN32) add_definitions(-DOPENMIND_USE_TBB) endif() endif() -set(OPENMIND_PREFERRED_BOOST_VERSION 1.85.0 CACHE STRING "Boost library version to use") -set(OPENMIND_REQUIRED_BOOST_VERSION 1.81.0 CACHE STRING "Boost library minimum compatible version to use") +set(OPENMIND_PREFERRED_BOOST_VERSION 1.83.0 CACHE STRING "Boost library version to use") +set(OPENMIND_REQUIRED_BOOST_VERSION 1.83.0 CACHE STRING "Boost library minimum compatible version to use") set_property(CACHE OPENMIND_PRIME_TABLE PROPERTY STRINGS ${OPENMIND_PRIME_TABLE_OPTIONS}) if(MSVC AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0") @@ -214,18 +214,32 @@ 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} - ) +find_package(Boost ${OPENMIND_REQUIRED_BOOST_VERSION} + COMPONENTS ${BOOST_USED_COMPONENTS} + REQUIRED +) + +if(Boost_FOUND) + set(Boost_USE_DEBUG_LIBS ON) + set(Boost_USE_RELEASE_LIBS ON) + message(STATUS "Boost found: ${Boost_VERSION}") + message(STATUS "Boost include dirs: ${Boost_INCLUDE_DIRS}") + message(STATUS "Boost library dirs: ${Boost_LIBRARY_DIRS}") + + if(Boost_VERSION VERSION_LESS ${OPENMIND_PREFERRED_BOOST_VERSION}) + message(WARNING "Found Boost version ${Boost_VERSION} is older than preferred version ${OPENMIND_PREFERRED_BOOST_VERSION}") + endif() +else() + message(FATAL_ERROR "Boost not found. Please install Boost ${OPENMIND_REQUIRED_BOOST_VERSION} or later, or check your configuration.") +endif() + +if(NOT TARGET Boost::boost) + add_library(Boost::boost INTERFACE IMPORTED) + set_target_properties(Boost::boost PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}" + ) endif() + add_custom_target(prerequisites) set_target_properties(prerequisites PROPERTIES FOLDER "util") @@ -350,8 +364,8 @@ if(TARGET boost) endif() set(BOOST_LINK_LIBS - Boost::chrono - Boost::filesystem + Boost::chrono + Boost::filesystem Boost::serialization Boost::system ) @@ -361,17 +375,40 @@ if(NOT MSVC OR Boost_VERSION VERSION_LESS 1.80.0) endif() set(BOOST_TEST_LINK_LIBS ${BOOST_LINK_LIBS} - Boost::test_exec_monitor - Boost::unit_test_framework + Boost::unit_test_framework ) +# Search for libboost_test_exec_monitor.a in various possible locations +set(BOOST_TEST_EXEC_MONITOR_PATHS + "${Boost_LIBRARY_DIR_RELEASE}/manual-link/libboost_test_exec_monitor.a" + "${Boost_LIBRARY_DIR_DEBUG}/manual-link/libboost_test_exec_monitor.a" + "${CMAKE_BINARY_DIR}/vcpkg_installed/x64-linux/lib/manual-link/libboost_test_exec_monitor.a" + "${CMAKE_BINARY_DIR}/vcpkg_installed/x64-linux/debug/lib/manual-link/libboost_test_exec_monitor.a" +) + +set(BOOST_TEST_EXEC_MONITOR_FOUND FALSE) +foreach(TEST_EXEC_MONITOR_PATH ${BOOST_TEST_EXEC_MONITOR_PATHS}) + if(EXISTS "${TEST_EXEC_MONITOR_PATH}") + set(BOOST_TEST_LINK_LIBS ${BOOST_TEST_LINK_LIBS} "${TEST_EXEC_MONITOR_PATH}") + set(BOOST_TEST_EXEC_MONITOR_FOUND TRUE) + break() + endif() +endforeach() + +if(NOT BOOST_TEST_EXEC_MONITOR_FOUND) + message(WARNING "libboost_test_exec_monitor.a not found in any of the searched directories") +endif() + IF (Boost_FOUND) - message("Boost_FOUND") - message("Boost_DIR: ${Boost_DIR}") - message("Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}") - message("EXTERNAL_FETCHED_BOOST: ${EXTERNAL_FETCHED_BOOST}") - message("Boost_LIBRARY_DIR: ${Boost_LIBRARY_DIR}") - message("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}") + message(STATUS "Boost found:") + message(STATUS " Boost_DIR: ${Boost_DIR}") + message(STATUS " Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}") + message(STATUS " Boost_LIBRARY_DIR: ${Boost_LIBRARY_DIR}") + message(STATUS " Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}") + message(STATUS " Boost_VERSION: ${Boost_VERSION}") + message(STATUS " Boost_LIBRARIES: ${Boost_LIBRARIES}") +ELSE() + message(FATAL_ERROR "Boost not found. Please install Boost or check your configuration.") ENDIF() diff --git a/cmake/vcpkg.cmake b/cmake/vcpkg.cmake index 39ef5a4fc..5a3144b03 100644 --- a/cmake/vcpkg.cmake +++ b/cmake/vcpkg.cmake @@ -1,57 +1,70 @@ - macro(find_vcpkg) - if(NOT EXISTS ${CMAKE_TOOLCHAIN_FILE}) - if(NOT EXISTS ${VCPKG_EXECUTABLE}) - find_program(VCPKG_EXECUTABLE vcpkg PATHS - "$ENV{ProgramFiles}/Microsoft Visual Studio/*/*/VC/vcpkg/" - "$ENV{USERPROFILE}$ENV{HOME}/vcpkg/" - ) - 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 () - endif() - if(EXISTS ${CMAKE_TOOLCHAIN_FILE}) - set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG toolchain file found ${CMAKE_TOOLCHAIN_FILE}") - endif() + if(NOT DEFINED VCPKG_ROOT) + set(VCPKG_ROOT "$ENV{VCPKG_ROOT}" CACHE PATH "Path to vcpkg installation") + endif() + + if(EXISTS "${VCPKG_ROOT}/vcpkg") + set(VCPKG_EXECUTABLE "${VCPKG_ROOT}/vcpkg" CACHE FILEPATH "Path to vcpkg executable") + else() + find_program(VCPKG_EXECUTABLE vcpkg PATHS + "$ENV{ProgramFiles}/Microsoft Visual Studio/*/*/VC/vcpkg/" + "$ENV{USERPROFILE}/vcpkg/" + "$ENV{HOME}/vcpkg/" + ) + endif() + + if(EXISTS ${VCPKG_EXECUTABLE}) + get_filename_component(VCPKG_ROOT ${VCPKG_EXECUTABLE} DIRECTORY) + set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") + set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG found") + else() + set(VCPKG_FOUND FALSE CACHE BOOL "VCPKG not found") endif() endmacro() macro(fetch_vcpkg) - include(gitect) - if(GIT_EXECUTABLE) - execute_process( - COMMAND ${GIT_EXECUTABLE} clone https://github.com/microsoft/vcpkg - WORKING_DIRECTORY $ENV{USERPROFILE}$ENV{HOME} - ) - execute_process( - COMMAND ${CMAKE_COMMAND} --build . - WORKING_DIRECTORY ${vcpkg_SOURCE_DIR} - ) - endif() + include(gitect) + if(GIT_EXECUTABLE) + set(VCPKG_ROOT "$ENV{HOME}/vcpkg" CACHE PATH "Path to vcpkg installation") + execute_process( + COMMAND ${GIT_EXECUTABLE} clone https://github.com/microsoft/vcpkg ${VCPKG_ROOT} + RESULT_VARIABLE GIT_RESULT + ) + if(NOT GIT_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to clone vcpkg repository") + endif() + execute_process( + COMMAND ${CMAKE_COMMAND} -E chdir ${VCPKG_ROOT} ${VCPKG_ROOT}/bootstrap-vcpkg.sh + RESULT_VARIABLE BOOTSTRAP_RESULT + ) + if(NOT BOOTSTRAP_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to bootstrap vcpkg") + endif() + set(VCPKG_EXECUTABLE "${VCPKG_ROOT}/vcpkg" CACHE FILEPATH "Path to vcpkg executable" FORCE) + set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file" FORCE) + set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG found" FORCE) + endif() endmacro() -if(NOT ${VCPKG_FOUND}) - find_vcpkg() -endif() +find_vcpkg() -option(OPENMIND_USE_VCPKG "Use vcpkg" ${VCPKG_FOUND}) +option(OPENMIND_USE_VCPKG "Use vcpkg" ON) 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) + fetch_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} + RESULT_VARIABLE VCPKG_RESULT + ) + if(NOT VCPKG_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to install dependencies using vcpkg") + endif() + endif() +endif()