Cycling74 / min-devkit

Tools, documentation, and reference implementation of a Max Package built using the Min-API.
MIT License
158 stars 31 forks source link

CMAKE rebuild triggered if Git commit is more recent than Cmake timestamp #105

Open DanBennettDev opened 6 years ago

DanBennettDev commented 6 years ago

On building an individual project in VS2017 I get this periodically, which triggers a CMake rebuild and overwrites my include and linker settings.

1>CMake is re-running because C:/Users/dan/Documents/Max 7/Packages/cpg/build/CMakeFiles/generate.stamp is out-of-date.
1>  the file 'C:/Users/dan/Documents/Max 7/Packages/cpg/.git/refs/heads/master'
1>  is newer than 'C:/Users/dan/Documents/Max 7/Packages/cpg/build/CMakeFiles/generate.stamp.depend'
1>  result='-1'
tap commented 6 years ago

Hi @DanBennettDev

Include and Linker settings should be done in the CMakeLists.txt file for your project rather than manually in the IDE. If you need help with figuring out what to do in there, let me know.

I should include some guidance on this in the documentation as well, though I haven't worked out exactly where/how.

DanBennettDev commented 6 years ago

Ok, thanks.

After a bit of fun I seem to have it working -

CMakeLists.txt in the top level solution file - I added this line to the end

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/source/MatsuokaEngine_src)

CMakeLists.txt in the static library directory

cmake_minimum_required(VERSION 3.0)

project(MatsuokaEngine)

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} MAT_SOURCES)

add_library(MatsuokaEngine STATIC ${MAT_SOURCES})

set(
    CMAKE_LIBRARY_OUTPUT_DIRECTORY
    ../../build/x64/Release
)

CMakeLists.txt in the project for the external that calls the static lib - as per normal min cmakelists file, but with these added:

include_directories( 
    "${C74_INCLUDES}"
    # ADDED BY ME
    "../../MatsuokaEngine_src" 
)

# ADDED BY ME
target_link_libraries(${PROJECT_NAME} MatsuokaEngine)

Is that close enough to what I ought to do that I haven't stored up pain anywhere? And I'm not sure on how to set up debug and release versions of the library (and use the relevant lib files in the debug and release versions of the external)

tap commented 6 years ago

This looks perfectly legit on first glance! Glad you got it worked out!

Regarding different configurations for debug vs release, here is a snippet of a CMakeLists.txt for an object I'm working on right now:

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_definitions(
        -DDEBUG
    )
else ()
    add_definitions(
        -DNDEBUG
    )
endif ()

Both this snippet and the pattern you describe for adding the static lib to the top level are material that I would like to add to the wiki.

DanBennettDev commented 6 years ago

Excellent, cheers - v useful :)

DanBennettDev commented 6 years ago

Addendum to this in case anyone else is trying to do something similar: I also needed to amend the unit test section at the end of the project cmake file


#############################################################
# UNIT TEST
#############################################################

include(${C74_MIN_API_DIR}/test/min-object-unittest.cmake)

# ADDED BY ME:
target_link_libraries(${PROJECT_NAME} MatsuokaEngine)
tap commented 6 years ago

excellent point!