Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: CMake cleanup #1504

Merged
merged 6 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ option(ENABLE_HTML "Enable HTML module, require CEF" ON)
# Add custom cmake modules path
LIST (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)

# Determine the git hash
FIND_PACKAGE (Git)
SET (CONFIG_VERSION_GIT_HASH "N/A")
IF (DEFINED ENV{GIT_HASH} AND NOT $ENV{GIT_HASH} STREQUAL "")
SET (CONFIG_VERSION_GIT_HASH "$ENV{GIT_HASH}")
ELSEIF (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/../.git")
EXEC_PROGRAM ("${GIT_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/../" ARGS rev-parse --verify --short HEAD OUTPUT_VARIABLE CONFIG_VERSION_GIT_HASH)
ENDIF ()

INCLUDE (CasparCG_Util)
CONFIGURE_FILE ("${PROJECT_SOURCE_DIR}/version.tmpl" "${CMAKE_BINARY_DIR}/generated/version.h")

if (MSVC)
INCLUDE (Bootstrap_Windows)
else ()
Expand All @@ -23,15 +35,14 @@ else ()
MESSAGE (STATUS "CPU Count: ${CONFIG_CPU_COUNT}")
MESSAGE (STATUS "Target build type: ${CMAKE_BUILD_TYPE}")
MESSAGE (STATUS "Build Version: ${CONFIG_VERSION_MAJOR}.${CONFIG_VERSION_MINOR}.${CONFIG_VERSION_BUG} ${CONFIG_VERSION_TAG} (Revision: ${CONFIG_VERSION_GIT_HASH})")
endif ()

CONFIGURE_FILE ("${PROJECT_SOURCE_DIR}/version.tmpl" "${CMAKE_BINARY_DIR}/generated/version.h")
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/generated")
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/generated")

ADD_SUBDIRECTORY (tools)
ADD_SUBDIRECTORY (accelerator)
ADD_SUBDIRECTORY (common)
ADD_SUBDIRECTORY (core)
ADD_SUBDIRECTORY (modules)
ADD_SUBDIRECTORY (protocol)
ADD_SUBDIRECTORY (shell)
endif ()
ADD_SUBDIRECTORY (tools)
ADD_SUBDIRECTORY (accelerator)
ADD_SUBDIRECTORY (common)
ADD_SUBDIRECTORY (core)
ADD_SUBDIRECTORY (modules)
ADD_SUBDIRECTORY (protocol)
ADD_SUBDIRECTORY (shell)
68 changes: 0 additions & 68 deletions src/CMakeModules/Bootstrap_Linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ IF (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
ENDIF ()
MARK_AS_ADVANCED (CMAKE_INSTALL_PREFIX)

FIND_PACKAGE (Git)
SET (CONFIG_VERSION_GIT_HASH "N/A")
IF (DEFINED ENV{GIT_HASH} AND NOT $ENV{GIT_HASH} STREQUAL "")
SET (CONFIG_VERSION_GIT_HASH "$ENV{GIT_HASH}")
ELSEIF (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/../.git")
EXEC_PROGRAM ("${GIT_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/../" ARGS rev-parse --verify --short HEAD OUTPUT_VARIABLE CONFIG_VERSION_GIT_HASH)
ENDIF ()

if (NOT USE_SYSTEM_BOOST)
SET (BOOST_ROOT_PATH "/opt/boost" CACHE STRING "Path to Boost")
SET (ENV{BOOST_ROOT} "${BOOST_ROOT_PATH}")
Expand Down Expand Up @@ -105,63 +97,3 @@ ENDIF ()
IF (POLICY CMP0045)
CMAKE_POLICY (SET CMP0045 OLD)
ENDIF ()

SET (CASPARCG_MODULE_INCLUDE_STATEMENTS "" CACHE INTERNAL "")
SET (CASPARCG_MODULE_INIT_STATEMENTS "" CACHE INTERNAL "")
SET (CASPARCG_MODULE_UNINIT_STATEMENTS "" CACHE INTERNAL "")
SET (CASPARCG_MODULE_COMMAND_LINE_ARG_INTERCEPTORS_STATEMENTS "" CACHE INTERNAL "")
SET (CASPARCG_MODULE_PROJECTS "" CACHE INTERNAL "")

# This PrecompiledHeader helper is broken on linux in debug builds
#INCLUDE (PrecompiledHeader)
FUNCTION (add_precompiled_header TARGET HEADER)
# Ignore
ENDFUNCTION ()

FUNCTION (casparcg_add_build_dependencies PROJECT)
# Ignore
ENDFUNCTION ()

FUNCTION (casparcg_add_include_statement HEADER_FILE_TO_INCLUDE)
SET (CASPARCG_MODULE_INCLUDE_STATEMENTS "${CASPARCG_MODULE_INCLUDE_STATEMENTS}"
"#include <${HEADER_FILE_TO_INCLUDE}>"
CACHE INTERNAL ""
)
ENDFUNCTION ()

FUNCTION (casparcg_add_init_statement INIT_FUNCTION_NAME NAME_TO_LOG)
SET (CASPARCG_MODULE_INIT_STATEMENTS "${CASPARCG_MODULE_INIT_STATEMENTS}"
" ${INIT_FUNCTION_NAME}(dependencies)\;"
" CASPAR_LOG(info) << L\"Initialized ${NAME_TO_LOG} module.\"\;"
""
CACHE INTERNAL ""
)
ENDFUNCTION ()

FUNCTION (casparcg_add_uninit_statement UNINIT_FUNCTION_NAME)
SET (CASPARCG_MODULE_UNINIT_STATEMENTS
" ${UNINIT_FUNCTION_NAME}()\;"
"${CASPARCG_MODULE_UNINIT_STATEMENTS}"
CACHE INTERNAL ""
)
ENDFUNCTION ()

FUNCTION (casparcg_add_command_line_arg_interceptor INTERCEPTOR_FUNCTION_NAME)
set(CASPARCG_MODULE_COMMAND_LINE_ARG_INTERCEPTORS_STATEMENTS "${CASPARCG_MODULE_COMMAND_LINE_ARG_INTERCEPTORS_STATEMENTS}"
" if (${INTERCEPTOR_FUNCTION_NAME}(argc, argv))"
" return true\;"
""
CACHE INTERNAL ""
)
ENDFUNCTION ()

FUNCTION (casparcg_add_module_project PROJECT)
SET (CASPARCG_MODULE_PROJECTS "${CASPARCG_MODULE_PROJECTS}" "${PROJECT}" CACHE INTERNAL "")
ENDFUNCTION ()

# http://stackoverflow.com/questions/7172670/best-shortest-way-to-join-a-list-in-cmake
FUNCTION (join_list VALUES GLUE OUTPUT)
STRING (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
STRING (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
SET (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
ENDFUNCTION ()
75 changes: 0 additions & 75 deletions src/CMakeModules/Bootstrap_Windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,13 @@ include(ExternalProject)
INCLUDE (PlatformIntrospection)
_DETERMINE_CPU_COUNT (CONFIG_CPU_COUNT)

find_package(Git)

set(CONFIG_VERSION_GIT_HASH "N/A")

if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/../.git")
exec_program("${GIT_EXECUTABLE}" "${PROJECT_SOURCE_DIR}"
ARGS rev-parse --verify --short HEAD
OUTPUT_VARIABLE CONFIG_VERSION_GIT_HASH)
endif ()

CONFIGURE_FILE ("${PROJECT_SOURCE_DIR}/version.tmpl" "${CMAKE_BINARY_DIR}/generated/version.h")
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/generated")

set(CASPARCG_DOWNLOAD_MIRROR https://github.com/CasparCG/dependencies/releases/download/ CACHE STRING "Source/mirror to use for external dependencies")
set(CASPARCG_DOWNLOAD_CACHE ${CMAKE_CURRENT_BINARY_DIR}/external CACHE STRING "Download cache directory for cmake ExternalProjects")
set(BOOST_USE_PRECOMPILED ON CACHE BOOL "Use precompiled boost")

set(CASPARCG_MODULE_INCLUDE_STATEMENTS "" CACHE INTERNAL "")
set(CASPARCG_MODULE_INIT_STATEMENTS "" CACHE INTERNAL "")
set(CASPARCG_MODULE_UNINIT_STATEMENTS "" CACHE INTERNAL "")
set(CASPARCG_MODULE_COMMAND_LINE_ARG_INTERCEPTORS_STATEMENTS "" CACHE INTERNAL "")
set(CASPARCG_MODULE_PROJECTS "" CACHE INTERNAL "")
set(CASPARCG_RUNTIME_DEPENDENCIES "" CACHE INTERNAL "")
set(CASPARCG_RUNTIME_DEPENDENCIES_DIRS "" CACHE INTERNAL "")

set(CASPARCG_EXTERNAL_PROJECTS "" CACHE INTERNAL "")
function (casparcg_add_external_project NAME)
set(CASPARCG_EXTERNAL_PROJECTS "${CASPARCG_EXTERNAL_PROJECTS}" "${NAME}" CACHE INTERNAL "")
endfunction()

function(casparcg_add_build_dependencies PROJECT)
add_dependencies(${PROJECT} ${CASPARCG_EXTERNAL_PROJECTS})
endfunction()

function(casparcg_add_include_statement HEADER_FILE_TO_INCLUDE)
set(CASPARCG_MODULE_INCLUDE_STATEMENTS "${CASPARCG_MODULE_INCLUDE_STATEMENTS}"
"#include <${HEADER_FILE_TO_INCLUDE}>"
CACHE INTERNAL "")
endfunction()

function(casparcg_add_init_statement INIT_FUNCTION_NAME NAME_TO_LOG)
set(CASPARCG_MODULE_INIT_STATEMENTS "${CASPARCG_MODULE_INIT_STATEMENTS}"
" ${INIT_FUNCTION_NAME}(dependencies)\;"
" CASPAR_LOG(info) << L\"Initialized ${NAME_TO_LOG} module.\"\;"
""
CACHE INTERNAL "")
endfunction()

function(casparcg_add_uninit_statement UNINIT_FUNCTION_NAME)
set(CASPARCG_MODULE_UNINIT_STATEMENTS
" ${UNINIT_FUNCTION_NAME}()\;"
"${CASPARCG_MODULE_UNINIT_STATEMENTS}"
CACHE INTERNAL "")
endfunction()

function(casparcg_add_command_line_arg_interceptor INTERCEPTOR_FUNCTION_NAME)
set(CASPARCG_MODULE_COMMAND_LINE_ARG_INTERCEPTORS_STATEMENTS "${CASPARCG_MODULE_COMMAND_LINE_ARG_INTERCEPTORS_STATEMENTS}"
" if (${INTERCEPTOR_FUNCTION_NAME}(argc, argv))"
" return true\;"
""
CACHE INTERNAL "")
endfunction()

function(casparcg_add_module_project PROJECT)
set(CASPARCG_MODULE_PROJECTS "${CASPARCG_MODULE_PROJECTS}" "${PROJECT}" CACHE INTERNAL "")
endfunction()

# http://stackoverflow.com/questions/7172670/best-shortest-way-to-join-a-list-in-cmake
function(join_list VALUES GLUE OUTPUT)
string (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
endfunction()

function(casparcg_add_runtime_dependency FILE_TO_COPY)
set(CASPARCG_RUNTIME_DEPENDENCIES "${CASPARCG_RUNTIME_DEPENDENCIES}" "${FILE_TO_COPY}" CACHE INTERNAL "")
endfunction()
Expand Down Expand Up @@ -310,11 +243,3 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /Ot /Gy /bigobj")
if (POLICY CMP0045)
cmake_policy(SET CMP0045 OLD)
endif ()

add_subdirectory(tools)
add_subdirectory(accelerator)
add_subdirectory(common)
add_subdirectory(core)
add_subdirectory(modules)
add_subdirectory(protocol)
add_subdirectory(shell)
108 changes: 108 additions & 0 deletions src/CMakeModules/CasparCG_Util.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Collect all ExternalProjects that have been defined
set(CASPARCG_EXTERNAL_PROJECTS "" CACHE INTERNAL "")
FUNCTION (casparcg_add_external_project NAME)
SET (CASPARCG_EXTERNAL_PROJECTS "${CASPARCG_EXTERNAL_PROJECTS}" "${NAME}" CACHE INTERNAL "")
ENDFUNCTION()

# Mark a project as depending on all of the ExternalProjects, to ensure build order
FUNCTION(casparcg_add_build_dependencies PROJECT)
if (CASPARCG_EXTERNAL_PROJECTS)
ADD_DEPENDENCIES (${PROJECT} ${CASPARCG_EXTERNAL_PROJECTS})
endif()
ENDFUNCTION()

# CasparCG version of CMake `add_library`
FUNCTION (casparcg_add_library PROJECT)
cmake_parse_arguments(
PARSED_ARGS # prefix of output variables
"" # list of names of the boolean arguments (only defined ones will be true)
"" # list of names of mono-valued arguments
"SOURCES" # list of names of multi-valued arguments (output variables are lists)
${ARGN} # arguments of the function to parse, here we take the all original ones
)

if(NOT PROJECT)
message(FATAL_ERROR "You must provide a project name")
endif()

# Setup the library and some default config
ADD_LIBRARY (${PROJECT} ${PARSED_ARGS_SOURCES})
target_compile_features (${PROJECT} PRIVATE cxx_std_17)
target_include_directories(${PROJECT} PRIVATE
${BOOST_INCLUDE_PATH}
${TBB_INCLUDE_PATH}
)

if (CASPARCG_EXTERNAL_PROJECTS)
# Setup dependency on ExternalProject
ADD_DEPENDENCIES (${PROJECT} ${CASPARCG_EXTERNAL_PROJECTS})
endif()

ENDFUNCTION ()

# CasparCG version of CMake `add_library` specifically for modules
SET (CASPARCG_MODULE_PROJECTS "" CACHE INTERNAL "")
FUNCTION (casparcg_add_module_project PROJECT)
cmake_parse_arguments(
PARSED_ARGS # prefix of output variables
"" # list of names of the boolean arguments (only defined ones will be true)
"NAME;HEADER_FILE;INIT_FUNCTION;UNINIT_FUNCTION;CLI_INTERCEPTOR" # list of names of mono-valued arguments
"SOURCES" # list of names of multi-valued arguments (output variables are lists)
${ARGN} # arguments of the function to parse, here we take the all original ones
)

# Use project if name is missing
if (NOT PARSED_ARGS_NAME)
set (PARSED_ARGS_NAME ${PROJECT})
endif()
# Use default path if header not defined
if (NOT PARSED_ARGS_HEADER_FILE)
set (PARSED_ARGS_HEADER_FILE "modules/${PROJECT}/${PROJECT}.h")
endif()
# Use default init name if nto d
if (NOT PARSED_ARGS_INIT_FUNCTION)
message(FATAL_ERROR "You must provide an INIT_FUNCTION")
endif()

# Setup the library and some default config
casparcg_add_library (${PROJECT} SOURCES ${PARSED_ARGS_SOURCES})
target_link_libraries(${PROJECT} common core)

# Setup linker and code loading
SET (CASPARCG_MODULE_PROJECTS "${CASPARCG_MODULE_PROJECTS}" "${PROJECT}" CACHE INTERNAL "")
SET (CASPARCG_MODULE_INCLUDE_STATEMENTS "${CASPARCG_MODULE_INCLUDE_STATEMENTS}"
"#include <${PARSED_ARGS_HEADER_FILE}>"
CACHE INTERNAL ""
)
SET (CASPARCG_MODULE_INIT_STATEMENTS "${CASPARCG_MODULE_INIT_STATEMENTS}"
" ${PARSED_ARGS_INIT_FUNCTION}(dependencies)\;"
" CASPAR_LOG(info) << L\"Initialized ${PARSED_ARGS_NAME} module.\"\;"
""
CACHE INTERNAL ""
)

IF (PARSED_ARGS_UNINIT_FUNCTION)
SET (CASPARCG_MODULE_UNINIT_STATEMENTS
" ${PARSED_ARGS_UNINIT_FUNCTION}()\;"
"${CASPARCG_MODULE_UNINIT_STATEMENTS}"
CACHE INTERNAL ""
)
ENDIF ()

IF (PARSED_ARGS_CLI_INTERCEPTOR)
SET (CASPARCG_MODULE_COMMAND_LINE_ARG_INTERCEPTORS_STATEMENTS "${CASPARCG_MODULE_COMMAND_LINE_ARG_INTERCEPTORS_STATEMENTS}"
" if (${PARSED_ARGS_CLI_INTERCEPTOR}(argc, argv))"
" return true\;"
""
CACHE INTERNAL ""
)
ENDIF ()

ENDFUNCTION ()

# http://stackoverflow.com/questions/7172670/best-shortest-way-to-join-a-list-in-cmake
FUNCTION (join_list VALUES GLUE OUTPUT)
STRING (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
STRING (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
SET (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
ENDFUNCTION ()
10 changes: 3 additions & 7 deletions src/accelerator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(SOURCES
accelerator.cpp
)
if (MSVC)
set(WIN32_SPECIFIC_SOURCES
list(APPEND SOURCES
d3d/d3d_device.cpp
d3d/d3d_device_context.cpp
d3d/d3d_texture2d.cpp
Expand All @@ -37,7 +37,7 @@ set(HEADERS
StdAfx.h
)
if (MSVC)
set(WIN32_SPECIFIC_HEADERS
list(APPEND HEADERS
d3d/d3d_device.h
d3d/d3d_device_context.h
d3d/d3d_texture2d.h
Expand All @@ -47,18 +47,14 @@ endif ()
bin2c("ogl/image/shader.vert" "ogl_image_vertex.h" "caspar::accelerator::ogl" "vertex_shader")
bin2c("ogl/image/shader.frag" "ogl_image_fragment.h" "caspar::accelerator::ogl" "fragment_shader")

add_library(accelerator ${SOURCES} ${HEADERS} ${WIN32_SPECIFIC_SOURCES} ${WIN32_SPECIFIC_HEADERS})
target_compile_features(accelerator PRIVATE cxx_std_17)
casparcg_add_library(accelerator SOURCES ${SOURCES} ${HEADERS})
target_include_directories(accelerator PRIVATE
..
${CMAKE_CURRENT_BINARY_DIR}
${BOOST_INCLUDE_PATH}
${TBB_INCLUDE_PATH}
${GLEW_INCLUDE_PATH}
${SFML_INCLUDE_PATH}
)
target_precompile_headers(accelerator PRIVATE "StdAfx.h")
casparcg_add_build_dependencies(accelerator)

source_group(sources ./.*)
source_group(sources\\cpu\\image cpu/image/.*)
Expand Down
10 changes: 3 additions & 7 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(SOURCES
utf.cpp
)
if (MSVC)
set(OS_SPECIFIC_SOURCES
list(APPEND SOURCES
compiler/vs/disable_silly_warnings.h

os/windows/filesystem.cpp
Expand All @@ -23,7 +23,7 @@ if (MSVC)
os/windows/windows.h
)
else ()
set(OS_SPECIFIC_SOURCES
list(APPEND SOURCES
os/linux/filesystem.cpp
os/linux/prec_timer.cpp
os/linux/thread.cpp
Expand Down Expand Up @@ -61,16 +61,12 @@ set(HEADERS
utf.h
)

add_library(common ${SOURCES} ${HEADERS} ${OS_SPECIFIC_SOURCES})
target_compile_features(common PRIVATE cxx_std_17)
casparcg_add_library(common SOURCES ${SOURCES} ${HEADERS})
target_include_directories(common PRIVATE
..
${BOOST_INCLUDE_PATH}
${TBB_INCLUDE_PATH}
${GLEW_INCLUDE_PATH}
)
target_precompile_headers(common PRIVATE "stdafx.h")
casparcg_add_build_dependencies(common)

source_group(sources ./*)
source_group(sources\\gl gl/*)
Expand Down
Loading