Skip to content

Commit

Permalink
Refactor install & ForgeConfig script commands
Browse files Browse the repository at this point in the history
* Install version header as part of the headers component
* Remove configure_file command for NSIS template file on non-windows platforms.
* Move glsl_shader headers under `PROJECT_BINARY_DIR/include`
* Remove unused target properties from examples targets
* Merge ConditionalDirectory and IfNotThisThenInclude scripts into
  InternalUtils cmake script.
  • Loading branch information
9prady9 committed Apr 17, 2018
1 parent 08ecc51 commit 002b591
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 106 deletions.
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.5)

set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}prefix;${CMAKE_PREFIX_PATH}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/cmake")

include(BuildType)
include(FGInstallDirs)
Expand Down Expand Up @@ -106,9 +105,6 @@ add_subdirectory(src/api/c)
add_subdirectory(src/api/cpp)
add_subdirectory(src/backend/opengl)

conditional_directory(FG_BUILD_DOCS docs)
conditional_directory(FG_BUILD_EXAMPLES examples)

#--------------------------------------------------------------------
# Install include folder, docs, examples etc.
#--------------------------------------------------------------------
Expand All @@ -119,11 +115,16 @@ install(DIRECTORY include/
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN ".gitignore" EXCLUDE)
# The Forge version header is generated and thus need to be
# included explicitly
install(FILES ${Forge_BINARY_DIR}/include/fg/version.h
DESTINATION "${FG_INSTALL_INC_DIR}/fg/"
COMPONENT headers)

install(EXPORT ForgeTargets
NAMESPACE Forge::
DESTINATION ${FG_INSTALL_CMAKE_DIR}
COMPONENT cmake)
COMPONENT forge)

