Handling GitHub repositories for max-sdk c-externals

Connector's icon

Hi there,

i want to prepare my Laptop and GitHub repository for developing c-externals with Max 8.2 SDK, Visual Studio 2022 and CMAKE 3.23.0 for Max 9.0.4. on Windows 10. Therefor i want to clear some points:

I have cloned the max-sdk in my Max 9 Packages Folder like it is described at https://github.com/Cycling74/max-sdk/blob/main/README.md .

For developing my own c-externals i want to copy and rename existing source code from the /max-sdk/source folder as a starting Point for modifying the code for my needs.

After finishing the external I want to push my own c-external Code to my own private GitHub Repository.

But I don't really know how to implement that because the /max-sdk/ Folder is still connected with the https://github.com/Cycling74/max-sdk repository.

  1. What is the best way to push my SourceCode into my own private repository on GitHub?

  2. Should I also commit the project files from the /max-sdk/build/source Folder after building it with CMAKE?

  3. Should I create one GitHub repository for each single external?

Hope you can help me with thesse Questions!

Best Regards

C.

JBG's icon

Hi!

The "Max SDK" github repo isn't really an SDK but an example repo containing a lot of different C-externals, the real SDK can be found here.

For any serious version controlled project, as long as you're somewhat comfortable with CMake, what I would do is create a new repo and set up a folder structure that mimicks that of the Max SDK, copying the relevant portions of the CMakeLists.txt accordingly, e.g.

my_project/
  - help/                   # for your own designed .maxhelp files
  - externals/              # where your compiled .mxe/64-objects will end up
  - source/
      - my_external1/
          - CMakeLists.txt
          - my_external1.c
      - my_external2/
          - CMakeLists.txt 
          - my_external2.c
      - max_sdk_base/       # git submodule https://github.com/Cycling74/max-sdk-base/
  - CMakeLists.txt

Where for my_project/source/my_external1/CMakeLists.txt etc. you can basically copy any CMakeLists.txt for a single external, and for the root my_project/CMakeLists.txt you can just write your own normal CMakeLists (with add_subdirectory(source/my_external1), etc.).

No need for any include, target_link_library or anything of the sort in the root CMakeLists. As long as you follow this exact structure, everything you need is in the first (and last) line of each external's CMakeLists.txt

Connector's icon

Hi JBG!

Thanks for your reply! I have tried to prepare my folder structure and CMakeLists.txt files like you explained in your post:

folder structure for testgit repository

My CMakeLists.txt in the testgit/source/firstexternal is:

include(${CMAKE_CURRENT_SOURCE_DIR}/../max-sdk-base/script/max-pretarget.cmake)

#############################################################
# MAX EXTERNAL
#############################################################

include_directories( 
	"${MAX_SDK_INCLUDES}"
	"${MAX_SDK_MSP_INCLUDES}"
	"${MAX_SDK_JIT_INCLUDES}"
)

file(GLOB PROJECT_SRC
     "*.h"
	 "*.c"
     "*.cpp"
)
add_library( 
	${PROJECT_NAME} 
	MODULE
	${PROJECT_SRC}
)

include(${CMAKE_CURRENT_SOURCE_DIR}/../max-sdk-base/script/max-posttarget.cmake)

And the root CMakeLists.txt in the testgit repository is:

cmake_minimum_required(VERSION 3.23)

string(REGEX REPLACE "(.*)/" "" THIS_FOLDER_NAME "${CMAKE_CURRENT_SOURCE_DIR}")
project(${THIS_FOLDER_NAME})

add_subdirectory(source/firstexternal)

Building the Visual Studio Project Files in the testgit/build folder with:

cd build
cmake -G "Visual Studio 17 2022" ..

is working fine. But then when i build my test external in Visual Studio 2022 a new Folder is created outside the testgit repository folder:

externals are stored in wrong folder level

Where can i define that the location of the externals Folder should be in inside the testgit repository folder?

And another question is: Should I add the testgit/build folder to the .gitignore file or should i also store the content from testgit/build into my testgit repository?

Best Regards

C.

Connector's icon

ok.. i solved this issue with following folder structure where the source code for the external is one directory level deeper than before => testgit/source/cvconnector/firstexternal:

externals folder inside repository folder

CMakeLIsts.txt root:

cmake_minimum_required(VERSION 3.23)

string(REGEX REPLACE "(.*)/" "" THIS_FOLDER_NAME "${CMAKE_CURRENT_SOURCE_DIR}")
project(${THIS_FOLDER_NAME})

add_subdirectory(source/cvconnector/firstexternal)

CMakeLIsts.txt inside external folder:

include(${CMAKE_CURRENT_SOURCE_DIR}/../../max-sdk-base/script/max-pretarget.cmake)

#############################################################
# MAX EXTERNAL
#############################################################

include_directories( 
	"${MAX_SDK_INCLUDES}"
	"${MAX_SDK_MSP_INCLUDES}"
	"${MAX_SDK_JIT_INCLUDES}"
)

file(GLOB PROJECT_SRC
     "*.h"
	 "*.c"
     "*.cpp"
)
add_library( 
	${PROJECT_NAME} 
	MODULE
	${PROJECT_SRC}
)

include(${CMAKE_CURRENT_SOURCE_DIR}/../../max-sdk-base/script/max-posttarget.cmake)

And I have added the build/ folder to the .gitignore file...

JBG's icon

Glad to hear that you got everything up and running!

The externals/ path seems to be defined here, and as you figured out, intended for the max-sdk repo which is one level deeper, i.e. source/<category>/external/. Another approach would be to override the C74_LIBRARY_OUTPUT_DIRECTORY variable, e.g. in root CMakeLists.txt:

set(C74_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/externals")

For the .gitignore, adding build/ is indeed a good approach (you can always use the max sdk gitignore as a reference)!