Skip to content

Commit 6917867

Browse files
committed
build: port many recent build improvements from OpenImageIO
Periodic re-synchronization of build system components between the two projects. dependency_utils.cmake: * Make dependency report more clear to read. * Infastructure related to auto-build of missing dependencies, which we don't yet do in the OSL side, but will eventually institute that like we did on the OIIO side. compiler.cmake: * Warnings about clang versions so old that we no longer test them. * Imroved ccache finding logic. * Fix TIME_COMMANDS. * Turn on CMAKE_EXPORT_COMPIE_COMMANDS to make a compile_commands.json. * Various other insubstantial changes just to keep the two projects in sync to make future diffs easier to understand. gh-win-installdeps.bash: * Accommodate newer python releases on Windows. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent d9dfaa2 commit 6917867

File tree

3 files changed

+319
-63
lines changed

3 files changed

+319
-63
lines changed

src/build-scripts/gh-win-installdeps.bash

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DEP_DIR/bin:$VCPKG_INSTALLATION_ROOT/i
2121
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DEP_DIR/lib:$VCPKG_INSTALLATION_ROOT/installed/x64-windows-release/lib"
2222

2323

24-
if [[ "$PYTHON_VERSION" == "3.7" ]] ; then
25-
export CMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH;/c/hostedtoolcache/windows/Python/3.7.9/x64"
26-
export Python_EXECUTABLE="/c/hostedtoolcache/windows/Python/3.7.9/x64/python.exe"
27-
export PYTHONPATH=$OpenImageIO_ROOT/lib/python${PYTHON_VERSION}/site-packages
28-
elif [[ "$PYTHON_VERSION" == "3.9" ]] ; then
24+
if [[ "$PYTHON_VERSION" == "3.9" ]] ; then
2925
export CMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH;/c/hostedtoolcache/windows/Python/3.9.13/x64"
3026
export Python_EXECUTABLE="/c/hostedtoolcache/windows/Python/3.9.13/x64/python3.exe"
3127
export PYTHONPATH=$OpenImageIO_ROOT/lib/python${PYTHON_VERSION}/site-packages
28+
elif [[ "$PYTHON_VERSION" == "3.12" ]] ; then
29+
export CMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH;/c/hostedtoolcache/windows/Python/3.12.10/x64"
30+
export Python_EXECUTABLE="/c/hostedtoolcache/windows/Python/3.12.10/x64/python3.exe"
31+
export PYTHONPATH=$OpenImageIO_ROOT/lib/python${PYTHON_VERSION}/site-packages
32+
elif [[ "$PYTHON_VERSION" == "3.14" ]] ; then
33+
export CMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH;/c/hostedtoolcache/windows/Python/3.14.3/x64"
34+
export Python_EXECUTABLE="/c/hostedtoolcache/windows/Python/3.14.3/x64/python3.exe"
35+
export PYTHONPATH=$OpenImageIO_ROOT/lib/python${PYTHON_VERSION}/site-packages
3236
fi
3337
pip install numpy
3438

src/cmake/compiler.cmake