export(EXPORT ForgeTargets
NAMESPACE Forge::
Expand Down Expand Up @@ -174,3 +175,6 @@ install(DIRECTORY examples/ #NOTE The slash at the end is important
COMPONENT examples)

include(CPackConfig)

conditional_directory(FG_BUILD_DOCS docs)
conditional_directory(FG_BUILD_EXAMPLES examples)
11 changes: 6 additions & 5 deletions CMakeModules/CPackConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ file(GLOB_RECURSE CACHES "${CMAKE_SOURCE_DIR}/CMakeCache.txt")

include(CPack)

# Configure file with custom definitions for NSIS.
configure_file(
${PROJECT_SOURCE_DIR}/CMakeModules/nsis/NSIS.definitions.nsh.in
${CMAKE_CURRENT_BINARY_DIR}/NSIS.definitions.nsh
)
if (WIN32)
# Configure file with custom definitions for NSIS.
configure_file(
${PROJECT_SOURCE_DIR}/CMakeModules/nsis/NSIS.definitions.nsh.in
${CMAKE_CURRENT_BINARY_DIR}/NSIS.definitions.nsh)
endif ()
20 changes: 16 additions & 4 deletions CMakeModules/FGInstallDirs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,38 @@ if(NOT DEFINED FG_INSTALL_INC_DIR)
set(FG_INSTALL_INC_DIR "include" CACHE PATH "Installation path for headers")
endif()

set(DATA_DIR "share/Forge")

# Documentation
if(NOT DEFINED FG_INSTALL_DOC_DIR)
set(FG_INSTALL_DOC_DIR "doc" CACHE PATH "Installation path for documentation")
if (WIN32)
set(docs_dir "doc")
else ()
set(docs_dir "${DATA_DIR}/doc")
endif ()
set(FG_INSTALL_DOC_DIR "${docs_dir}" CACHE PATH "Installation path for documentation")
endif()

if(NOT DEFINED FG_INSTALL_EXAMPLE_DIR)
set(FG_INSTALL_EXAMPLE_DIR "examples" CACHE PATH "Installation path for examples")
if (WIN32)
set(examples_dir "examples")
else ()
set(examples_dir "${DATA_DIR}/examples")
endif ()
set(FG_INSTALL_EXAMPLE_DIR "${examples_dir}" CACHE PATH "Installation path for examples")
endif()

# Man pages
if(NOT DEFINED FG_INSTALL_MAN_DIR)
set(FG_INSTALL_MAN_DIR "man" CACHE PATH "Installation path for man pages")
set(FG_INSTALL_MAN_DIR "${DATA_DIR}/man" CACHE PATH "Installation path for man pages")
endif()

# CMake files
if(NOT DEFINED FG_INSTALL_CMAKE_DIR)
if(WIN32)
set(cmake_dir "cmake")
else()
set(cmake_dir "lib/cmake/Forge")
set(cmake_dir "${DATA_DIR}/cmake")
endif()
set(FG_INSTALL_CMAKE_DIR "${cmake_dir}" CACHE PATH "Installation path for CMake files")
endif()
Expand Down
109 changes: 67 additions & 42 deletions CMakeModules/ForgeConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,52 +1,77 @@
# Copyright (c) 2018, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause

# Forge
# -----
#
# This is the cmake configuration file for Forge library. It provides
# the following imported targets.
#
# ``Forge::forge`` - the target for Forge
#
# This target can be used to link with your application using the
# ``target_link_library`` command. Here is an example of how to use these
# targets in your application:
#
# add_executable(mybinary source.cpp)
# target_link_library(mybinary PRIVATE Forge::forge)
#
# This example creates a mybinary executable from the source.cpp file and links
# against the Forge library. Note you do *not* need to set the include
# directories as they are automatically included with the target.
#
# This is the recommended way of linking against Forge
#
#
# Legacy Variables
# ----------------
#
# Defines the following variables:
# Forge_INCLUDE_DIRS - Location of Forge's include directory.
# Forge_LIBRARIES - Location of Forge's libraries.
# Forge_FOUND - True if Forge has been located
# Forge_INCLUDE_DIRS - Path to Forge include directory.
# Forge_LIBRARIES - Path to Forge libraries used in link commands.
# Forge_FOUND - True if Forge backend has been found.
#
# You may provide a hint to where Forge's root directory may be located
# by setting Forge_DIR.
# by setting Forge_DIR. You do not need to set this if you installed
# Forge using the official installers or the package manager(please submit
# a bug report if any issues). If CMake is unable to locate Forge then
# set the Forge_DIR to the directory of this file.
#
#=============================================================================
# Copyright (c) 2015, ArrayFire
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# * Neither the name of the ArrayFire nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================

SET(Forge_VERSION "@Forge_VERSION@")
# If you are trying to link against a source build then this should be set to
# the build directory.

@PACKAGE_INIT@

SET_AND_CHECK(Forge_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@FG_INSTALL_INC_DIR@")
SET_AND_CHECK(Forge_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/@FG_INSTALL_LIB_DIR@")
set_and_check(Forge_INCLUDE_DIRS @PACKAGE_INCLUDE_DIRS@)

set(Forge_FOUND OFF)

FIND_LIBRARY(Forge_LIBRARIES forge HINTS ${Forge_LIBRARY_DIRS})
if (NOT TARGET Forge::forge AND
NOT TARGET forge AND
EXISTS @PACKAGE_CMAKE_DIR@/ForgeTargets.cmake)
include(@PACKAGE_CMAKE_DIR@/ForgeTargets.cmake)
endif ()

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Forge DEFAULT_MSG
Forge_INCLUDE_DIRS Forge_LIBRARIES)
if (TARGET Forge::forge)
get_property(config TARGET Forge::forge PROPERTY IMPORTED_CONFIGURATIONS)
if(NOT config)
set(config "NOCONFIG")
endif()
get_property(loc TARGET Forge::forge PROPERTY IMPORTED_LOCATION_${config})
endif ()

INCLUDE("@PACKAGE_CMAKE_DIR@/ForgeTargets.cmake")
if ((TARGET Forge::forge AND EXISTS ${loc})
OR
TARGET forge)
set(Forge_FOUND ON)
if (TARGET forge AND NOT TARGET Forge::forge)
add_library(Forge::forge ALIAS forge)
endif ()
set(Forge_LIBRARIES Forge::forge)
else ()
set(Forge_FOUND OFF)
endif ()
3 changes: 1 addition & 2 deletions CMakeModules/InternalUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ mark_as_advanced(
CUDA_SDK_ROOT_DIR
CUDA_TOOLKIT_ROOT_DIR
CUDA_USE_STATIC_CUDA_RUNTIME
CUDA_rt_LIBRARY
)
CUDA_rt_LIBRARY)
32 changes: 10 additions & 22 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(Forge-Examples LANGUAGES CXX)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

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

if(FG_ENABLE_HUNTER)
hunter_add_package(OpenCL)
Expand All @@ -13,9 +13,16 @@ else ()
find_package(OpenCL 1.2 QUIET)
endif()

find_package(Forge REQUIRED)
find_package(OpenGL REQUIRED)
find_package(CUDA QUIET)

mark_as_advanced(
CUDA_HOST_COMPILER
CUDA_USE_STATIC_CUDA_RUNTIME
CUDA_rt_LIBRARY
CMAKE_CUDA_HOST_COMPILER)

if(APPLE)
find_package(X11 REQUIRED)
if(X11_FOUND AND NOT TARGET X11::x11)
Expand All @@ -28,9 +35,8 @@ if(APPLE)
endif()

include(CMakeParseArguments)
include(ConditionalDirectory)
include(CMakeDependentOption)
include(IfNotThisThenInclude)
include(InternalUtils)

option(FG_BUILD_CUDA_EXAMPLES "Turn off/on building cuda examples" ${CUDA_FOUND})
option(FG_BUILD_OPENCL_EXAMPLES "Turn off/on building opencl examples" ${OpenCL_FOUND})
Expand All @@ -45,23 +51,6 @@ fg_deprecate(BUILD_EXAMPLES_CUDA FG_BUILD_CUDA_EXAMPLES)
fg_deprecate(BUILD_EXAMPLES_OPENCL FG_BUILD_OPENCL_EXAMPLES)
fg_deprecate(USE_SYSTEM_CL2HPP FG_USE_SYSTEM_CL2HPP)

add_library(OSCompileFlags INTERFACE)

if (WIN32)
target_compile_definitions(OSCompileFlags
INTERFACE OS_WIN WIN32_MEAN_AND_LEAN)
elseif (APPLE)
target_compile_definitions(OSCompileFlags INTERFACE OS_MAC)
else(WIN32)
target_compile_definitions(OSCompileFlags INTERFACE OS_LNX)
endif(WIN32)

if(TARGET forge)
add_library(Forge::forge ALIAS forge)
else()
include(${Forge_BINARY_DIR}/ForgeConfig.cmake)
endif()

function(add_example target_name source backend)
set(options CXX11)
set(single_value_args "")
Expand Down Expand Up @@ -92,8 +81,7 @@ function(add_example target_name source backend)
OpenGL::GL
Forge::forge
${arg_LIBRARIES}
$<$<PLATFORM_ID:Darwin>:X11::x11>
)
$<$<PLATFORM_ID:Darwin>:X11::x11>)
endfunction()

