From 0defe94b4c0fcd2d126aaff429ce90ad77c770b8 Mon Sep 17 00:00:00 2001 From: "B. Scott Michel" Date: Mon, 4 Dec 2023 11:33:00 -0800 Subject: [PATCH] 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. 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. --- .travis/deps.sh | 16 +++++++++++++++- CMakeLists.txt | 13 +++++++------ cmake/cmake-builder.ps1 | 3 +++ cmake/cmake-builder.sh | 21 ++++++++++++++++++--- cmake/dep-link.cmake | 15 +++++++++++++++ cmake/pthreads-dep.cmake | 2 +- cmake/vcpkg-setup.cmake | 8 +++++--- 7 files changed, 64 insertions(+), 14 deletions(-) diff --git a/.travis/deps.sh b/.travis/deps.sh index fb18ddf77..f9cf1251c 100755 --- a/.travis/deps.sh +++ b/.travis/deps.sh @@ -45,8 +45,22 @@ install_ucrt64() { mingw-w64-ucrt-x86_64-libpcap } +install_clang64() { + pacman -S --needed mingw-w64-clang-x86_64-ninja \ + mingw-w64-clang-x86_64-cmake \ + mingw-w64-clang-x86_64-extra-cmake-modules \ + mingw-w64-clang-x86_64-clang \ + mingw-w64-clang-x86_64-make \ + mingw-w64-clang-x86_64-pcre \ + mingw-w64-clang-x86_64-freetype \ + mingw-w64-clang-x86_64-SDL2 \ + mingw-w64-clang-x86_64-SDL2_ttf \ + mingw-w64-clang-x86_64-libpcap +} + + case "$1" in - osx|linux|mingw64|ucrt64) + osx|linux|mingw64|ucrt64|clang64) install_"$1" ;; *) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2eebcc6f1..2b74fbef6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,13 @@ if (CMAKE_VERSION VERSION_LESS "3.21" AND NOT DEFINED SIMH_INSTALLER_WARNING) set(SIMH_INSTALLER_WARNING TRUE CACHE BOOL "Installer/CPack warning issued when CMAKE_VERSION < 3.21" FORCE) endif () +## SIMH Version variables: +set(SIMH_VERSION_MAJOR 4) +set(SIMH_VERSION_MINOR 1) +set(SIMH_VERSION_PATCH 0) +set(SIMH_VERSION "${SIMH_VERSION_MAJOR}.${SIMH_VERSION_MINOR}.${SIMH_VERSION_PATCH}" + CACHE PATH "Open-Simh version string.") + # Places to look for CMake modules/includes set(SIMH_INCLUDE_PATH_LIST ${CMAKE_SOURCE_DIR}/cmake @@ -73,12 +80,6 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15) cmake_policy(SET CMP0091 NEW) endif() -## SIMH Version variables: -set(SIMH_VERSION_MAJOR 4) -set(SIMH_VERSION_MINOR 1) -set(SIMH_VERSION_PATCH 0) -set(SIMH_VERSION "${SIMH_VERSION_MAJOR}.${SIMH_VERSION_MINOR}.${SIMH_VERSION_PATCH}") - project(simh VERSION "${SIMH_VERSION}" LANGUAGES C CXX) include(vcpkg-setup) diff --git a/cmake/cmake-builder.ps1 b/cmake/cmake-builder.ps1 index de661c9fb..377282b0c 100644 --- a/cmake/cmake-builder.ps1 +++ b/cmake/cmake-builder.ps1 @@ -201,10 +201,13 @@ $singleConfig = $true $cmakeGenMap = @{ "vs2022" = [GeneratorInfo]::new("Visual Studio 17 2022", $multiConfig, $false, "", @("-A", "Win32")); "vs2022-xp" = [GeneratorInfo]::new("Visual Studio 17 2022", $multiConfig, $false, "", @("-A", "Win32", "-T", "v141_xp")); + "vs2022-x64" = [GeneratorInfo]::new("Visual Studio 17 2022", $multiConfig, $false, "", @("-A", "x64", "-T", "host=x64")); "vs2019" = [GeneratorInfo]::new("Visual Studio 16 2019", $multiConfig, $false, "", @("-A", "Win32")); "vs2019-xp" = [GeneratorInfo]::new("Visual Studio 16 2019", $multiConfig, $false, "", @("-A", "Win32", "-T", "v141_xp")); + "vs2019-x64" = [GeneratorInfo]::new("Visual Studio 17 2022", $multiConfig, $false, "", @("-A", "x64", "-T", "host=x64")); "vs2017" = [GeneratorInfo]::new("Visual Studio 15 2017", $multiConfig, $false, "", @("-A", "Win32")); "vs2017-xp" = [GeneratorInfo]::new("Visual Studio 15 2017", $multiConfig, $false, "", @("-A", "Win32", "-T", "v141_xp")); + "vs2017-x64" = [GeneratorInfo]::new("Visual Studio 17 2022", $multiConfig, $false, "", @("-A", "x64", "-T", "host=x64")); "vs2015" = [GeneratorInfo]::new("Visual Studio 14 2015", $multiConfig, $false, "", @()); "mingw-make" = [GeneratorInfo]::new("MinGW Makefiles", $singleConfig, $false, "", @()); "mingw-ninja" = [GeneratorInfo]::new("Ninja", $singleConfig, $false, "", @()) diff --git a/cmake/cmake-builder.sh b/cmake/cmake-builder.sh index a6b66767c..01e56f029 100755 --- a/cmake/cmake-builder.sh +++ b/cmake/cmake-builder.sh @@ -11,13 +11,14 @@ Compile/Build options: ---------------------- --clean (-x) Remove the build subdirectory --generate (-g) Generate the build environment, don't compile/build +--cache '--generate' and show CMake's variable cache --parallel (-p) Enable build parallelism (parallel builds) --notest Do not execute 'ctest' test cases --noinstall Do not install SIMH simulators. --testonly Do not build, execute the 'ctest' test cases --installonly Do not build, install the SIMH simulators ---flavor (-f) Specifies the build flavor. Valid flavors are: +--flavor (-f) [Required] Specifies the build flavor. Valid flavors are: unix ninja xcode @@ -62,8 +63,8 @@ generateArgs= buildArgs= buildPostArgs="" buildClean= -buildFlavor="Unix Makefiles" -buildSubdir=build-unix +buildFlavor= +buildSubdir= buildConfig=Release testArgs= notest=no @@ -261,6 +262,11 @@ while true; do generateOnly=yes shift ;; + --cache) + generateOnly=yes + generateArgs="${generateArgs} -LA" + shift + ;; --testonly) testOnly=yes shift @@ -286,6 +292,14 @@ while true; do esac done +# Sanity check: buildSubdir should be set, unless the '-f' flag wasn't present. +if [ "x${buildSubdir}" = x ]; then + echo "" + echo "${scriptName}: Build flavor is NOT SET -- see the \"--flavor\"/\"-f\" flag in the help." + echo "" + showHelp +fi + ## Determine the SIMH top-level source directory: simhTopDir=$(${dirname} $(${realpath} $0)) while [ "x${simhTopDir}" != x -a ! -f "${simhTopDir}/CMakeLists.txt" ]; do @@ -306,6 +320,7 @@ if [[ x"$buildClean" != x ]]; then echo "${scriptName}: Cleaning ${buildSubdir}" rm -rf ${buildSubdir} fi + if [[ ! -d ${buildSubdir} ]]; then mkdir ${buildSubdir} fi diff --git a/cmake/dep-link.cmake b/cmake/dep-link.cmake index 56e5bfa4b..80bd8f912 100644 --- a/cmake/dep-link.cmake +++ b/cmake/dep-link.cmake @@ -21,6 +21,10 @@ get_target_property(_aliased ${_targ} ALIASED_TARGET) get_property(orig_libs TARGET ${_targ} PROPERTY INTERFACE_LINK_LIBRARIES) foreach(each_lib IN LISTS ${_lib}) string(STRIP ${each_lib} stripped_lib) + file(TO_CMAKE_PATH "${stripped_lib}" stripped_lib) + if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.19") + file(REAL_PATH "${stripped_lib}" stripped_lib) + endif () list(APPEND fixed_libs ${stripped_lib}) message("** \"${each_lib}\" -> \"${stripped_lib}\"") endforeach () @@ -34,6 +38,10 @@ function (fix_libraries _lib) set(fixed_libs) foreach(each_lib IN LISTS ${_lib}) string(STRIP ${each_lib} stripped_lib) + file(TO_CMAKE_PATH "${stripped_lib}" stripped_lib) + if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.19") + file(REAL_PATH "${stripped_lib}" stripped_lib) + endif () list(APPEND fixed_libs ${stripped_lib}) endforeach () set(${_lib} ${fixed_libs} PARENT_SCOPE) @@ -48,6 +56,11 @@ IF (WITH_VIDEO) foreach (lname ${FREETYPE_LIBRARIES} ${FREETYPE_LIBRARY} ${HARFBUZZ_LIBRARIES} ${HARFBUZZ_LIBRARY}) get_filename_component(dirname "${lname}" DIRECTORY) if (dirname) + string(STRIP ${dirname} dirname) + file(TO_CMAKE_PATH "${dirname}" dirname) + if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.19") + file(REAL_PATH "${dirname}" dirname) + endif () list(APPEND ldirs ${dirname}) endif() endforeach () @@ -128,6 +141,8 @@ IF (WITH_VIDEO) ENDIF () IF (PNG_FOUND) + target_compile_definitions(simh_video INTERFACE HAVE_LIBPNG) + if (TARGET PNG::PNG) target_link_libraries(simh_video INTERFACE PNG::PNG) list(APPEND VIDEO_PKG_STATUS "interface PNG") diff --git a/cmake/pthreads-dep.cmake b/cmake/pthreads-dep.cmake index 69b560518..3c989ea70 100644 --- a/cmake/pthreads-dep.cmake +++ b/cmake/pthreads-dep.cmake @@ -64,7 +64,7 @@ if (WITH_ASYNC) set(THREADING_PKG_STATUS "Platform-detected threading support") endif () - if (THREADS_FOUND OR PTW_FOUND) + if (THREADS_FOUND OR PTW_FOUND OR PThreads4W_FOUND) target_compile_definitions(thread_lib INTERFACE USE_READER_THREAD SIM_ASYNCH_IO) else () target_compile_definitions(thread_lib INTERFACE DONT_USE_READER_THREAD) diff --git a/cmake/vcpkg-setup.cmake b/cmake/vcpkg-setup.cmake index a3c5c9b6a..8c4494075 100644 --- a/cmake/vcpkg-setup.cmake +++ b/cmake/vcpkg-setup.cmake @@ -79,8 +79,10 @@ message(STATUS "Executing deferred vcpkg toolchain initialization.\n" ## Initialize vcpkg after CMake detects the compiler and we've to set the platform triplet. ## VCPKG_INSTALL_OPTIONS are additional args to 'vcpkg install'. Don't need to see the ## usage instructions each time... -list(APPEND VCPKG_INSTALL_OPTIONS - "--no-print-usage" -) +if (NOT ("--no-print-usage" IN_LIST VCPKG_INSTALL_OPTIONS)) + list(APPEND VCPKG_INSTALL_OPTIONS + "--no-print-usage" + ) +endif () include(${SIMH_CMAKE_TOOLCHAIN_FILE})