Lines changed: 87 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ message (VERBOSE "CMAKE_SYSTEM_VERSION = ${CMAKE_SYSTEM_VERSION}")
2020
message (VERBOSE "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}")
2121
message (STATUS "CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}")
2222
message (STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
23+
message (VERBOSE "CMAKE_CXX_COMPILE_FEATURES = ${CMAKE_CXX_COMPILE_FEATURES}")
2324

2425

2526
###########################################################################
@@ -72,6 +73,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER MATCHES "[Cc]lan
7273
message (VERBOSE "The compiler is Clang: ${CMAKE_CXX_COMPILER_ID} version ${APPLECLANG_VERSION_STRING}")
7374
if (APPLECLANG_VERSION_STRING VERSION_LESS 5.0)
7475
message (ERROR "Apple clang minimum version is 5.0")
76+
elseif (APPLECLANG_VERSION_STRING VERSION_LESS 10.0)
77+
message (WARNING "Apple clang minimum version is 10.0. Older versions might work, but we don't test or support them.")
7578
endif ()
7679
elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
7780
set (CMAKE_COMPILER_IS_INTELCLANG 1)
@@ -85,12 +88,17 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER MATCHES "[Cc]lan
8588
message (VERBOSE "The compiler is Clang: ${CMAKE_CXX_COMPILER_ID} version ${CLANG_VERSION_STRING}")
8689
if (CLANG_VERSION_STRING VERSION_LESS 5.0)
8790
message (ERROR "clang minimum version is 5.0")
91+
elseif (CLANG_VERSION_STRING VERSION_LESS 10.0)
92+
message (WARNING "clang minimum version is 10.0. Older versions might work, but we don't test or support them.")
8893
endif ()
8994
endif ()
9095
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
9196
set (CMAKE_COMPILER_IS_INTEL 1)
9297
message (VERBOSE "Using Intel as the compiler")
9398
endif ()
99+
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
100+
set (COMPILER_IS_GCC_OR_ANY_CLANG TRUE)
101+
endif ()
94102

95103

96104
###########################################################################
@@ -107,12 +115,12 @@ else ()
107115
endif()
108116
option (EXTRA_WARNINGS "Enable lots of extra pedantic warnings" OFF)
109117
if (NOT MSVC)
110-
add_compile_options ("-Wall")
118+
add_compile_options (-Wall)
111119
if (EXTRA_WARNINGS)
112-
add_compile_options ("-Wextra")
120+
add_compile_options (-Wextra)
113121
endif ()
114122
if (STOP_ON_WARNING)
115-
add_compile_options ("-Werror")
123+
add_compile_options (-Werror)
116124
endif ()
117125
endif ()
118126

@@ -232,18 +240,31 @@ endif ()
232240
# logic here makes it work even if the user is unaware of ccache. If it's
233241
# not found on the system, it will simply be silently not used.
234242
option (USE_CCACHE "Use ccache if found" ON)
235-
find_program (CCACHE_EXE ccache)
236-
if (CCACHE_EXE AND USE_CCACHE)
237-
if (CMAKE_COMPILER_IS_CLANG AND USE_QT AND (NOT DEFINED ENV{CCACHE_CPP2}))
238-
message (STATUS "Ignoring ccache because clang + Qt + env CCACHE_CPP2 is not set")
239-
else ()
240-
if (NOT ${CXX_COMPILER_LAUNCHER} MATCHES "ccache")
241-
set (CXX_COMPILER_LAUNCHER ${CCACHE_EXR} ${CXX_COMPILER_LAUNCHER})
242-
endif ()
243-
if (NOT ${C_COMPILER_LAUNCHER} MATCHES "ccache")
244-
set (C_COMPILER_LAUNCHER ${CCACHE_EXR} ${C_COMPILER_LAUNCHER})
243+
if (USE_CCACHE)
244+
find_program (CCACHE_EXE ccache
245+
PATHS "${PROJECT_SOURCE_DIR}/ext/dist/"
246+
"${PROJECT_SOURCE_DIR}/ext/dist/bin")
247+
if (CCACHE_EXE)
248+
if (CMAKE_COMPILER_IS_CLANG AND USE_QT AND (NOT DEFINED ENV{CCACHE_CPP2}))
249+
message (STATUS "Ignoring ccache because clang + Qt + env CCACHE_CPP2 is not set")
250+
else ()
251+
message (STATUS "CMAKE_CXX_COMPILER_LAUNCHER: ${CMAKE_CXX_COMPILER_LAUNCHER}")
252+
253+
if (NOT CMAKE_CXX_COMPILER_LAUNCHER MATCHES "ccache")
254+
set (CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXE})
255+
message (STATUS "first if CMAKE_CXX_COMPILER_LAUNCHER: ${CMAKE_CXX_COMPILER_LAUNCHER}")
256+
else ()
257+
message (STATUS "first else CMAKE_CXX_COMPILER_LAUNCHER: '${CMAKE_CXX_COMPILER_LAUNCHER}'")
258+
endif ()
259+
if (NOT CMAKE_C_COMPILER_LAUNCHER MATCHES "ccache")
260+
set (CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXE})
261+
endif ()
262+
message (STATUS "ccache enabled: ${CCACHE_EXE}")
263+
message (STATUS "CCACHE_DIR env: $ENV{CCACHE_DIR}")
264+
message (STATUS "CMAKE_CXX_COMPILER_LAUNCHER: ${CMAKE_CXX_COMPILER_LAUNCHER}")
245265
endif ()
246-
message (STATUS "ccache enabled: ${CCACHE_EXE}")
266+
else ()
267+
message (STATUS "ccache not found")
247268
endif ()
248269
endif ()
249270

