Skip to content

Commit

Permalink
Simplify cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
kunitoki committed Apr 30, 2024
1 parent 7e42343 commit e62b81f
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 275 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@ set_property (GLOBAL PROPERTY USE_FOLDERS ON)
option (YUP_BUILD_EXAMPLES "Build the examples" ON)
option (YUP_BUILD_TESTS "Build the tests" ON)

# Dependencies modules
yup_add_module (thirdparty/glad)
yup_add_module (thirdparty/harfbuzz)
yup_add_module (thirdparty/sheenbidi)
yup_add_module (thirdparty/rive)
yup_add_module (thirdparty/rive_pls_renderer)

# Original juce modules
yup_add_module (modules/juce_core)
yup_add_module (modules/juce_events)
yup_add_module (modules/juce_audio_basics)
yup_add_module (modules/juce_audio_devices)

# New yup modules
yup_add_module (modules/yup_graphics)
yup_add_module (modules/yup_gui)

# Targets
if (YUP_BUILD_EXAMPLES)
message (STATUS "YUP -- Building examples")
add_subdirectory (examples/app)
Expand Down
85 changes: 82 additions & 3 deletions cmake/yup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ endfunction()

#==============================================================================

function (_yup_prepare_frameworks frameworks weak_frameworks output_variable)
function (_yup_module_prepare_frameworks frameworks weak_frameworks output_variable)
set (temp_frameworks "")
foreach (framework ${frameworks})
list (APPEND temp_frameworks "-framework ${framework}")
Expand Down Expand Up @@ -296,10 +296,10 @@ function (yup_add_module module_path)
set (module_libs "")
if ("${yup_platform}" MATCHES "^(ios)$")
set (module_libs "${module_ios_libs}")
_yup_prepare_frameworks ("${module_ios_frameworks}" "${module_ios_weak_frameworks}" module_frameworks)
_yup_module_prepare_frameworks ("${module_ios_frameworks}" "${module_ios_weak_frameworks}" module_frameworks)
elseif ("${yup_platform}" MATCHES "^(osx)$")
set (module_libs "${module_osx_libs}")
_yup_prepare_frameworks ("${module_osx_frameworks}" "${module_osx_weak_frameworks}" module_frameworks)
_yup_module_prepare_frameworks ("${module_osx_frameworks}" "${module_osx_weak_frameworks}" module_frameworks)
elseif ("${yup_platform}" MATCHES "^(linux)$")
set (module_libs "${module_linux_libs}")
foreach (package ${module_linux_packages})
Expand Down Expand Up @@ -390,3 +390,82 @@ function (yup_add_module module_path)
source_group (TREE ${module_path}/ FILES ${all_module_files})

endfunction()

#==============================================================================

function (yup_standalone_app)
# ==== Fetch options
set (options CONSOLE)
set (one_value_args TARGET_NAME)
set (multi_value_args DEFINITIONS MODULES LINK_OPTIONS)

cmake_parse_arguments (YUP_ARG "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})

set (target_name "${YUP_ARG_TARGET_NAME}")
set (additional_libraries "")
set (additional_definitions "")

# ==== Find dependencies
if (NOT "${yup_platform}" STREQUAL "emscripten")
include (FetchContent)

FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG master)
set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable (glfw)

set (additional_libraries "glfw")
endif()

# ==== Prepare sources
add_executable (${target_name})

target_compile_features (${target_name} PRIVATE cxx_std_17)

if (NOT YUP_ARG_CONSOLE)
if ("${yup_platform}" MATCHES "^(osx|ios)$")
set_target_properties (${target_name} PROPERTIES
BUNDLE ON
CXX_EXTENSIONS OFF
MACOSX_BUNDLE_GUI_IDENTIFIER "org.kunitoki.yup.${target_name}"
MACOSX_BUNDLE_NAME "${target_name}"
MACOSX_BUNDLE_VERSION "1.0.0"
#MACOSX_BUNDLE_ICON_FILE "Icon.icns"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/platforms/macos/Info.plist"
#RESOURCE "${RESOURCE_FILES}"
#XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED OFF
XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf
XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN ON
XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME OFF)

elseif ("${yup_platform}" MATCHES "^(emscripten)$")
set_target_properties (${target_name} PROPERTIES SUFFIX ".html")

set (additional_definitions "RIVE_WEBGL=1")

