Skip to content

Commit b865cb0

Browse files
authored
build: port set_utils and dependency_utils from oiio cmake scripts (#1845)
For those who didn't see this get added in OIIO land a few months back, the highlights are: * set_utils.cmake -- variable setting utilities, including replacements/wrappers for set(CACHE) and option() that have a few extra bells and whistles, including that they allow environment variables of the same name to override the default values. * dependency_utils.cmake -- moved the prior contents of checked_find_package.cmake here, added more features, including... * An end-of-config dependency report that prints which dependencies were found and their versions, which were found but were too old, which were missing. * The skeleton of an automatic local dependency build facility. The short story is that if a dependency is not found or is too old AND it can find a file called src/cmake/build_PACKAGE.cmake, it will run that file and expect it to download and build the dependency on the fly. I haven't added any of those scripts here yet, but on the OIIO side we already have a few to build certain critical dependencies. Future PRs to OSL will also add the missing pieces to build the dependencies. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 64000b4 commit b865cb0

File tree

5 files changed

+783
-220
lines changed

5 files changed

+783
-220
lines changed

CMakeLists.txt

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ if (CMAKE_VERSION VERSION_LESS 3.21)
3939
endif ()
4040
endif ()
4141

42+
# Set up module path for our own cmake modules and add some esential ones
43+
list (APPEND CMAKE_MODULE_PATH
44+
"${PROJECT_SOURCE_DIR}/src/cmake/modules"
45+
"${PROJECT_SOURCE_DIR}/src/cmake")
46+
47+
# Utilities
48+
include (colors)
49+
include (set_utils)
50+
include (check_is_enabled)
51+
include (fancy_add_executable)
52+
53+
# If the user wants to use Conan to build dependencies, they will have done
54+
# this prior to the cmake config:
55+
# cd <build area>
56+
# conan install <source area>
57+
# and that will leave a conanbuildinfo.cmake in the build area for us.
58+
if (EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
59+
include (${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
60+
message (STATUS "Using Conan for dependencies")
61+
conan_basic_setup()
62+
endif()
63+
4264
if (NOT CMAKE_BUILD_TYPE)
4365
set (CMAKE_BUILD_TYPE "Release")
4466
endif ()
@@ -60,6 +82,7 @@ message (STATUS "Project build dir = ${CMAKE_BINARY_DIR}")
6082
message (STATUS "Project install prefix = ${CMAKE_INSTALL_PREFIX}")
6183
message (STATUS "Configuration types = ${CMAKE_CONFIGURATION_TYPES}")
6284
message (STATUS "Build type = ${CMAKE_BUILD_TYPE}")
85+
message (STATUS "Supported release = ${${PROJECT_NAME}_SUPPORTED_RELEASE}")
6386

6487
# Make the build area layout look a bit more like the final dist layout
6588
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
@@ -70,7 +93,6 @@ if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
7093
message (FATAL_ERROR "Not allowed to run in-source build!")
7194
endif ()
7295

73-
7496
option (CMAKE_USE_FOLDERS "Use the FOLDER target property to organize targets into folders." ON)
7597
mark_as_advanced (CMAKE_USE_FOLDERS)
7698
if (CMAKE_USE_FOLDERS)
@@ -158,22 +180,24 @@ if (${PROJ_NAME}_NAMESPACE_INCLUDE_PATCH)
158180
endif ()
159181
message(STATUS "Setting Namespace to: ${PROJ_NAMESPACE_V}")
160182

183+
# Define OSL_INTERNAL symbol only when building OSL itself, will not be
184+
# defined for downstream projects using OSL.
185+
add_definitions (-DOSL_INTERNAL=1)
161186

162-
list (APPEND CMAKE_MODULE_PATH
163-
"${PROJECT_SOURCE_DIR}/src/cmake/modules"
164-
"${PROJECT_SOURCE_DIR}/src/cmake")
165-
166-
# Helpful functions and macros for our project
167-
include (colors)
168-
include (check_is_enabled)
169-
include (checked_find_package)
187+
# To make sure we aren't relying on deprecated OIIO features, we define
188+
# OIIO_DISABLE_DEPRECATED before including any OIIO headers.
189+
add_definitions (-DOIIO_DISABLE_DEPRECATED=900000)
170190

171191
# All the C++ and compiler related options and adjustments
172192
include (compiler)
173193

194+
# Dependency finding utilities and all dependency-related options
195+
include (dependency_utils)
196+
174197
# Utilities and options related to finding python and making python bindings
175198
include (pythonutils)
176199

200+
# Dependency finding utilities and all dependency-related options
177201
include (externalpackages)
178202
include (flexbison)
179203
include (cuda_macros)
@@ -311,3 +335,5 @@ endif ()
311335
if (PROJECT_IS_TOP_LEVEL)
312336
include (packaging)
313337
endif ()
338+
339+
print_package_notfound_report ()

src/cmake/checked_find_package.cmake

Lines changed: 0 additions & 211 deletions
This file was deleted.

src/cmake/colors.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ set (ColorReset "${ColorEsc}[m")
99
set (ColorRed "${ColorEsc}[31m")
1010
set (ColorGreen "${ColorEsc}[32m")
1111
set (ColorYellow "${ColorEsc}[33m")
12+
set (ColorBlue "${ColorEsc}[34m")
13+
set (ColorMagenta "${ColorEsc}[35m")
14+
set (ColorBoldRed "${ColorEsc}[1;31m")
15+
set (ColorBoldGreen "${ColorEsc}[1;32m")
16+
set (ColorBoldYellow "${ColorEsc}[1;33m")
1217
set (ColorBoldWhite "${ColorEsc}[1;37m")

0 commit comments

Comments
 (0)