Skip to content

Commit

Permalink
Fixed cmake build
Browse files Browse the repository at this point in the history
  • Loading branch information
ondys committed Apr 18, 2018
1 parent 4b2788b commit 02272a6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 33 deletions.
38 changes: 5 additions & 33 deletions cmake/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ macro (add_c_flag_if_supported c_flag)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${c_flag}" CACHE STRING "")
else ()
set(DRACO_FAILED_C_FLAGS "${DRACO_FAILED_C_FLAGS} ${c_flag}" CACHE STRING
"")
"" FORCE)
endif ()
endif ()
endmacro ()
Expand All @@ -48,7 +48,7 @@ macro (add_cxx_flag_if_supported cxx_flag)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${cxx_flag}" CACHE STRING "")
else()
set(DRACO_FAILED_CXX_FLAGS "${DRACO_FAILED_CXX_FLAGS} ${cxx_flag}" CACHE
STRING "")
STRING "" FORCE)
endif ()
endif ()
endmacro ()
Expand All @@ -75,7 +75,7 @@ macro (require_c_flag c_flag update_c_flags)
"${PROJECT_NAME} requires support for C flag: ${c_flag}.")
endif ()
if (${update_c_flags})
set(CMAKE_C_FLAGS "${c_flag} ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "${c_flag} ${CMAKE_C_FLAGS}" CACHE STRING "" FORCE)
endif ()
endif ()
endmacro ()
Expand All @@ -95,7 +95,8 @@ macro (require_cxx_flag cxx_flag update_cxx_flags)
"${PROJECT_NAME} requires support for CXX flag: ${cxx_flag}.")
endif ()
if (${update_cxx_flags})
set(CMAKE_CXX_FLAGS "${cxx_flag} ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${cxx_flag} ${CMAKE_CXX_FLAGS}" CACHE STRING ""
FORCE)
endif ()
endif ()
endmacro ()
Expand Down Expand Up @@ -131,35 +132,6 @@ macro (require_compiler_flag_nomsvc flag update_cmake_flags)
require_cxx_flag_nomsvc(${flag} ${update_cmake_flags})
endmacro ()

# Adds $preproc_def to C compiler command line (as -D$preproc_def) if not
# already present.
macro (add_c_preproc_definition preproc_def)
unset(PREPROC_DEF_FOUND CACHE)
string(FIND "${CMAKE_C_FLAGS}" "${preproc_def}" PREPROC_DEF_FOUND)

if (${PREPROC_DEF_FOUND} EQUAL -1)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D${preproc_def}")
endif ()
endmacro ()

# Adds $preproc_def to CXX compiler command line (as -D$preproc_def) if not
# already present.
macro (add_cxx_preproc_definition preproc_def)
unset(PREPROC_DEF_FOUND CACHE)
string(FIND "${CMAKE_CXX_FLAGS}" "${preproc_def}" PREPROC_DEF_FOUND)

if (${PREPROC_DEF_FOUND} EQUAL -1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${preproc_def}")
endif ()
endmacro ()

# Adds $preproc_def to C and CXX compiler command line (as -D$preproc_def) if
# not already present.
macro (add_preproc_definition preproc_def)
add_c_preproc_definition(${preproc_def})
add_cxx_preproc_definition(${preproc_def})
endmacro ()

# Adds $flag to assembler command line.
macro (append_as_flag flag)
unset(AS_FLAG_FOUND CACHE)
Expand Down
57 changes: 57 additions & 0 deletions cmake/draco_features.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
if (NOT DRACO_CMAKE_DRACO_FEATURES_CMAKE_)
set(DRACO_CMAKE_DRACO_FEATURES_CMAKE_ 1)

set(draco_features_file_name "${draco_build_dir}/draco/draco_features.h")
set(draco_features_list)

# Macro that handles tracking of Draco preprocessor symbols for the purpose of
# producing draco_features.h.
#
# draco_enable_feature(FEATURE <feature_name> [TARGETS <target_name>])
# FEATURE is required. It should be a Draco preprocessor symbol.
# TARGETS is optional. It can be one or more draco targets.
#
# When the TARGETS argument is not present the preproc symbol is added to
# draco_features.h. When it is draco_features.h is unchanged, and
# target_compile_options() is called for each target specified.
macro (draco_enable_feature)
set(def_flags)
set(def_single_arg_opts FEATURE)
set(def_multi_arg_opts TARGETS)
cmake_parse_arguments(DEF "${def_flags}" "${def_single_arg_opts}"
"${def_multi_arg_opts}" ${ARGN})
if ("${DEF_FEATURE}" STREQUAL "")
message(FATAL_ERROR "Empty FEATURE passed to draco_enable_feature().")
endif ()

# Do nothing/return early if $DEF_FEATURE is already in the list.
list(FIND draco_features_list ${DEF_FEATURE} df_index)
if (NOT df_index EQUAL -1)
return ()
endif ()

list(LENGTH DEF_TARGETS df_targets_list_length)
if (${df_targets_list_length} EQUAL 0)
list(APPEND draco_features_list ${DEF_FEATURE})
else ()
foreach (target ${DEF_TARGETS})
target_compile_definitions(${target} PRIVATE ${DEF_FEATURE})
endforeach ()
endif ()
endmacro ()

# Function for generating draco_features.h.
function (draco_generate_features_h)
file(WRITE "${draco_features_file_name}"
"// GENERATED FILE -- DO NOT EDIT\n\n"
"#ifndef DRACO_FEATURES_H_\n"
"#define DRACO_FEATURES_H_\n\n")

foreach (feature ${draco_features_list})
file(APPEND "${draco_features_file_name}" "#define ${feature}\n")
endforeach ()

file(APPEND "${draco_features_file_name}" "\n#endif // DRACO_FEATURES_H_")
endfunction ()

endif () # DRACO_CMAKE_DRACO_FEATURES_CMAKE_

0 comments on commit 02272a6

Please sign in to comment.