Skip to content

Commit

Permalink
Examples CMakeLists.txt cleanup
Browse files Browse the repository at this point in the history
Removes INTERFACE library from examples cmake

CUDA backend examples need newer FindCUDA module so that same LINK
keyword(PRIVATE|PUBLIC) is used for example targets. Older FindCUDA
modules from CMake doesn't have this customization. Hence, copied the
module from CMake. 3.20 to examples/cuda/CMakeModules
  • Loading branch information
9prady9 committed Apr 21, 2021
1 parent ee6865c commit d1b8fdc
Show file tree
Hide file tree
Showing 11 changed files with 3,026 additions and 54 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ endif()
option(FG_BUILD_DOCS
"Build Documentation" $<AND:${DOXYGEN_FOUND},${Sphinx_FOUND}>)
option(FG_BUILD_EXAMPLES
"Build Examples" ON)
"Build CPU Examples" ON)
option(FG_WITH_FREEIMAGE
"Use FreeImage to add support for saving framebuffer to disk"
${FreeImage_FOUND})
Expand Down Expand Up @@ -152,8 +152,6 @@ export(EXPORT ForgeTargets
FILE ForgeTargets.cmake
)

include(ForgeCPackConfig)

conditional_directory(FG_BUILD_DOCS docs)
conditional_directory(FG_BUILD_EXAMPLES examples)

Expand All @@ -178,3 +176,5 @@ mark_as_advanced(
Z_VCPKG_CL
_VCPKG_INSTALLED_DIR
)

include(ForgeCPackConfig)
58 changes: 30 additions & 28 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")

include(CMakeDependentOption)
include(CMakeParseArguments)
include(InternalUtils)

set(CUDA_LINK_LIBRARIES_KEYWORD "PRIVATE")
find_package(CUDA QUIET)
find_package(OpenCL 1.2 QUIET)
include(build_cl2hpp) #This needs to be after find OpenCL call only

set(FORGE_BUILD_TREE OFF)
if(Forge_BINARY_DIR AND EXISTS "${Forge_BINARY_DIR}")
set(Forge_DIR ${Forge_BINARY_DIR})
set(FORGE_BUILD_TREE ON)
endif()

find_package(OpenCL 1.2 QUIET)
find_package(CUDA QUIET)
find_package(Forge REQUIRED)

mark_as_advanced(
CUDA_HOST_COMPILER
CUDA_USE_STATIC_CUDA_RUNTIME
CUDA_rt_LIBRARY
CMAKE_CUDA_HOST_COMPILER)

include(CMakeParseArguments)
include(CMakeDependentOption)
include(InternalUtils)
find_package(Forge REQUIRED)

cmake_dependent_option(FG_BUILD_OPENCL_EXAMPLES
"Build opencl examples" ON
Expand All @@ -34,15 +30,6 @@ cmake_dependent_option(FG_BUILD_CUDA_EXAMPLES
"Build cuda examples" ON
"CUDA_FOUND;FG_BUILD_EXAMPLES" OFF)

include(build_cl2hpp)
mark_as_advanced(
FG_BUILD_CUDA_EXAMPLES
FG_BUILD_OPENCL_EXAMPLES
)

fg_deprecate(BUILD_EXAMPLES_CUDA FG_BUILD_CUDA_EXAMPLES)
fg_deprecate(BUILD_EXAMPLES_OPENCL FG_BUILD_OPENCL_EXAMPLES)

function(add_example target_name source backend)
set(options CXX11)
set(single_value_args "")
Expand Down Expand Up @@ -84,14 +71,29 @@ function(add_example target_name source backend)
set_target_properties(${target} PROPERTIES CXX_STANDARD 11)
endif (${arg_CXX11})

target_include_directories(${target} PRIVATE ${arg_INCLUDE_DIRS})
if(WIN32)
target_compile_definitions(${target} PRIVATE OS_WIN WIN32_MEAN_AND_LEAN)
elseif(APPLE)
target_compile_definitions(${target} PRIVATE OS_MAC)
else(WIN32)
target_compile_definitions(${target} PRIVATE OS_LNX)
endif(WIN32)

target_link_libraries(${target}
OSCompileFlags
Forge::forge
${arg_LIBRARIES})
target_include_directories(${target} PRIVATE ${arg_INCLUDE_DIRS})
target_link_libraries(${target} PRIVATE Forge::forge ${arg_LIBRARIES})
endfunction()

add_subdirectory(cpu)
conditional_directory(FG_BUILD_CUDA_EXAMPLES cuda)
conditional_directory(FG_BUILD_OPENCL_EXAMPLES opencl)

mark_as_advanced(
FG_BUILD_CUDA_EXAMPLES
FG_BUILD_OPENCL_EXAMPLES
CUDA_HOST_COMPILER
CUDA_USE_STATIC_CUDA_RUNTIME
CUDA_rt_LIBRARY
CMAKE_CUDA_HOST_COMPILER)

fg_deprecate(BUILD_EXAMPLES_CUDA FG_BUILD_CUDA_EXAMPLES)
fg_deprecate(BUILD_EXAMPLES_OPENCL FG_BUILD_OPENCL_EXAMPLES)
Loading

0 comments on commit d1b8fdc

Please sign in to comment.