Skip to content

Commit

Permalink
Build: Adjust for changes introduced in Atoms 6
Browse files Browse the repository at this point in the history
In version 6 symbols compiled into `AtomsCore`, AtomsGraph` and
`AtomsUtils` are all in the `Atoms` libraries now. To adjust for this
we use only add those to the linked libraries for versions prior 6.

Additionally Toolchefs moved a `using half` directive into the
appropriate Atoms namespace, but including `AtomsUtils.h` pulls their
shipped `half.h` into the source file which leads to an undefined half
type. We attemt to fix this by instructing the preprocessor to include
the `half.h` found on the given search paths first.

The decision for this is to remove a constraint to add an include directive for half.h in every
source file which might depend on the half data type (via nested includes and
templated definitions provided by Cortex and Gaffer).
  • Loading branch information
yannci committed Feb 8, 2024
1 parent cca7c67 commit 4f01e11
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,38 @@ set(DEPENDENCY_INCLUDE_PATHS
${ATOMS_INCLUDE_PATH}
)

# The Atoms version is defined in the AtomsUtils/Version.h file. We read
# and parse it here for the major version
if(NOT ATOMS_MAJOR_VERSION)
find_file(ATOMS_VERSION_H "Version.h" ${ATOMS_INCLUDE_PATH}/AtomsUtils NO_CACHE)
file(READ ${ATOMS_VERSION_H} ATOMS_VERSION_CONTENT)
string(REGEX MATCH "ATOMS_MAJOR_VERSION ([0-9]*)" _ ${ATOMS_VERSION_CONTENT})
set(ATOMS_MAJOR_VERSION ${CMAKE_MATCH_1})
endif()

# In Atoms 6 the half type definition was moved into the Atoms namespace.
# When for example including AtomsUtils/Logger.h it will pull the half.h shipped with
# Atoms into the file. Since we want to use the one coming with our Imath
# version, we instruct the preprocessor to include `half.h` as if it was
# the first instruction in whatever source file and it will include a `half.h`
# found in one of the include paths (which we asume to be OpenExr/Imath).
# We make this version dependent to keep the previous behavior for older (re)builds.
if(ATOMS_MAJOR_VERSION VERSION_GREATER_EQUAL "6")
add_compile_options( -include "half.h" )
endif()

# build the library
file( GLOB AtomsGafferSrc src/AtomsGaffer/*.cpp )
link_directories( AtomsGaffer ${GAFFER_ROOT}/lib ${ATOMS_LIB_PATH} )
add_library( AtomsGaffer SHARED ${AtomsGafferSrc} )
target_compile_definitions( AtomsGaffer PRIVATE BOOST_SIGNALS_NO_DEPRECATION_WARNING=1 LINUX=1 _GLIBCXX_USE_CXX11_ABI=0)
target_include_directories( AtomsGaffer SYSTEM PRIVATE ${DEPENDENCY_INCLUDE_PATHS} )
target_include_directories( AtomsGaffer PRIVATE include )
target_link_libraries( AtomsGaffer Gaffer GafferScene AtomsCore AtomsGraph Atoms AtomsUtils )
# Since Atoms version 6, symbols from AtomsCore, AtomsGraph and AtomsUtils have been
# moved to the Atoms library, so we only link against the former for Atoms versions
# less than 6.
set(ATOMS_ADDITIONAL_LINK_LIBS AtomsCore AtomsGraph AtomsUtils)
target_link_libraries( AtomsGaffer Gaffer GafferScene Atoms "$<$<VERSION_LESS:${ATOMS_MAJOR_VERSION},6>:${ATOMS_ADDITIONAL_LINK_LIBS}>")
install( TARGETS AtomsGaffer DESTINATION lib )

# build the python bindings
Expand Down

0 comments on commit 4f01e11

Please sign in to comment.