Skip to content

Commit

Permalink
CMake: Updates
Browse files Browse the repository at this point in the history
Issue open-simh#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.
  • Loading branch information
bscottm committed Dec 30, 2023
1 parent c3a60fb commit 0defe94
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 14 deletions.
16 changes: 15 additions & 1 deletion .travis/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
;;
*)
Expand Down
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cmake/cmake-builder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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, "", @())
Expand Down
21 changes: 18 additions & 3 deletions cmake/cmake-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,8 +63,8 @@ generateArgs=
buildArgs=
buildPostArgs=""
buildClean=
buildFlavor="Unix Makefiles"
buildSubdir=build-unix
buildFlavor=
buildSubdir=
buildConfig=Release
testArgs=
notest=no
Expand Down Expand Up @@ -261,6 +262,11 @@ while true; do
generateOnly=yes
shift
;;
--cache)
generateOnly=yes
generateArgs="${generateArgs} -LA"
shift
;;
--testonly)
testOnly=yes
shift
Expand All @@ -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
Expand All @@ -306,6 +320,7 @@ if [[ x"$buildClean" != x ]]; then
echo "${scriptName}: Cleaning ${buildSubdir}"
rm -rf ${buildSubdir}
fi

if [[ ! -d ${buildSubdir} ]]; then
mkdir ${buildSubdir}
fi
Expand Down
15 changes: 15 additions & 0 deletions cmake/dep-link.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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)
Expand All @@ -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 ()
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmake/pthreads-dep.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions cmake/vcpkg-setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

0 comments on commit 0defe94

Please sign in to comment.