summaryrefslogtreecommitdiffhomepage
path: root/cmake/opentrack-macros.cmake
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-05-22 10:26:31 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-05-22 10:26:31 +0200
commit73620251fb9af400fecc4af2de32b6b6ccc770ac (patch)
tree8913a092dec51eacd0497c925f1999f6258584ed /cmake/opentrack-macros.cmake
parent57b069b70c85a61cfd42fe2a2184bd1fc8346938 (diff)
cmake: simplify, avoid macros
Avoid macros when able to allow for scope control. Macros shove everything inside the parent scope. The lone remaining macro needs to be there since functions allow for a fixed amount of parameters. Link against dinput automatically since LTO will remove it if it's not needed anyway. Rift trackers don't presently need access to ${project}-all etc. so don't expose them through opentrack_rift_boilerplate yet.
Diffstat (limited to 'cmake/opentrack-macros.cmake')
-rw-r--r--cmake/opentrack-macros.cmake131
1 files changed, 72 insertions, 59 deletions
diff --git a/cmake/opentrack-macros.cmake b/cmake/opentrack-macros.cmake
index 988ab9af..71c166f2 100644
--- a/cmake/opentrack-macros.cmake
+++ b/cmake/opentrack-macros.cmake
@@ -1,4 +1,5 @@
-macro(opentrack_module n dir)
+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)
@@ -6,84 +7,96 @@ macro(opentrack_module n dir)
endforeach()
file(GLOB ${n}-ui ${dir}/*.ui)
file(GLOB ${n}-rc ${dir}/*.qrc)
-endmacro()
-
-macro(opentrack_boilerplate opentrack-project-name)
- set(extra_macro_args ${ARGN})
- set(spliced ${extra_macro_args})
- project(${opentrack-project-name})
- opentrack_library(${opentrack-project-name} ${PROJECT_SOURCE_DIR} ${spliced})
- set(spliced)
-endmacro()
+ foreach(i c res ui rc)
+ set(${n}-${i} ${${n}-${i}} PARENT_SCOPE)
+ endforeach()
+endfunction()
-macro(opentrack_qt n)
+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})
-endmacro()
+ foreach(i moc uih rcc all)
+ set(${n}-${i} ${${n}-${i}} PARENT_SCOPE)
+ endforeach()
+endfunction()
-set(msvc-subsystem "/VERSION:5.1 /SUBSYSTEM:WINDOWS,5.01")
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_library n dir)
- cmake_parse_arguments(opentrack-foolib
+macro(opentrack_boilerplate n)
+ cmake_parse_arguments(${n}-args
"NO-LIBRARY;STATIC;NO-COMPAT"
- "LINK;COMPILE;GNU-LINK;GNU-COMPILE"
+ "LINK;COMPILE"
""
${ARGN}
)
- if(NOT " ${opentrack-foolib_UNPARSED_ARGUMENTS}" STREQUAL " ")
- message(FATAL_ERROR "opentrack_library bad formals ${opentrack-foolib_UNPARSED_ARGUMENTS}")
+ if(NOT "${${n}-args_UNPARSED_ARGUMENTS}" STREQUAL "")
+ message(FATAL_ERROR "opentrack_boilerplate bad formals ${${n}-args_UNPARSED_ARGUMENTS}")
endif()
- opentrack_module(${n} ${dir})
+ project(${n})
+ opentrack_set_globs(${n})
opentrack_qt(${n})
- set(link-mode SHARED)
- if(NOT opentrack-foolib_NO-LIBRARY)
- if (opentrack-foolib_STATIC)
- set(link-mode STATIC)
- endif()
- add_library(${n} ${link-mode} ${${n}-all})
- set(link-mode)
- if(NOT opentrack-foolib_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 ${opentrack-foolib_GNU-COMPILE}")
- endif()
- if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE)
- set(l-props "${opentrack-foolib_GNU-LINK} -Wl,--as-needed")
- else()
- if(MSVC)
- set(l-props "${msvc-subsystem} /DEBUG /OPT:ICF")
- endif()
- endif()
- set_target_properties(${n} PROPERTIES
- LINK_FLAGS "${l-props} ${opentrack-foolib_LINK}"
- COMPILE_FLAGS "${c-props} ${opentrack-foolib_COMPILE}"
- )
- string(REGEX REPLACE "^opentrack-" "" n_ ${n})
- string(REPLACE "-" "_" n_ ${n_})
- target_compile_definitions(${n} PRIVATE "BUILD_${n_}")
- if(NOT opentrack-foolib_STATIC)
- install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .)
- endif()
- opentrack_compat(${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()
-
-function(link_with_dinput8 n)
- if(WIN32)
- target_link_libraries(${n} dinput8 dxguid strmiids)
- endif()
-endfunction()