Browse Source

fix: avoid rebuilding after cmake

tags/20181228
Abdel Younes nihui 7 years ago
parent
commit
b48ec83e36
4 changed files with 26 additions and 10 deletions
  1. +11
    -10
      src/CMakeLists.txt
  2. +5
    -0
      src/layer_declaration.h.in
  3. +5
    -0
      src/layer_registry.h.in
  4. +5
    -0
      src/layer_type_enum.h.in

+ 11
- 10
src/CMakeLists.txt View File

@@ -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
@@ -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)


+ 5
- 0
src/layer_declaration.h.in View File

@@ -0,0 +1,5 @@
// Layer Declaration header
//
// This file is auto-generated by cmake, don't edit it.

@layer_declaration@

+ 5
- 0
src/layer_registry.h.in View File

@@ -0,0 +1,5 @@
// Layer Registry header
//
// This file is auto-generated by cmake, don't edit it.

@layer_registry@

+ 5
- 0
src/layer_type_enum.h.in View File

@@ -0,0 +1,5 @@
// Layer Type Enum header
//
// This file is auto-generated by cmake, don't edit it.

@layer_type_enum@

Loading…
Cancel
Save