target_link_options (${target_name} PRIVATE
$<$<CONFIG:DEBUG>:-gsource-map>
-sWASM=1 -sASSERTIONS=1 -sUSE_GLFW=3 -sERROR_ON_UNDEFINED_SYMBOLS=1
-sDEMANGLE_SUPPORT=1 -sSTACK_OVERFLOW_CHECK=2 -sFORCE_FILESYSTEM=1
-sNODERAWFS=0 -sMAX_WEBGL_VERSION=2 -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$dynCall'
${YUP_ARG_LINK_OPTIONS})

endif()
endif()

target_compile_definitions (${target_name} PRIVATE
$<$<CONFIG:DEBUG>:DEBUG=1>
$<$<CONFIG:RELEASE>:NDEBUG=1>
JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1
JUCE_STANDALONE_APPLICATION=1
${YUP_ARG_DEFINITIONS}
${additional_definitions})

target_link_libraries (${target_name} PRIVATE
${YUP_ARG_MODULES}
${additional_libraries})

endfunction()
86 changes: 17 additions & 69 deletions examples/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,79 +17,27 @@
#
# ==============================================================================

cmake_minimum_required (VERSION 3.28)
cmake_minimum_required(VERSION 3.28)

# ==== Prepare target
set (target_name example_app)

# ==== Find dependencies
set (additional_deps "")
if (NOT "${yup_platform}" STREQUAL "emscripten")
include (FetchContent)
FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG master)
set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable (glfw)
set (additional_deps "glfw")
endif()
yup_standalone_app (
TARGET_NAME ${target_name}
MODULES
juce_core
juce_events
juce_audio_basics
juce_audio_devices
yup_graphics
yup_gui
harfbuzz
sheenbidi
rive
rive_pls_renderer
)

# ==== Prepare sources
file (GLOB_RECURSE sources
"${CMAKE_CURRENT_LIST_DIR}/source/*.cpp")

file (GLOB_RECURSE sources "${CMAKE_CURRENT_LIST_DIR}/source/*.cpp")
source_group (TREE ${CMAKE_CURRENT_LIST_DIR}/ FILES ${sources})

# ==== Setup executable
add_executable (${target_name})

target_compile_features (${target_name} PRIVATE cxx_std_17)

target_sources (${target_name} PRIVATE ${sources})

if ("${yup_platform}" MATCHES "^(osx|ios)$")
set_target_properties (${target_name} PROPERTIES
BUNDLE ON
CXX_STANDARD 17
CXX_EXTENSIONS OFF
MACOSX_BUNDLE_GUI_IDENTIFIER "org.kunitoki.yup.${target_name}"
MACOSX_BUNDLE_NAME "${target_name}"
MACOSX_BUNDLE_ERSION "1.0.0"
MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0"
#MACOSX_BUNDLE_ICON_FILE "Icon.icns"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/../../cmake/platforms/macos/Info.plist"
#RESOURCE "${RESOURCE_FILES}"
#XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED OFF
XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf
XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN ON
XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME OFF)
elseif ("${yup_platform}" MATCHES "^(emscripten)$")
set_target_properties (${target_name} PROPERTIES
SUFFIX ".html")