@@ -256,8 +277,8 @@ endif ()
256277
# set `-j 1` or CMAKE_BUILD_PARALLEL_LEVEL to 1.
257278
option (TIME_COMMANDS "Time each compile and link command" OFF)
258279
if (TIME_COMMANDS)
259-
set (CXX_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E time ${CXX_COMPILER_LAUNCHER})
260-
set (C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E time ${C_COMPILER_LAUNCHER})
280+
set (CMAKE_CXX_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E time ${CMAKE_CXX_COMPILER_LAUNCHER})
281+
set (CMAKE_C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E time ${CMAKE_C_COMPILER_LAUNCHER})
261282
endif ()
262283

263284

@@ -296,20 +317,38 @@ endif ()
296317
# the proper compiler directives added to generate code for those ISA
297318
# capabilities.
298319
#
299-
set (USE_SIMD "" CACHE STRING "Use SIMD directives (0, sse2, sse3, ssse3, sse4.1, sse4.2, avx, avx2, avx512f, f16c, aes)")
320+
set_cache (USE_SIMD "" "Use SIMD directives (0, sse2, sse3, ssse3, sse4.1, sse4.2, avx, avx2, avx512f, f16c, aes)")
300321
set (SIMD_COMPILE_FLAGS "")
322+
message (STATUS "Compiling with SIMD level ${USE_SIMD}")
301323
if (NOT USE_SIMD STREQUAL "")
302-
message (STATUS "Compiling with SIMD level ${USE_SIMD}")
303324
if (USE_SIMD STREQUAL "0")
304-
set (SIMD_COMPILE_FLAGS ${SIMD_COMPILE_FLAGS} "-DOIIO_NO_SSE=1")
325+
set (SIMD_COMPILE_FLAGS ${SIMD_COMPILE_FLAGS} "-DOIIO_NO_SIMD=1")
305326
else ()
306-
string (REPLACE "," ";" SIMD_FEATURE_LIST ${USE_SIMD})
327+
set(_highest_msvc_arch 0)
328+
string (REPLACE "," ";" SIMD_FEATURE_LIST "${USE_SIMD}")
307329
foreach (feature ${SIMD_FEATURE_LIST})
308330
message (VERBOSE "SIMD feature: ${feature}")
309331
if (MSVC OR CMAKE_COMPILER_IS_INTEL)
310-
set (SIMD_COMPILE_FLAGS ${SIMD_COMPILE_FLAGS} "/arch:${feature}")
332+
if (feature STREQUAL "sse2")
333+
list (APPEND SIMD_COMPILE_FLAGS "/D__SSE2__")
334+
endif ()
335+
if (feature STREQUAL "sse4.1")
336+
list (APPEND SIMD_COMPILE_FLAGS "/D__SSE2__" "/D__SSE4_1__")
337+
endif ()
338+
if (feature STREQUAL "sse4.2")
339+
list (APPEND SIMD_COMPILE_FLAGS "/D__SSE2__" "/D__SSE4_2__")
340+
endif ()
341+
if (feature STREQUAL "avx" AND _highest_msvc_arch LESS 1)
342+
set(_highest_msvc_arch 1)
343+
endif ()
344+
if (feature STREQUAL "avx2" AND _highest_msvc_arch LESS 2)
345+
set(_highest_msvc_arch 2)
346+
endif ()
347+
if (feature STREQUAL "avx512f" AND _highest_msvc_arch LESS 3)
348+
set(_highest_msvc_arch 3)
349+
endif ()
311350
else ()
312-
set (SIMD_COMPILE_FLAGS ${SIMD_COMPILE_FLAGS} "-m${feature}")
351+
list (APPEND SIMD_COMPILE_FLAGS "-m${feature}")
313352
endif ()
314353
if (feature STREQUAL "fma" AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
315354
# If fma is requested, for numerical accuracy sake, turn it
@@ -319,10 +358,25 @@ if (NOT USE_SIMD STREQUAL "")
319358
add_compile_options ("-ffp-contract=off")
320359
endif ()
321360
endforeach()
361+
362+
# Only add a single /arch flag representing the highest level of support.
363+
if (MSVC OR CMAKE_COMPILER_IS_INTEL)
364+
if (_highest_msvc_arch EQUAL 1)
365+
list (APPEND SIMD_COMPILE_FLAGS "/arch:AVX")
366+
endif ()
367+
if (_highest_msvc_arch EQUAL 2)
368+
list (APPEND SIMD_COMPILE_FLAGS "/arch:AVX2")
369+
endif ()
370+
if (_highest_msvc_arch EQUAL 3)
371+
list (APPEND SIMD_COMPILE_FLAGS "/arch:AVX512")
372+
endif ()
373+
endif ()
374+
unset(_highest_msvc_arch)
322375
endif ()
323376
add_compile_options (${SIMD_COMPILE_FLAGS})
324377
endif ()
325378

379+
326380
###########################################################################
327381
# Batched SIMD shader execution options.
328382
#
@@ -395,7 +449,7 @@ endif ()
395449
###########################################################################
396450
# Sanitizer options
397451
#
398-
set (SANITIZE "" CACHE STRING "Build code using sanitizer (address, thread)")
452+
set_cache (SANITIZE "" "Build code using sanitizer (address, thread, undefined)")
399453
if (SANITIZE AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG))
400454
message (STATUS "Compiling for sanitizer=${SANITIZE}")
401455
string (REPLACE "," ";" SANITIZE_FEATURE_LIST ${SANITIZE})
@@ -433,9 +487,7 @@ if (CLANG_TIDY)
433487
DOC "Path to clang-tidy executable")
434488
message (STATUS "CLANG_TIDY_EXE ${CLANG_TIDY_EXE}")
435489
if (CLANG_TIDY_EXE)
436-
set (CMAKE_CXX_CLANG_TIDY
437-
"${CLANG_TIDY_EXE}"
438-
)
490+
set (CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
439491
if (CLANG_TIDY_ARGS)
440492
list (APPEND CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_ARGS})
441493
endif ()
@@ -511,21 +563,21 @@ endif ()
511563
set (EXTRA_CPP_ARGS "" CACHE STRING "Extra C++ command line definitions")
512564
if (EXTRA_CPP_ARGS)
513565
message (STATUS "Extra C++ args: ${EXTRA_CPP_ARGS}")
514-
add_compile_options ("${EXTRA_CPP_ARGS}")
566+
add_compile_options (${EXTRA_CPP_ARGS})
515567
endif()
516568
set (EXTRA_DSO_LINK_ARGS "" CACHE STRING "Extra command line definitions when building DSOs")
517569

