From b20f047e015980329af4131500bce8b72e340737 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 22 May 2016 10:27:19 +0200 Subject: cmake: rename macros -> boilerplate --- cmake/opentrack-boilerplate.cmake | 102 ++++++++++++++++++++++++++++++++++++++ cmake/opentrack-macros.cmake | 102 -------------------------------------- 2 files changed, 102 insertions(+), 102 deletions(-) create mode 100644 cmake/opentrack-boilerplate.cmake delete mode 100644 cmake/opentrack-macros.cmake (limited to 'cmake') diff --git a/cmake/opentrack-boilerplate.cmake b/cmake/opentrack-boilerplate.cmake new file mode 100644 index 00000000..71c166f2 --- /dev/null +++ b/cmake/opentrack-boilerplate.cmake @@ -0,0 +1,102 @@ +function(opentrack_set_globs n) + set(dir ${PROJECT_SOURCE_DIR}) + file(GLOB ${n}-c ${dir}/*.cpp ${dir}/*.c ${dir}/*.h ${dir}/*.hpp) + file(GLOB ${n}-res ${dir}/*.rc) + foreach(f ${n}-res) + set_source_files_properties(${f} PROPERTIES LANGUAGE RC) + endforeach() + file(GLOB ${n}-ui ${dir}/*.ui) + file(GLOB ${n}-rc ${dir}/*.qrc) + foreach(i c res ui rc) + set(${n}-${i} ${${n}-${i}} PARENT_SCOPE) + endforeach() +endfunction() + +function(opentrack_qt n) + qt5_wrap_cpp(${n}-moc ${${n}-c} OPTIONS --no-notes) + QT5_WRAP_UI(${n}-uih ${${n}-ui}) + QT5_ADD_RESOURCES(${n}-rcc ${${n}-rc}) + set(${n}-all ${${n}-c} ${${n}-rc} ${${n}-rcc} ${${n}-uih} ${${n}-moc} ${${n}-res}) + foreach(i moc uih rcc all) + set(${n}-${i} ${${n}-${i}} PARENT_SCOPE) + endforeach() +endfunction() + +function(opentrack_compat target) + if(MSVC) + set(msvc-subsystem "/VERSION:5.1 /SUBSYSTEM:WINDOWS,5.01") + set_target_properties(${target} PROPERTIES LINK_FLAGS "${msvc-subsystem} /DEBUG /OPT:ICF") + endif() + if(NOT MSVC) + set_property(SOURCE ${${target}-moc} APPEND_STRING PROPERTY COMPILE_FLAGS "-w -Wno-error") + endif() + if(WIN32) + target_link_libraries(${target} dinput8 dxguid strmiids) + endif() +endfunction() + +function(opentrack_boilerplate__ n files_ no-library_ static_ no-compat_ compile_ link_) + set(link-mode SHARED) + if (static_) + set(link-mode STATIC) + endif() + add_library(${n} ${link-mode} ${files_}) + opentrack_compat(${n}) + set(link-mode) + if(NOT no-compat_) + target_link_libraries(${n} opentrack-api opentrack-compat) + endif() + target_link_libraries(${n} ${MY_QT_LIBS}) + set(c-props) + set(l-props) + if(CMAKE_COMPILER_IS_GNUCXX) + set(c-props "-fvisibility=hidden -fuse-cxa-atexit") + endif() + if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE) + set(l-props "-Wl,--as-needed") + endif() + if(MSVC) + set(l-props "${msvc-subsystem} /DEBUG /OPT:ICF") + endif() + get_target_property(orig-compile ${n} COMPILE_FLAGS) + if(NOT orig-compile) + set(orig-compile "") + endif() + get_target_property(orig-link ${n} LINK_FLAGS) + if(NOT orig-link) + set(orig-link "") + endif() + set_target_properties(${n} PROPERTIES + COMPILE_FLAGS "${c-props} ${orig-compile} ${compile_}" + LINK_FLAGS "${l-props} ${orig-link} ${link_}" + ) + string(REGEX REPLACE "^opentrack-" "" n_ ${n}) + string(REPLACE "-" "_" n_ ${n_}) + target_compile_definitions(${n} PRIVATE "BUILD_${n_}") + if(NOT static_) + install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .) + endif() +endfunction() + +macro(opentrack_boilerplate n) + cmake_parse_arguments(${n}-args + "NO-LIBRARY;STATIC;NO-COMPAT" + "LINK;COMPILE" + "" + ${ARGN} + ) + if(NOT "${${n}-args_UNPARSED_ARGUMENTS}" STREQUAL "") + message(FATAL_ERROR "opentrack_boilerplate bad formals ${${n}-args_UNPARSED_ARGUMENTS}") + endif() + project(${n}) + opentrack_set_globs(${n}) + opentrack_qt(${n}) + if(NOT ${n}-args_NO-LIBRARY) + opentrack_boilerplate__("${n}" "${${n}-all}" + "${${n}-args_NO-LIBRARY}" + "${${n}-args_STATIC}" + "${${n}-args_NO-COMPAT}" + "${${n}-args_COMPILE}" + "${${n}-args_LINK}") + endif() +endmacro() diff --git a/cmake/opentrack-macros.cmake b/cmake/opentrack-macros.cmake deleted file mode 100644 index 71c166f2..00000000 --- a/cmake/opentrack-macros.cmake +++ /dev/null @@ -1,102 +0,0 @@ -function(opentrack_set_globs n) - set(dir ${PROJECT_SOURCE_DIR}) - file(GLOB ${n}-c ${dir}/*.cpp ${dir}/*.c ${dir}/*.h ${dir}/*.hpp) - file(GLOB ${n}-res ${dir}/*.rc) - foreach(f ${n}-res) - set_source_files_properties(${f} PROPERTIES LANGUAGE RC) - endforeach() - file(GLOB ${n}-ui ${dir}/*.ui) - file(GLOB ${n}-rc ${dir}/*.qrc) - foreach(i c res ui rc) - set(${n}-${i} ${${n}-${i}} PARENT_SCOPE) - endforeach() -endfunction() - -function(opentrack_qt n) - qt5_wrap_cpp(${n}-moc ${${n}-c} OPTIONS --no-notes) - QT5_WRAP_UI(${n}-uih ${${n}-ui}) - QT5_ADD_RESOURCES(${n}-rcc ${${n}-rc}) - set(${n}-all ${${n}-c} ${${n}-rc} ${${n}-rcc} ${${n}-uih} ${${n}-moc} ${${n}-res}) - foreach(i moc uih rcc all) - set(${n}-${i} ${${n}-${i}} PARENT_SCOPE) - endforeach() -endfunction() - -function(opentrack_compat target) - if(MSVC) - set(msvc-subsystem "/VERSION:5.1 /SUBSYSTEM:WINDOWS,5.01") - set_target_properties(${target} PROPERTIES LINK_FLAGS "${msvc-subsystem} /DEBUG /OPT:ICF") - endif() - if(NOT MSVC) - set_property(SOURCE ${${target}-moc} APPEND_STRING PROPERTY COMPILE_FLAGS "-w -Wno-error") - endif() - if(WIN32) - target_link_libraries(${target} dinput8 dxguid strmiids) - endif() -endfunction() - -function(opentrack_boilerplate__ n files_ no-library_ static_ no-compat_ compile_ link_) - set(link-mode SHARED) - if (static_) - set(link-mode STATIC) - endif() - add_library(${n} ${link-mode} ${files_}) - opentrack_compat(${n}) - set(link-mode) - if(NOT no-compat_) - target_link_libraries(${n} opentrack-api opentrack-compat) - endif() - target_link_libraries(${n} ${MY_QT_LIBS}) - set(c-props) - set(l-props) - if(CMAKE_COMPILER_IS_GNUCXX) - set(c-props "-fvisibility=hidden -fuse-cxa-atexit") - endif() - if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE) - set(l-props "-Wl,--as-needed") - endif() - if(MSVC) - set(l-props "${msvc-subsystem} /DEBUG /OPT:ICF") - endif() - get_target_property(orig-compile ${n} COMPILE_FLAGS) - if(NOT orig-compile) - set(orig-compile "") - endif() - get_target_property(orig-link ${n} LINK_FLAGS) - if(NOT orig-link) - set(orig-link "") - endif() - set_target_properties(${n} PROPERTIES - COMPILE_FLAGS "${c-props} ${orig-compile} ${compile_}" - LINK_FLAGS "${l-props} ${orig-link} ${link_}" - ) - string(REGEX REPLACE "^opentrack-" "" n_ ${n}) - string(REPLACE "-" "_" n_ ${n_}) - target_compile_definitions(${n} PRIVATE "BUILD_${n_}") - if(NOT static_) - install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .) - endif() -endfunction() - -macro(opentrack_boilerplate n) - cmake_parse_arguments(${n}-args - "NO-LIBRARY;STATIC;NO-COMPAT" - "LINK;COMPILE" - "" - ${ARGN} - ) - if(NOT "${${n}-args_UNPARSED_ARGUMENTS}" STREQUAL "") - message(FATAL_ERROR "opentrack_boilerplate bad formals ${${n}-args_UNPARSED_ARGUMENTS}") - endif() - project(${n}) - opentrack_set_globs(${n}) - opentrack_qt(${n}) - if(NOT ${n}-args_NO-LIBRARY) - opentrack_boilerplate__("${n}" "${${n}-all}" - "${${n}-args_NO-LIBRARY}" - "${${n}-args_STATIC}" - "${${n}-args_NO-COMPAT}" - "${${n}-args_COMPILE}" - "${${n}-args_LINK}") - endif() -endmacro() -- cgit v1.2.3