Switched to global Bundles.cmake

This commit is contained in:
Max Wash
2020-08-23 19:39:19 +01:00
parent cff3723792
commit 9d384d164c
2 changed files with 9 additions and 148 deletions

View File

@@ -1,139 +0,0 @@
find_program(BUNDLE_PROGRAM "bundle")
if (BUNDLE_PROGRAM STREQUAL BUNDLE_PROGRAM-NOTFOUND)
message(WARNING "Couldn't find Bundle generator. "
"Please install bundle from https://gitalb.com/doorstuck/magenta/bundle.git")
endif ()
function (add_framework name)
set(options STATIC SHARED)
set(one_value_args BUNDLE_ID)
set(multi_value_args HEADER_DIRS HEADERS SOURCES)
cmake_parse_arguments(ARG "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
if (ARG_HEADER_DIRS STREQUAL "")
message(FATAL_ERROR "add_framework: No header directories specified for ${name}")
endif ()
if (ARG_SOURCES STREQUAL "")
message(FATAL_ERROR "add_framework: No source files specified for ${name}")
endif ()
if (ARG_BUNDLE_ID STREQUAL "")
message(FATAL_ERROR "add_framework: No bundle ID specified for ${name}")
endif ()
string(TOLOWER ${name} lib_name)
if (NOT ARG_STATIC AND NOT ARG_SHARED)
message(FATAL_ERROR "add_framework: Neither STATIC nor SHARED specified for ${name}")
endif ()
add_custom_target(${name} ALL)
if (ARG_STATIC)
add_library(${lib_name}_s STATIC ${ARG_SOURCES})
add_dependencies(${name} ${lib_name}_s)
endif ()
if (ARG_SHARED)
add_library(${lib_name} SHARED ${ARG_SOURCES})
add_dependencies(${name} ${lib_name})
endif ()
set(header_dirs_arg "")
foreach (header_dir ${ARG_HEADER_DIRS})
set(header_dirs_arg ${header_dirs_arg} --header-dir \"${header_dir}\")
endforeach (header_dir)
set(headers_arg "")
foreach (header ${ARG_HEADERS})
set(headers_arg ${headers_arg} --header \"${header}\")
endforeach (header)
set(binary_args "")
if (ARG_STATIC)
set(binary_args ${binary_args} --static-binary \"${CMAKE_CURRENT_BINARY_DIR}/lib${lib_name}_s.a\")
endif ()
if (ARG_SHARED)
set(binary_args ${binary_args} --shared-binary \"${CMAKE_CURRENT_BINARY_DIR}/lib${lib_name}.so\")
endif ()
string(ASCII 27 esc)
string(ASCII 10 lf)
string(ASCII 13 cr)
add_custom_command(TARGET ${name}
POST_BUILD
COMMENT "[ -- ] Building framework bundle ${name}.framework"
COMMAND rm -rf ${name}.framework
COMMAND ${BUNDLE_PROGRAM} create-framework
-o ${name}.framework
-i ${ARG_BUNDLE_ID}
${headers_arg}
${header_dirs_arg}
${binary_args}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endfunction (add_framework)
function (framework_compile_options name)
string(TOLOWER ${name} lib_name)
if (TARGET ${lib_name})
target_compile_options(${lib_name} PRIVATE ${ARGN})
endif ()
if (TARGET ${lib_name}_s)
target_compile_options(${lib_name}_s PRIVATE ${ARGN})
endif ()
endfunction (framework_compile_options)
function (framework_link_libraries name)
string(TOLOWER ${name} lib_name)
if (TARGET ${lib_name})
target_link_libraries(${lib_name} ${ARGN})
endif ()
if (TARGET ${lib_name}_s)
target_link_libraries(${lib_name}_s ${ARGN})
endif ()
endfunction (framework_link_libraries)
function (framework_include_directories name)
string(TOLOWER ${name} lib_name)
if (TARGET ${lib_name})
target_include_directories(${lib_name} PRIVATE ${ARGN})
endif ()
if (TARGET ${lib_name}_s)
target_include_directories(${lib_name}_s PRIVATE ${ARGN})
endif ()
endfunction (framework_include_directories)
function (framework_link_frameworks name)
string(TOLOWER ${name} lib_name)
foreach (framework ${ARGN})
if (TARGET ${lib_name})
target_compile_options(${lib_name} PRIVATE -framework ${framework})
endif ()
if (TARGET ${lib_name}_s)
target_compile_options(${lib_name}_s PRIVATE -framework ${framework})
endif ()
endforeach (framework)
endfunction (framework_link_frameworks)
function (framework_add_dependencies name)
string(TOLOWER ${name} lib_name)
if (TARGET ${lib_name})
add_dependencies(${lib_name} ${ARGN})
endif ()
if (TARGET ${lib_name}_s)
add_dependencies(${lib_name}_s ${ARGN})
endif ()
endfunction (framework_add_dependencies)