target_link_options (${target_name} PRIVATE
-gsource-map -sWASM=1 -sASSERTIONS=1 -sUSE_GLFW=3 -sERROR_ON_UNDEFINED_SYMBOLS=1
-sDEMANGLE_SUPPORT=1 -sSTACK_OVERFLOW_CHECK=2 -sFORCE_FILESYSTEM=1 -sNODERAWFS=0
-sEXPORTED_RUNTIME_METHODS=cwrap
-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$dynCall')
endif()

target_compile_definitions (${target_name} PRIVATE
$<$<CONFIG:DEBUG>:DEBUG=1>
$<$<CONFIG:RELEASE>:NDEBUG=1>
JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1
JUCE_STANDALONE_APPLICATION=1)

target_link_libraries (${target_name} PRIVATE
juce_core
juce_events
juce_audio_basics
juce_audio_devices
yup_graphics
yup_gui
harfbuzz
sheenbidi
rive
rive_pls_renderer
${additional_deps})
40 changes: 14 additions & 26 deletions examples/console/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,22 @@
#
# ==============================================================================

cmake_minimum_required (VERSION 3.28)
cmake_minimum_required(VERSION 3.28)

# ==== Prepare target
set (target_name example_console)

file (GLOB_RECURSE sources
"${CMAKE_CURRENT_LIST_DIR}/source/*.cpp")

yup_standalone_app (
TARGET_NAME ${target_name}
CONSOLE
MODULES
juce_core
juce_events
juce_audio_basics
juce_audio_devices
)

# ==== Prepare sources
file (GLOB_RECURSE sources "${CMAKE_CURRENT_LIST_DIR}/source/*.cpp")
source_group (TREE ${CMAKE_CURRENT_LIST_DIR}/ FILES ${sources})

add_executable (${target_name})

target_compile_features (${target_name} PRIVATE cxx_std_17)

target_sources (${target_name} PRIVATE ${sources})

if ("${yup_platform}" STREQUAL "emscripten")
target_link_options (${target_name} PRIVATE
-sWASM=1 -sASSERTIONS=1 -sERROR_ON_UNDEFINED_SYMBOLS=1 -sDEMANGLE_SUPPORT=1 -sSTACK_OVERFLOW_CHECK=2 -sFORCE_FILESYSTEM=1 -sNODERAWFS=0)
endif()

target_compile_definitions (${target_name} PRIVATE
$<$<CONFIG:DEBUG>:DEBUG=1>
$<$<CONFIG:RELEASE>:NDEBUG=1>
JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1
JUCE_STANDALONE_APPLICATION=1)

target_link_libraries (${target_name} PRIVATE
juce_core
juce_events
juce_audio_basics
juce_audio_devices)
89 changes: 16 additions & 73 deletions examples/graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,82 +19,25 @@

cmake_minimum_required(VERSION 3.28)

# ==== Prepare target
set (target_name example_graphics)

# ==== Find dependencies
set (additional_deps "")
if (NOT "${yup_platform}" STREQUAL "emscripten")
include (FetchContent)
FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG master)
set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable (glfw)
set (additional_deps "glfw")
endif()
yup_standalone_app (
TARGET_NAME ${target_name}
MODULES
juce_core
juce_events
juce_audio_basics
juce_audio_devices
yup_graphics
yup_gui
harfbuzz
sheenbidi
rive
rive_pls_renderer
)

# ==== Prepare sources
file (GLOB_RECURSE sources
"${CMAKE_CURRENT_LIST_DIR}/source/main.cpp")

file (GLOB_RECURSE sources "${CMAKE_CURRENT_LIST_DIR}/source/*.cpp")
source_group (TREE ${CMAKE_CURRENT_LIST_DIR}/ FILES ${sources})

# ==== Setup executable
add_executable (${target_name})

target_compile_features (${target_name} PRIVATE cxx_std_17)

target_sources (${target_name} PRIVATE ${sources})

set (additional_definitions "")

if ("${yup_platform}" MATCHES "^(osx|ios)$")
set_target_properties (${target_name} PROPERTIES
BUNDLE ON
CXX_STANDARD 17
CXX_EXTENSIONS OFF
MACOSX_BUNDLE_GUI_IDENTIFIER "org.kunitoki.yup.${target_name}"
MACOSX_BUNDLE_NAME "${target_name}"
MACOSX_BUNDLE_ERSION "1.0.0"
MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0"
#MACOSX_BUNDLE_ICON_FILE "Icon.icns"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/../../cmake/platforms/macos/Info.plist"
#RESOURCE "${RESOURCE_FILES}"
#XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED OFF
XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf
XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN ON
XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME OFF)
elseif ("${yup_platform}" MATCHES "^(emscripten)$")
set_target_properties (${target_name} PROPERTIES
SUFFIX ".html")

set (additional_definitions "RIVE_WEBGL=1")

target_link_options (${target_name} PRIVATE
-gsource-map -sWASM=1 -sASSERTIONS=1 -sUSE_GLFW=3 -sERROR_ON_UNDEFINED_SYMBOLS=1
-sDEMANGLE_SUPPORT=1 -sSTACK_OVERFLOW_CHECK=2 -sFORCE_FILESYSTEM=1 -sNODERAWFS=0
-sMAX_WEBGL_VERSION=2
-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$dynCall')
endif()

target_compile_definitions (${target_name} PRIVATE
$<$<CONFIG:DEBUG>:DEBUG=1>
$<$<CONFIG:RELEASE>:NDEBUG=1>
JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1
JUCE_STANDALONE_APPLICATION=1
${additional_definitions})

target_link_libraries (${target_name} PRIVATE
juce_core
juce_events
juce_audio_basics
juce_audio_devices
yup_graphics
yup_gui
harfbuzz
sheenbidi
rive
rive_pls_renderer
${additional_deps})
Loading

0 comments on commit e62b81f

Please sign in to comment.