Skip to content

Commit

Permalink
refactor: CMake option variables to have FG_ prefix
Browse files Browse the repository at this point in the history
Also marked some varaibles as advanced as they don't need to
be modified for most of the use cases.
  • Loading branch information
9prady9 committed Mar 16, 2018
1 parent 5c3f78c commit d8ee939
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 51 deletions.
82 changes: 50 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.5)

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

include(BuildType)
Expand All @@ -9,15 +10,10 @@ include(GetPrerequisites)
include(InternalUtils)
include(platform)

option(BUILD_SHARED_LIBS "Build shared/static library" ON)
option(USE_HUNTER "Use Hunter cmake package handler" OFF)
option(USE_STATIC_FREEIMAGE "Use static version of freeimage" OFF)
option(USE_STATIC_STDCPP "Use static libstdc++ for generating forge library" OFF)
option(USE_STATIC_GCC "Use static libgcc for generating forge library" OFF)
mark_as_advanced(USE_STATIC_STDCPP)
mark_as_advanced(USE_STATIC_GCC)
option(BUILD_SHARED_LIBS "Build shared/static library" ON)
option(FG_ENABLE_HUNTER "Use Hunter cmake package handler" OFF)

if(USE_HUNTER)
if(FG_ENABLE_HUNTER)
set(HUNTER_TLS_VERIFY OFF)
set(HUNTER_BUILD_SHARED_LIBS OFF)
include(${CMAKE_CURRENT_LIST_DIR}/CMakeModules/HunterGate.cmake)
Expand All @@ -36,7 +32,15 @@ include(Version)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if(USE_HUNTER)
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

if(FG_ENABLE_HUNTER)
hunter_add_package(glbinding)
hunter_add_package(glm)
hunter_add_package(freetype)
Expand All @@ -58,36 +62,50 @@ find_package(X11 QUIET)
find_package(FreeImage QUIET)
find_package(Boost REQUIRED)

