summaryrefslogtreecommitdiffhomepage
path: root/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake')
-rw-r--r--cmake/opentrack-macros.cmake131
-rw-r--r--cmake/opentrack-rift.cmake33
2 files changed, 88 insertions, 76 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()
diff --git a/cmake/opentrack-rift.cmake b/cmake/opentrack-rift.cmake
index 86396637..d5b557ea 100644
--- a/cmake/opentrack-rift.cmake
+++ b/cmake/opentrack-rift.cmake
@@ -1,5 +1,5 @@
-macro(opentrack_rift_boilerplate proj opt)
- if(${opt})
+function(opentrack_rift_boilerplate proj opt)
+ if(opt)
set(link-flags)
set(c-flags)
if(APPLE)
@@ -7,31 +7,30 @@ macro(opentrack_rift_boilerplate proj opt)
set(c-flags "-fno-strict-aliasing")
else()
if(NOT MSVC)
- set(c-flags "-fno-strict-aliasing")
+ set(c-flags "-fno-strict-aliasing")
endif()
endif()
- opentrack_boilerplate("${proj}" LINK ${link-flags} COMPILE ${c-flags})
- set(proj ${opentrack-project-name})
+ opentrack_boilerplate(${proj} LINK ${link-flags} COMPILE ${c-flags})
+ set(proj ${proj})
target_include_directories(${proj} SYSTEM PUBLIC ${${opt}}/Include ${${opt}}/Src)
set(c-flags)
set(link-flags)
+ if(MSVC)
+ set(ext lib)
+ set(p)
+ else()
+ set(ext a)
+ set(p lib)
+ endif()
+ target_link_libraries(${proj} ${${opt}}/libLibOVR.${ext})
if(WIN32)
- if(MSVC)
- set(ext lib)
- set(p)
- else()
- set(ext a)
- set(p lib)
- endif()
- target_link_libraries(${proj} ${${opt}}/${p}LibOVR.${ext} winmm setupapi ws2_32 imagehlp wbemuuid)
+ target_link_libraries(${proj} winmm setupapi ws2_32 imagehlp wbemuuid)
set(ext)
set(p)
else()
if(NOT APPLE)
- target_link_libraries(${proj} ${${opt}}/libLibOVR.a udev Xinerama)
- else()
- target_link_libraries(${proj} ${${opt}}/libLibOVR.a)
+ target_link_libraries(${proj} udev Xinerama)
endif()
endif()
endif()
-endmacro()
+endfunction()