Skip to content

Commit

Permalink
Merge branch '31-cmake-dependency-chain' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
greenrobot committed Aug 19, 2024
2 parents adcdaff + 1f85b66 commit 8753ad3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
16 changes: 9 additions & 7 deletions cmake/FindObjectBoxGenerator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ One caveat with ``INSOURCE`` is that a cmake clean (cmake --target clean) also d
``OUTPUT_DIR`` specifies the location for auto-generated files in the source tree
(default: current source directory).
If you have multiple schemas (multiple calls to ``add_obx_schema()``), you need to use different ``OUTPUT_DIR``s
to ensure a clear separation of generated files (e.g. avoid overwriting files with the same name).
If you have multiple schemas (multiple calls to ``add_obx_schema()``), you need to use different ``OUTPUT_DIR``
directories to ensure a clear separation of generated files (e.g. avoid overwriting files with the same name).
* For in-source (``INSOURCE``) builds, this affects all generated files.
The given directory can be relative to current source directory or can be given as absolute path.
Expand Down Expand Up @@ -303,8 +303,10 @@ function (add_obx_schema)
if (ARG_INSOURCE)
if (OBX_GEN_OUTPUT_DIR)
set(OBX_GEN_OUTPUT_DIR_SRC ${OBX_GEN_OUTPUT_DIR})
set(OBX_GEN_OUTPUT_DIR_HEADERS ${OBX_GEN_OUTPUT_DIR})
else()
set(OBX_GEN_OUTPUT_DIR_SRC)
set(OBX_GEN_OUTPUT_DIR_HEADERS)
endif()
if (ARG_OUTPUT_DIR_HEADERS)
if(IS_ABSOLUTE ${ARG_OUTPUT_DIR_HEADERS})
Expand All @@ -313,8 +315,6 @@ function (add_obx_schema)
set(OBX_GEN_OUTPUT_DIR_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_OUTPUT_DIR_HEADERS})
endif()
file(MAKE_DIRECTORY ${OBX_GEN_OUTPUT_DIR_HEADERS})
else()
set(OBX_GEN_OUTPUT_DIR_HEADERS)
endif()
else () # out-of-source:
if (ARG_OUTPUT_DIR_HEADERS)
Expand Down Expand Up @@ -353,6 +353,8 @@ function (add_obx_schema)
set(OBX_GEN_OUTPUT_MODEL_H_ONCE "objectbox-model.h")
endif ()

set(prev_cppfile) # previous cppfile used for artificial dependency chain

# Add a custom call to invoke the generator for each provided schema file.
foreach(SCHEMA_FILE ${ARG_SCHEMA_FILES})

Expand Down Expand Up @@ -413,13 +415,13 @@ function (add_obx_schema)
${ARG_EXTRA_OPTIONS}
${schema_filepath}
DEPENDS
${schema_filepath}
USES_TERMINAL # Needed for ninja
${schema_filepath}
${prev_cppfile} # artificial dependency to ensure no parallel execution
)
set(OBX_GEN_OUTPUT_MODEL_H_ONCE "") # Once only; clear after the first custom command.
set(prev_cppfile ${cppfile})
list(APPEND sources ${cppfile} ${hppfile})
endforeach()

target_sources(${ARG_TARGET} PRIVATE ${sources})
if (NOT ARG_INSOURCE)
target_include_directories(${ARG_TARGET} PRIVATE ${OBX_GEN_OUTPUT_DIR_HEADERS})
Expand Down
8 changes: 4 additions & 4 deletions test/cmake/cmake.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ func (cmake *Cmake) BuildWithTarget(target string) ([]byte, []byte, error) {
return cmakeExec(cmake.ConfDir,
"--build", cmake.BuildDir,
"--target", target,
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
"--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
)
}

// Build runs cmake build step.
func (cmake *Cmake) BuildDefaults() ([]byte, []byte, error) {
return cmakeExec(cmake.ConfDir,
"--build", cmake.BuildDir,
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
"--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
)
}

Expand All @@ -213,7 +213,7 @@ func (cmake *Cmake) BuildDefaultsWithConfig(config string) ([]byte, []byte, erro
return cmakeExec(cmake.ConfDir,
"--build", cmake.BuildDir,
"--config", config,
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
"--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
)
}

Expand All @@ -223,7 +223,7 @@ func (cmake *Cmake) BuildTargetWithConfig(config, target string) ([]byte, []byte
"--build", cmake.BuildDir,
"--config", config,
"--target", target,
// "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
"--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
)
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration/cmake/projects/cpp-flat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (DO_INSOURCE)
SCHEMA_FILES
task.fbs
INSOURCE
OUTPUT_DIR_HEADERS
OUTPUT_DIR
schema1
)
add_obx_schema(
Expand All @@ -32,7 +32,7 @@ if (DO_INSOURCE)
SCHEMA_FILES
monster.fbs
INSOURCE
OUTPUT_DIR_HEADERS
OUTPUT_DIR
schema2
)
target_include_directories(objectbox-test PRIVATE schema1 schema2)
Expand Down

0 comments on commit 8753ad3

Please sign in to comment.