option(BUILD_DOCS "Build Documentation" ${DOXYGEN_FOUND})
option(BUILD_EXAMPLES "Build Examples" ON)
option(WITH_FREEIMAGE "Use FreeImage to add support for
saving framebuffer to disk" ${FreeImage_FOUND})
option(FG_BUILD_DOCS
"Build Documentation" ${DOXYGEN_FOUND})
option(FG_BUILD_EXAMPLES
"Build Examples" ON)
option(FG_WITH_FREEIMAGE
"Use FreeImage to add support for saving framebuffer to disk"
${FreeImage_FOUND})

option(FG_USE_STATIC_FREEIMAGE
"Use static version of freeimage" OFF)
option(FG_USE_STATIC_STDCPP
"Use static libstdc++ for generating forge library" OFF)
option(FG_USE_STATIC_GCC
"Use static libgcc for generating forge library" OFF)

set(FG_USE_WINDOW_TOOLKIT "glfw3" CACHE STRING "Choose Window toolkit")
set_property(CACHE FG_USE_WINDOW_TOOLKIT PROPERTY STRINGS "glfw3" "sdl2")

mark_as_advanced(
FG_USE_STATIC_FREEIMAGE
FG_USE_STATIC_STDCPP
FG_USE_STATIC_GCC
)

fg_deprecate(BUILD_DOCS FG_BUILD_DOCS)
fg_deprecate(BUILD_EXAMPLES FG_BUILD_EXAMPLES)
fg_deprecate(WITH_FREEIMAGE FG_WITH_FREEIMAGE)
fg_deprecate(USE_STATIC_FREEIMAGE FG_USE_STATIC_FREEIMAGE)
fg_deprecate(WITH_TOOLKIT FG_USE_WINDOW_TOOLKIT)

if(Boost_FOUND AND NOT TARGET Boost::boost)
add_library(Boost::boost INTERFACE IMPORTED)
set_property(TARGET Boost::boost PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
set_property(TARGET Boost::boost
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
endif(Boost_FOUND AND NOT TARGET Boost::boost)


set(WINDOW_TOOLKIT "glfw3" CACHE STRING "Choose Window toolkit")
set_property(CACHE WINDOW_TOOLKIT PROPERTY STRINGS "glfw3" "sdl2")

# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

add_subdirectory(src/backend/common)
add_subdirectory(src/backend/glsl_shaders)
add_subdirectory(src/api/c)
add_subdirectory(src/api/cpp)
add_subdirectory(src/backend/opengl)

conditional_directory(BUILD_DOCS docs)
conditional_directory(BUILD_EXAMPLES examples)
conditional_directory(FG_BUILD_DOCS docs)
conditional_directory(FG_BUILD_EXAMPLES examples)

#--------------------------------------------------------------------
# Install include folder, docs, examples etc.
Expand Down Expand Up @@ -148,10 +166,10 @@ configure_package_config_file(
#--------------------------------------------------------------------
# Install examples
#--------------------------------------------------------------------
# install the examples irrespective of the BUILD_EXAMPLES value
# install the examples irrespective of the FG_BUILD_EXAMPLES value
# only the examples source files are installed, so the installation of these
# source files does not depend on BUILD_EXAMPLES
# when BUILD_EXAMPLES is OFF, the examples source is installed without
# source files does not depend on FG_BUILD_EXAMPLES
# when FG_BUILD_EXAMPLES is OFF, the examples source is installed without
# building the example executables
install(DIRECTORY examples/ #NOTE The slash at the end is important
DESTINATION ${FG_INSTALL_EXAMPLE_DIR}
Expand Down
27 changes: 27 additions & 0 deletions CMakeModules/InternalUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,30 @@ function(resolve_dependencies_paths out_deps in_deps context search_dirs)
endforeach()
set(${out_deps} ${out_list} PARENT_SCOPE)
endfunction()

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()

# mark CUDA cmake cache variables as advanced
# this should have been taken care of by FindCUDA I think.
mark_as_advanced(
CMAKE_CUDA_HOST_COMPILER
CUDA_HOST_COMPILER
CUDA_SDK_ROOT_DIR
CUDA_TOOLKIT_ROOT_DIR
CUDA_USE_STATIC_CUDA_RUNTIME
CUDA_rt_LIBRARY
)
23 changes: 14 additions & 9 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

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

if(USE_HUNTER)
if(FG_ENABLE_HUNTER)
hunter_add_package(OpenCL)
endif()

Expand All @@ -25,18 +25,23 @@ if(APPLE)
endif()
endif()

option(BUILD_EXAMPLES_CUDA "Turn off/on building cuda examples" ${CUDA_FOUND})
option(BUILD_EXAMPLES_OPENCL "Turn off/on building opencl examples" ${OpenCL_FOUND})
mark_as_advanced(BUILD_EXAMPLES_CUDA BUILD_EXAMPLES_OPENCL)

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

cmake_dependent_option(USE_SYSTEM_CL2HPP "Use system cl2.hpp header" OFF "OpenCL_FOUND" OFF)
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})

cmake_dependent_option(FG_USE_SYSTEM_CL2HPP "Use system cl2.hpp header" OFF "OpenCL_FOUND" OFF)

include_if_not(FG_USE_SYSTEM_CL2HPP build_cl2hpp)

mark_as_advanced(FG_BUILD_CUDA_EXAMPLES FG_BUILD_OPENCL_EXAMPLES)

include_if_not(USE_SYSTEM_CL2HPP build_cl2hpp)
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)

Expand Down Expand Up @@ -90,5 +95,5 @@ function(add_example target_name source backend)
endfunction()

add_subdirectory(cpu)
conditional_directory(BUILD_EXAMPLES_CUDA cuda)
conditional_directory(BUILD_EXAMPLES_OPENCL opencl)
conditional_directory(FG_BUILD_CUDA_EXAMPLES cuda)
conditional_directory(FG_BUILD_OPENCL_EXAMPLESCL opencl)
16 changes: 8 additions & 8 deletions src/backend/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ target_sources(${BackendTarget}
${CMAKE_CURRENT_SOURCE_DIR}/window_impl.cpp
)

if(${WINDOW_TOOLKIT} STREQUAL "glfw3")
if(${FG_USE_WINDOW_TOOLKIT} STREQUAL "glfw3")
add_subdirectory(glfw)
target_compile_definitions(${BackendTarget} PRIVATE USE_GLFW)
elseif(${WINDOW_TOOLKIT} STREQUAL "sdl2")
elseif(${FG_USE_WINDOW_TOOLKIT} STREQUAL "sdl2")
add_subdirectory(sdl)
target_compile_definitions(${BackendTarget} PRIVATE USE_SDL)
endif()

if(WITH_FREEIMAGE)
if(FG_WITH_FREEIMAGE)
target_compile_definitions(${BackendTarget} PRIVATE USE_FREEIMAGE)
if (USE_STATIC_FREEIMAGE)
if (FG_USE_STATIC_FREEIMAGE)
target_link_libraries(${BackendTarget} PRIVATE FreeImage::FreeImage_STATIC)
else ()
target_link_libraries(${BackendTarget} PRIVATE FreeImage::FreeImage)
Expand Down Expand Up @@ -107,8 +107,8 @@ if(UNIX)
PRIVATE
FontConfig::FontConfig
${X11_X11_LIB}
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<BOOL:${USE_STATIC_STDCPP}>>:-static-libstdc++>
$<$<AND:$<C_COMPILER_ID:GNU>,$<BOOL:${USE_STATIC_GCC}>>:-static-libgcc>
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<BOOL:${FG_USE_STATIC_STDCPP}>>:-static-libstdc++>
$<$<AND:$<C_COMPILER_ID:GNU>,$<BOOL:${FG_USE_STATIC_GCC}>>:-static-libgcc>
)
endif(UNIX)

Expand All @@ -120,9 +120,9 @@ source_group("api\\c" REGULAR_EXPRESSION ${Forge_SOURCE_DIR}/src/api/c
source_group("backend" REGULAR_EXPRESSION ${Forge_SOURCE_DIR}/src/backend/common/*|${CMAKE_CURRENT_SOURCE_DIR}/*)
source_group("backend\\shaders" REGULAR_EXPRESSION ${Forge_SOURCE_DIR}/src/backend/glsl_shaders/*)

if(${WINDOW_TOOLKIT} STREQUAL "glfw3")
if(${FG_USE_WINDOW_TOOLKIT} STREQUAL "glfw3")
source_group("backend\\glfw" REGULAR_EXPRESSION ${Forge_SOURCE_DIR}/src/backend/opengl/glfw/*)
elseif(${WINDOW_TOOLKIT} STREQUAL "sdl2")
elseif(${FG_USE_WINDOW_TOOLKIT} STREQUAL "sdl2")
source_group("backend\\sdl2" REGULAR_EXPRESSION ${Forge_SOURCE_DIR}/src/backend/opengl/sdl/*)
endif()

Expand Down
2 changes: 1 addition & 1 deletion src/backend/opengl/glfw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(USE_HUNTER)
if(FG_ENABLE_HUNTER)
hunter_add_package(glfw)
endif()

Expand Down
2 changes: 1 addition & 1 deletion src/backend/opengl/sdl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if(USE_HUNTER)
if(FG_ENABLE_HUNTER)
hunter_add_package(SDL2)
endif()

Expand Down

0 comments on commit d8ee939

Please sign in to comment.