simh-testsetgenerator/cmake/pthreads-dep.cmake
B. Scott Michel d9d0e8bd74 CMake: Updates
Issue #294: "apple silicon build problem(s?)": If the "--flavor/-f" flag
is not specified on the command line, then complain loudly, print help
and exit. The script used to default to "Unix Makefiles".

Updates:

- Add missing "-DHAVE_LIBPNG" compiler command line define when the PNG
  library is detected/present for screen capture support.

- Add "clang64" to the list of MinGW64 platforms for which the
  .travis/deps.sh script can install build dependencies.

- Add PThread4W_FOUND to the condition that sets async I/O for Win32
  when using vcpkg for build dependencies.

- Add vs2022-x64, vs2019-x64 and vs2017-x64 build environments to
  build 64-bit Windows executables.

- Use simulator AIO only where needed by the simulator (i.e., the
  simulator calls/uses AIO_CHECK_EVENT in sim_instr())

  - Add "USES_AIO" flag to add_simulator() to mark a simulator that
    acutally uses asynchronous I/O.

  - Build "_aio" SIMH core library variants that have AIO turned on,
    link with the "_aio" variant when a simulator sets USES_AIO.

  - Emit a warning message when WITH_ASYNC is False (CMake configuration
    option) to notify the user/developer that some functionality will be
    crippled.

  Affected simulator builds: 3b2 family, PDP-6, PDP-11, VAX family,
  IMLAC and TT2500. The makefile and cmake/generate.py also updated
  to remain in sync with CMake.

  N.B.: Simulators still link with the underlying platform's threading
  library. SEL32 requires pthreads or equivalent threading library,
  independent of AIO.

- cmake/cmake-builder.sh

  - New "--no-aio" flag: Build simulators without async I/O.

  - New "--no-aio-intrinsics" flag: Don't build async I/O using compiler
    compare-exchange, atomic load intrinsics.

- cmake/cmake-builder.ps1

  - New "-noaio" flag: Build simulators without async I/O.

  - New "-noaiointrinsics" flag: Don't build async I/O using compiler
    compare-exchange, atomic load intrinsics.

CMake 3.28.1 INTERFACE_LINK_LIBRARIES behavior change: The file name
must now be an absolute path. Relative paths no longer accepted.
Internally, SIMH enforces this if CMAKE_VERSION >= 3.19, when REAL_PATH
was first implemented.
2024-02-01 12:51:13 -05:00

76 lines
3.2 KiB
CMake

#~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
# Manage the pthreads dependency
#
# (a) Try to locate the system's installed pthreads library, which is very
# platform dependent (MSVC -> Pthreads4w, MinGW -> pthreads, *nix -> pthreads.)
# (b) MSVC: Build Pthreads4w as a dependent
#~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
add_library(thread_lib INTERFACE)
set(AIO_FLAGS)
if (WITH_ASYNC)
include(ExternalProject)
if (MSVC OR (WIN32 AND CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
# Pthreads4w: pthreads for windows.
if (USING_VCPKG)
find_package(PThreads4W REQUIRED)
target_link_libraries(thread_lib INTERFACE PThreads4W::PThreads4W)
set(THREADING_PKG_STATUS "vcpkg PThreads4W")
else ()
find_package(PTW)
if (PTW_FOUND)
target_compile_definitions(thread_lib INTERFACE PTW32_STATIC_LIB)
target_include_directories(thread_lib INTERFACE ${PTW_INCLUDE_DIRS})
target_link_libraries(thread_lib INTERFACE ${PTW_C_LIBRARY})
set(THREADING_PKG_STATUS "detected PTW/PThreads4W")
else ()
## Would really like to build from the original jwinarske repo, but it
## ends up installing in ${CMAKE_INSTALL_PREFIX}/<x86|x86_64>> prefix.
## Which completely breaks how CMake Find*.cmake works.
##
## set(PTHREADS4W_URL "https://github.com/jwinarske/pthreads4w")
## set(PTHREADS4W_URL "https://github.com/bscottm/pthreads4w")
set(PTHREADS4W_URL "https://github.com/bscottm/pthreads4w/archive/refs/tags/version-3.1.0-release.zip")
ExternalProject_Add(pthreads4w-ext
URL ${PTHREADS4W_URL}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
BuildDepMatrix(pthreads4w-ext pthreads4w
# CMAKE_ARGS
# -DDIST_ROOT=${SIMH_DEP_TOPDIR}
)
list(APPEND SIMH_BUILD_DEPS pthreads4w)
list(APPEND SIMH_DEP_TARGETS pthreads4w-ext)
message(STATUS "Building Pthreads4w from ${PTHREADS4W_URL}")
set(THREADING_PKG_STATUS "pthreads4w source build")
endif ()
endif ()
else ()
# Let CMake determine which threading library ought be used.
set(THREADS_PREFER_PTHREAD_FLAG On)
find_package(Threads)
if (THREADS_FOUND)
target_link_libraries(thread_lib INTERFACE Threads::Threads)
endif (THREADS_FOUND)
set(THREADING_PKG_STATUS "Platform-detected threading support")
endif ()
if (THREADS_FOUND OR PTW_FOUND OR PThreads4W_FOUND)
set(AIO_FLAGS USE_READER_THREAD SIM_ASYNCH_IO)
else ()
set(AIO_FLAGS DONT_USE_READER_THREAD)
endif ()
else()
target_compile_definitions(thread_lib INTERFACE DONT_USE_READER_THREAD)
set(THREADING_PKG_STATUS "asynchronous I/O disabled.")
endif()