add_subdirectory(cpu)
Expand Down
6 changes: 0 additions & 6 deletions examples/CMakeModules/ConditionalDirectory.cmake

This file was deleted.

7 changes: 0 additions & 7 deletions examples/CMakeModules/IfNotThisThenInclude.cmake

This file was deleted.

46 changes: 46 additions & 0 deletions examples/CMakeModules/InternalUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2018, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause

function(__fg_deprecate_var var access value)
if(access STREQUAL "READ_ACCESS")
message(DEPRECATION "Variable ${var} is deprecated. Use FG_${var} instead.")
endif()
endfunction()

function(fg_deprecate var newvar)
if(DEFINED ${var})
message(DEPRECATION "Variable ${var} is deprecated. Use ${newvar} instead.")
get_property(doc CACHE ${newvar} PROPERTY HELPSTRING)
set(${newvar} ${${var}} CACHE BOOL "${doc}" FORCE)
unset(${var} CACHE)
endif()
variable_watch(${var} __fg_deprecate_var)
endfunction()

function(conditional_directory variable directory)
if(${variable})
add_subdirectory(${directory})
endif()
endfunction()

# Includes the cmake script if the variable is NOT true
macro(include_if_not variable cmake_script)
if(NOT ${variable})
include(${cmake_script})
endif()
endmacro()

add_library(OSCompileFlags INTERFACE)

if (WIN32)
target_compile_definitions(OSCompileFlags
INTERFACE OS_WIN WIN32_MEAN_AND_LEAN)
elseif (APPLE)
target_compile_definitions(OSCompileFlags INTERFACE OS_MAC)
else(WIN32)
target_compile_definitions(OSCompileFlags INTERFACE OS_LNX)
endif(WIN32)
11 changes: 3 additions & 8 deletions examples/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,19 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORCE_INLINES")

if (${CMAKE_VERSION} VERSION_LESS "3.10.0")
INCLUDE_DIRECTORIES(
${Forge_SOURCE_DIR}/include
${CUDA_INCLUDE_DIRS}
${CMAKE_CURRENT_DIR}
)
${CMAKE_CURRENT_SOURCE_DIR})
else()
enable_language(CUDA)
endif ()

macro(make_cuda_example target src)
add_example(${target} ${src} cuda CXX11
INCLUDE_DIRS
${Forge_SOURCE_DIR}/include
${CUDA_INCLUDE_DIRS}
${CMAKE_CURRENT_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
LIBRARIES
${CUDA_LIBRARIES}
${Forge_LIBRARIES}
)
${CUDA_LIBRARIES})
endmacro(make_cuda_example)

make_cuda_example(bubblechart bubblechart.cu)
Expand Down
Loading

0 comments on commit 002b591

Please sign in to comment.