Build a framework on the Mac

I’m trying to set up a CMakeLists.txt to build a Mac framework. I’m running into issues where any headers that include <framework/something.h> in angle brackets (because the include itself is in a public header) are not finding the file. For example:

@atlantis build % make
[  1%] Building C object CMakeFiles/Azoth.dir/Azoth/Classes/Application/AZAppDelegate.m.o
[  2%] Building C object CMakeFiles/Azoth.dir/Azoth/Classes/Application/AZApplication.m.o
In file included from ~/src/Azoth/Classes/Application/AZApplication.m:12:
~/src/Azoth/Classes/Application/AZApplication.h:9:9: fatal error: 'Azoth/AZTypes.h' file not found
    9 | #import <Azoth/AZTypes.h>
      |         ^~~~~~~~~~~~~~~~~

I can understand that there’s a chicken-and-egg situation where it’s hard to include the headers from the framework you’re still building… So I thought I’d fake it :slight_smile: … If I create a directory called ‘Azoth/’ inside the build/ directory, and copy all the headers into it, then with suitable include flags that’d be “as if” the framework was already extant.

Except I can’t get cmake to make my directory and copy the headers from the source before the build. I’ve tried:

cmake_minimum_required(VERSION 3.10)

project(Azoth)

set (AZOTH_HEADER_DIR ${PROJECT_BINARY_DIR}/Azoth)
set (MODULE_HEADER ${AZOTH_HEADER_DIR}/Azoth.h)

file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "Azoth/*.m")
file(GLOB_RECURSE HEADERS RELATIVE ${CMAKE_SOURCE_DIR} "Azoth/*.h")

add_executable(Azoth 
		${MODULE_HEADER}
		${SOURCES}
		)

add_custom_command(
	OUTPUT 				${AZOTH_HEADER_DIR}
    COMMAND 			make_directory(${AZOTH_HEADER_DIR})
    WORKING_DIRECTORY   ${PROJECT_BINARY_DIR}
)

add_custom_command(
    OUTPUT ${MODULE_HEADER}
    COMMAND ${CMAKE_COMMAND} -E copy ${HEADERS} ${AZOTH_HEADER_DIR}
    WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
    DEPENDS ${AZOTH_HEADER_DIR}
)

target_include_directories(Azoth PUBLIC
		"${CMAKE_SOURCE_DIR}/Classes"
		"${CMAKE_SOURCE_DIR}/Classes/Utility"

		)

set_target_properties(Azoth PROPERTIES LINK_FLAGS "-Wl,-F/opt/SDL3")

target_link_libraries(Azoth PUBLIC -framework /opt/SDL3/SDL3.xcframework)
target_link_libraries(Azoth PUBLIC -framework /opt/SDL3/SDL3_image.xcframework)
target_link_libraries(Azoth PUBLIC -framework /opt/SDL3/SDL3_ttf.xcframework)

… where my thinking is to create the directory with one custom_command and copy the files in with the other, but neither of them are running. I was hoping the dependency-tree for $MODULE_HEADER would make this happen in the right order.

I also tried setting the mkdir command as a PRE_BUILD task:

add_custom_command(
	TARGET 				Azoth PRE_BUILD
    COMMAND 			make_directory(${AZOTH_HEADER_DIR})
    WORKING_DIRECTORY   ${PROJECT_BINARY_DIR}
)

… but I had to drop the OUTPUT (can’t have both, apparently) so I wasn’t sure if there would be a way to know the mkdir was running ahead of the copy. Didn’t matter, neither ran :frowning:

Presumably I’m missing something (or a lot of things [grin]). If there’s a better way to get around the include chicken/egg problem, I’m all ears, otherwise if some kind soul could point out what I’m doing wrong above, I’d really appreciate it :slight_smile: