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

A few CMake quality of life suggestions #35

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
50 changes: 47 additions & 3 deletions CMakeCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function (SetGlobalCompilerDefinitions acVersion)
else ()
add_definitions (-Dmacintosh=1)
if (${acVersion} GREATER_EQUAL 26)
set (CMAKE_OSX_ARCHITECTURES "x86_64;arm64" PARENT_SCOPE CACHE STRING "" FORCE)
set (CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "" FORCE)
endif ()
endif ()
add_definitions (-DACExtension)
Expand Down Expand Up @@ -101,6 +101,9 @@ endfunction ()

function (GenerateAddOnProject target acVersion devKitDir addOnName addOnSourcesFolder addOnResourcesFolder addOnLanguage)

verify_api_devkit_folder (${devKitDir})
andesyv marked this conversation as resolved.
Show resolved Hide resolved
check_valid_language_code ("${CMAKE_SOURCE_DIR}/config.json" ${addOnLanguage})

find_package (Python COMPONENTS Interpreter)

set (ResourceObjectsDir ${CMAKE_BINARY_DIR}/ResourceObjects)
Expand Down Expand Up @@ -176,8 +179,10 @@ function (GenerateAddOnProject target acVersion devKitDir addOnName addOnSources

set_target_properties (${target} PROPERTIES OUTPUT_NAME ${addOnName})
if (WIN32)
set_target_properties (${target} PROPERTIES SUFFIX ".apx")
set_target_properties (${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_$<CONFIG> "${CMAKE_BINARY_DIR}/$<CONFIG>")
set_target_properties (${target} PROPERTIES
SUFFIX ".apx"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
target_link_options (${target} PUBLIC "${ResourceObjectsDir}/${addOnName}.res")
target_link_options (${target} PUBLIC /export:GetExportedFuncAddrs,@1 /export:SetImportedFuncAddrs,@2)
else ()
Expand Down Expand Up @@ -246,3 +251,42 @@ function (GenerateAddOnProject target acVersion devKitDir addOnName addOnSources
SetCompilerOptions (${target} ${acVersion})

endfunction ()

function (check_valid_language_code configFile languageCode)
file (READ ${configFile} configsContent)
string (JSON configuredLanguagesList GET "${configsContent}" "languages")
string (JSON configuredLanguagesListLen LENGTH "${configsContent}" "languages")
set (i 0)
while (${i} LESS ${configuredLanguagesListLen})
andesyv marked this conversation as resolved.
Show resolved Hide resolved
string (JSON language GET "${configuredLanguagesList}" ${i})
if (${language} STREQUAL ${languageCode})
return ()
endif ()
math (EXPR i "${i} + 1")
endwhile()

message (FATAL_ERROR "Language code ${languageCode} is not part of the configured languages in ${configFile}.")
endfunction ()

function (verify_api_devkit_folder devKitPath)
if (NOT EXISTS ${devKitPath})
message (FATAL_ERROR "The supplied API DevKit path ${devKitPath} does not exist")
endif ()

cmake_path (GET devKitPath FILENAME currentFolderName)
if (NOT "${currentFolderName}" STREQUAL "Support")
andesyv marked this conversation as resolved.
Show resolved Hide resolved
message (FATAL_ERROR "The supplied API DevKit path should point to the /Support subfolder of the API DevKit. Actual path: ${devKitPath}")
endif ()

if (NOT EXISTS "${devKitPath}/Lib")
message (FATAL_ERROR "${devKitPath}/Lib does not exist")
endif ()

if (NOT EXISTS "${devKitPath}/Modules")
message (FATAL_ERROR "${devKitPath}/Modules does not exist")
endif ()

if (APPLE AND NOT EXISTS "${devKitPath}/Frameworks")
message (FATAL_ERROR "${devKitPath}/Frameworks does not exist")
endif ()
endfunction ()