Skip to content

Commit

Permalink
fix: avoid rebuilding after cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
ayounes-nviso authored and nihui committed Dec 4, 2018
1 parent 65be036 commit b48ec83
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,25 @@ macro(ncnn_add_layer class)
# generate layer_declaration and layer_registry file
if(WITH_LAYER_${name})
if(WITH_LAYER_${name}_${arch})
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_declaration.h
string(APPEND layer_declaration
"extern Layer* ${class}_${arch}_layer_creator();\n")
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_registry.h
string(APPEND layer_registry
"#if NCNN_STRING\n{\"${class}\",${class}_${arch}_layer_creator},\n#else\n{${class}_${arch}_layer_creator},\n#endif\n")
else()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_declaration.h
string(APPEND layer_declaration
"extern Layer* ${class}_layer_creator();\n")
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_registry.h
string(APPEND layer_registry
"#if NCNN_STRING\n{\"${class}\",${class}_layer_creator},\n#else\n{${class}_layer_creator},\n#endif\n")
endif()
else()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_registry.h "#if NCNN_STRING\n{\"${class}\",0},\n#else\n{0},\n#endif\n")
string(APPEND layer_registry "#if NCNN_STRING\n{\"${class}\",0},\n#else\n{0},\n#endif\n")
endif()

# generate layer_type_enum file
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_type_enum.h "${class} = ${__LAYER_TYPE_ENUM_INDEX},\n")
string(APPEND layer_type_enum "${class} = ${__LAYER_TYPE_ENUM_INDEX},\n")
math(EXPR __LAYER_TYPE_ENUM_INDEX "${__LAYER_TYPE_ENUM_INDEX}+1")
endmacro()

# create new
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/layer_declaration.h)
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/layer_registry.h)
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/layer_type_enum.h)
set(__LAYER_TYPE_ENUM_INDEX 0)

# layer implementation
Expand Down Expand Up @@ -148,6 +144,11 @@ ncnn_add_layer(Yolov3DetectionOutput)
ncnn_add_layer(PSROIPooling)
ncnn_add_layer(ROIAlign OFF)

# create new
configure_file(layer_declaration.h.in ${CMAKE_CURRENT_BINARY_DIR}/layer_declaration.h)
configure_file(layer_registry.h.in ${CMAKE_CURRENT_BINARY_DIR}/layer_registry.h)
configure_file(layer_type_enum.h.in ${CMAKE_CURRENT_BINARY_DIR}/layer_type_enum.h)

add_library(ncnn STATIC ${ncnn_SRCS})

if(NCNN_OPENMP AND OpenMP_CXX_FOUND)
Expand Down
5 changes: 5 additions & 0 deletions src/layer_declaration.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Layer Declaration header
//
// This file is auto-generated by cmake, don't edit it.

@layer_declaration@
5 changes: 5 additions & 0 deletions src/layer_registry.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Layer Registry header
//
// This file is auto-generated by cmake, don't edit it.

@layer_registry@
5 changes: 5 additions & 0 deletions src/layer_type_enum.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Layer Type Enum header
//
// This file is auto-generated by cmake, don't edit it.

@layer_type_enum@

0 comments on commit b48ec83

Please sign in to comment.