518570

519571
###########################################################################
520572
# Set the versioning for shared libraries.
521573
#
522-
if (${PROJECT_NAME}_SUPPORTED_RELEASE)
574+
if (${PROJECT_NAME}_SUPPORTED_RELEASE AND NOT SKBUILD)
523575
# Supported releases guarantee ABI back-compatibility within the release
524576
# family, so SO versioning is major.minor.
525577
set (SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
526578
CACHE STRING "Set the SO version for dynamic libraries")
527579
else ()
528-
# Development master makes no ABI stability guarantee, so we make the
580+
# Main development branch makes no ABI stability guarantee, so we make the
529581
# SO naming capture down to the major.minor.patch level.
530582
set (SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
531583
CACHE STRING "Set the SO version for dynamic libraries")
@@ -537,7 +589,7 @@ message(VERBOSE "Setting SOVERSION to: ${SOVERSION}")
537589
# BUILD_SHARED_LIBS, if turned off, will disable building of .so/.dll
538590
# dynamic libraries and instead only build static libraries.
539591
#
540-
option (BUILD_SHARED_LIBS "Build shared libraries (set to OFF to build static libs)" ON)
592+
set_option (BUILD_SHARED_LIBS "Build shared libraries (set to OFF to build static libs)" ON)
541593
if (NOT BUILD_SHARED_LIBS)
542594
add_compile_definitions (${PROJECT_NAME}_STATIC_DEFINE=1)
543595
endif ()
@@ -601,6 +653,11 @@ set (CMAKE_SKIP_BUILD_RPATH FALSE)
601653
set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
602654

603655

656+
###########################################################################
657+
# Generate compile_commands.json for use by editors and tools.
658+
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
659+
660+
604661
###########################################################################
605662
# Macro to install targets to the appropriate locations. Use this instead
606663
# of the install(TARGETS ...) signature. Note that it adds it to the

0 commit comments

Comments
 (0)