summaryrefslogtreecommitdiffhomepage
path: root/cmake/opentrack-boilerplate.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/opentrack-boilerplate.cmake')
-rw-r--r--cmake/opentrack-boilerplate.cmake364
1 files changed, 221 insertions, 143 deletions
diff --git a/cmake/opentrack-boilerplate.cmake b/cmake/opentrack-boilerplate.cmake
index 11e5c71d..e325cd6a 100644
--- a/cmake/opentrack-boilerplate.cmake
+++ b/cmake/opentrack-boilerplate.cmake
@@ -1,160 +1,187 @@
-set(opentrack-perms PERMISSIONS WORLD_READ WORLD_EXECUTE OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
+include_guard(GLOBAL)
-set(new-hier-path "#pragma once
-#ifndef OPENTRACK_NO_QT_PATH
+set(opentrack-perms-file WORLD_READ OWNER_WRITE OWNER_READ GROUP_READ)
+set(opentrack-perms-dir WORLD_READ WORLD_EXECUTE OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
+set(opentrack-perms-exec "${opentrack-perms-dir}")
-# include <QCoreApplication>
-# include <QString>
+set(new-hier-path "#pragma once
+#ifdef QT_CORE_LIB
+# include \"compat/base-path.hpp\"
+#endif
-# define OPENTRACK_BASE_PATH (([]() -> const QString& { \\
- const static QString const__path___ = QCoreApplication::applicationDirPath(); \\
- return const__path___; \\
- })())
+#if defined __APPLE__
+# define OPENTRACK_LIBRARY_EXTENSION \"dylib\"
+#elif defined _WIN32
+# define OPENTRACK_LIBRARY_EXTENSION \"dll\"
+#else
+# define OPENTRACK_LIBRARY_EXTENSION \"so\"
#endif
-#define OPENTRACK_LIBRARY_PATH \"${opentrack-hier-path}\"
-#define OPENTRACK_DOC_PATH \"${opentrack-hier-doc}\"
-#define OPENTRACK_CONTRIB_PATH \"${opentrack-hier-doc}contrib/\"
-#define OPENTRACK_I18N_PATH \"${opentrack-i18n-path}\"
+
+#define OPENTRACK_LIBRARY_PREFIX \"\"
+#define OPENTRACK_LIBRARY_PATH \"${opentrack-runtime-libexec}\"
+#define OPENTRACK_DOC_PATH \"${opentrack-runtime-doc}\"
+#define OPENTRACK_CONTRIB_PATH \"${opentrack-runtime-doc}contrib/\"
+#define OPENTRACK_I18N_PATH \"${opentrack-runtime-i18n}\"
")
-set(hier-path-filename "${CMAKE_BINARY_DIR}/opentrack-library-path.h")
-set(orig-hier-path "")
-if(EXISTS "${hier-path-filename}")
- file(READ ${hier-path-filename} orig-hier-path)
-endif()
-if(NOT (orig-hier-path STREQUAL new-hier-path))
- file(WRITE "${hier-path-filename}" "${new-hier-path}")
-endif()
+function(otr_write_library_paths)
+ set(hier-path-filename "${CMAKE_BINARY_DIR}/opentrack-library-path.hxx")
+ set(orig-hier-path "")
+ if(EXISTS "${hier-path-filename}")
+ file(READ ${hier-path-filename} orig-hier-path)
+ endif()
+ if(NOT (orig-hier-path STREQUAL new-hier-path))
+ file(WRITE "${hier-path-filename}" "${new-hier-path}")
+ endif()
+endfunction()
+
+otr_write_library_paths()
function(otr_glob_sources var)
- set(dir "${CMAKE_CURRENT_SOURCE_DIR}")
- file(GLOB ${var}-cc ${dir}/*.cpp ${dir}/*.c)
- file(GLOB ${var}-hh ${dir}/*.h ${dir}/*.hpp)
- file(GLOB ${var}-res ${dir}/*.rc)
- foreach(f ${var}-res)
- set_source_files_properties(${f} PROPERTIES LANGUAGE RC)
+ set(basedir "${CMAKE_CURRENT_SOURCE_DIR}")
+ foreach(i ui rc res cc cxx hh all)
+ set(${var}-${i} "")
endforeach()
- file(GLOB ${var}-ui ${dir}/*.ui)
- file(GLOB ${var}-rc ${dir}/*.qrc)
- set(${var}-all ${${var}-cc} ${${var}-hh} ${${var}-rc} ${${var}-res})
- foreach(i ui rc res cc hh all)
- set(${var}-${i} "${${var}-${i}}" PARENT_SCOPE)
- endforeach()
-endfunction()
-
-function(otr_qt n)
- if(".${${n}-hh}" STREQUAL ".")
- message(FATAL_ERROR "project ${n} not globbed")
- endif()
- qt5_wrap_cpp(${n}-moc ${${n}-hh} OPTIONS --no-notes)
- qt5_wrap_ui(${n}-uih ${${n}-ui})
- qt5_add_resources(${n}-rcc ${${n}-rc})
- foreach(i moc uih rcc)
- set(${n}-${i} "${${n}-${i}}" PARENT_SCOPE)
- list(APPEND ${n}-all ${${n}-${i}})
+ foreach(dir ${ARGN})
+ set(dir "${basedir}/${dir}")
+ file(GLOB cxx CONFIGURE_DEPENDS "${dir}/*.cpp")
+ file(GLOB cc CONFIGURE_DEPENDS "${dir}/*.c")
+ file(GLOB hh CONFIGURE_DEPENDS "${dir}/*.h" "${dir}/*.hpp" "${dir}/*.inc")
+ file(GLOB res CONFIGURE_DEPENDS "${dir}/*.rc")
+ foreach(f res)
+ set_source_files_properties(${f} PROPERTIES LANGUAGE RC)
+ endforeach()
+ file(GLOB ui CONFIGURE_DEPENDS "${dir}/*.ui")
+ file(GLOB rc CONFIGURE_DEPENDS "${dir}/*.qrc")
+ set(all ${cc} ${cxx} ${hh} ${res})
+ foreach(i ui rc res cc cxx hh all)
+ set(${var}-${i} "${${var}-${i}}" ${${i}} PARENT_SCOPE)
+ endforeach()
endforeach()
- set(${n}-all "${${n}-all}" PARENT_SCOPE)
endfunction()
function(otr_fixup_subsystem n)
if(MSVC)
- if(SDK_CONSOLE_DEBUG)
- set(subsystem CONSOLE)
- else()
- set(subsystem WINDOWS)
- endif()
- set(loc "$<TARGET_FILE:${n}>")
+ otr_find_msvc_editbin(editbin-pathname)
+ set(subsystem WINDOWS)
get_property(type TARGET "${n}" PROPERTY TYPE)
if (NOT type STREQUAL "STATIC_LIBRARY")
+ set(loc "$<TARGET_FILE:${n}>")
add_custom_command(TARGET "${n}"
POST_BUILD
- COMMAND editbin -nologo -SUBSYSTEM:${subsystem},5.01 -OSVERSION:5.1 \"${loc}\")
+ COMMAND "${editbin-pathname}" -nologo -SUBSYSTEM:${subsystem},5.01 -OSVERSION:5.1 \"${loc}\")
endif()
endif()
endfunction()
function(otr_compat target)
if(NOT MSVC)
- set_property(SOURCE ${${target}-moc} APPEND_STRING PROPERTY COMPILE_FLAGS "-w -Wno-error")
+ set_property(SOURCE ${${target}-moc} APPEND PROPERTY COMPILE_OPTIONS "-w;-Wno-error")
endif()
- if(WIN32)
- target_link_libraries(${target} dinput8 dxguid strmiids)
+
+ if(UNIX) # no-op on OSX
+ target_link_libraries(${target} m)
+ endif()
+
+ get_property(type TARGET "${n}" PROPERTY TYPE)
+ if (type STREQUAL "EXECUTABLE")
+ otr_fixup_subsystem(${target})
endif()
- otr_fixup_subsystem(${target})
endfunction()
-include(CMakeParseArguments)
+function(otr_is_sln_generator var)
+ string(FIND "${CMAKE_GENERATOR}" "Visual Studio " is-msvc)
+ if(is-msvc EQUAL 0)
+ set(${var} TRUE PARENT_SCOPE)
+ else()
+ set(${var} FALSE PARENT_SCOPE)
+ endif()
+endfunction()
-function(otr_is_target_c_only ret srcs)
- set(val TRUE)
- foreach(i ${srcs})
- get_filename_component(ext "${i}" EXT)
- string(TOLOWER "${ext}" ext)
- if(ext STREQUAL ".cpp")
- set(val FALSE)
- break()
- endif()
- endforeach()
- set(${ret} "${val}" PARENT_SCOPE)
+function(otr_find_msvc_editbin varname)
+ if(MSVC)
+ get_filename_component(linker-dir "${CMAKE_LINKER}" DIRECTORY)
+ set("${varname}" "${linker-dir}/editbin.exe" PARENT_SCOPE)
+ else()
+ set("${varname}" "editbin" PARENT_SCOPE)
+ endif()
endfunction()
-function(otr_install_pdb_current_project)
- if(MSVC AND FALSE)
- file(GLOB_RECURSE pdbs "${CMAKE_CURRENT_BINARY_DIR}/*.pdb")
- install(FILES ${pdbs} DESTINATION "${subdir}" ${opentrack-perms})
+function(otr_install_pdb_current_project target)
+ if(MSVC)
+ install(FILES "$<TARGET_PDB_FILE:${target}>" DESTINATION "${opentrack-debug}" PERMISSIONS ${opentrack-perms-file})
endif()
endfunction()
-function(otr_module n)
- message(STATUS "module ${n}")
+function(otr_module n_)
+ message(STATUS "module ${n_}")
cmake_parse_arguments(arg
- "STATIC;NO-COMPAT;BIN;EXECUTABLE;NO-QT;WIN32-CONSOLE;NO-INSTALL"
+ "STATIC;NO-COMPAT;BIN;EXECUTABLE;NO-QT;NO-I18N;WIN32-CONSOLE;NO-INSTALL;RELINK"
"LINK;COMPILE"
- "SOURCES"
+ "SOURCES;SUBDIRS"
${ARGN}
- )
+ )
+
if(NOT "${arg_UNPARSED_ARGUMENTS}" STREQUAL "")
- message(FATAL_ERROR "otr_module bad formals: ${arg_UNPARSED_ARGUMENTS}")
+ message(FATAL_ERROR "otr_module(${n_}) bad formals: ${arg_UNPARSED_ARGUMENTS}")
endif()
- set(n_orig "${n}")
- set(n "opentrack-${n}")
+ set(n "opentrack-${n_}")
- otr_glob_sources(${n})
- otr_is_target_c_only(is-c-only "${${n}-all}")
- if(NOT (is-c-only OR arg_NO-QT))
- otr_qt(${n})
+ if(NOT arg_SUBDIRS)
+ otr_glob_sources(${n} .)
else()
- set(arg_NO-QT TRUE)
+ otr_glob_sources(${n} . ${arg_SUBDIRS})
endif()
- list(APPEND ${n}-all ${arg_SOURCES})
- if(arg_NO-QT)
- set(arg_NO-COMPAT TRUE)
- endif()
-
- string(TOUPPER arg_WIN32-CONSOLE "${arg_WIN32-CONSOLE}")
+ list(APPEND ${n}-all ${arg_SOURCES})
- if(NOT WIN32)
- set(subsys "")
- elseif(MSVC)
- set(subsys "WIN32")
- elseif(arg_WIN32-CONSOLE)
- set(subsys "")
+ if(NOT arg_NO-QT)
+ otr_qt(${n})
else()
- set(subsys "WIN32")
+ set(arg_NO-COMPAT TRUE)
+ set(arg_NO-I18N TRUE)
endif()
if(arg_EXECUTABLE)
+ if (APPLE)
+ set(subsys "MACOSX_BUNDLE")
+ elseif(NOT WIN32)
+ set(subsys "")
+ elseif(arg_WIN32-CONSOLE)
+ set(subsys "")
+ else()
+ set(subsys "WIN32")
+ endif()
+
add_executable(${n} ${subsys} "${${n}-all}")
+ set_target_properties(${n} PROPERTIES
+ SUFFIX "${opentrack-binary-suffix}"
+ OUTPUT_NAME "${n_}"
+ PREFIX "")
+ if(MSVC)
+ target_compile_options(${n} PRIVATE -GA)
+ endif()
else()
set(link-mode SHARED)
if (arg_STATIC)
set(link-mode STATIC)
endif()
add_library(${n} ${link-mode} "${${n}-all}")
+ set_property(TARGET "${n}" PROPERTY PREFIX "")
+ endif()
+
+ if(NOT arg_NO-QT)
+ otr_qt2("${n}")
+ endif()
+
+ set(self "${n}" PARENT_SCOPE)
+
+ if(NOT arg_RELINK AND FALSE)
+ set_property(TARGET ${n} PROPERTY LINK_DEPENDS_NO_SHARED TRUE)
+ else()
+ set_property(TARGET ${n} PROPERTY LINK_DEPENDS_NO_SHARED FALSE)
endif()
- set_property(TARGET ${n} PROPERTY PREFIX "")
if(NOT arg_NO-QT)
target_link_libraries(${n} ${MY_QT_LIBS})
@@ -164,60 +191,111 @@ function(otr_module n)
target_link_libraries(${n} opentrack-api opentrack-options opentrack-compat)
endif()
+ string(REPLACE "-" "_" build-n ${n_})
+ string(TOUPPER "${build-n}" build-n)
+ target_compile_definitions(${n} PRIVATE "BUILD_${build-n}")
+ include(opentrack-org)
+
+ if(arg_STATIC)
+ set(arg_NO-INSTALL TRUE)
+ endif()
+
otr_compat(${n})
- if(CMAKE_COMPILER_IS_GNUCXX)
- set(c-props "-fvisibility=hidden")
- if(NOT is-c-only)
- set(c-props "${c-props} -fuse-cxa-atexit")
+ if(CMAKE_COMPILER_IS_CLANGXX AND (arg_EXECUTABLE OR NOT arg_BIN))
+ set(opts
+ weak-vtables
+ header-hygiene
+ )
+ foreach(k ${opts})
+ target_compile_options(${n} PRIVATE "-Wno-${k}")
+ endforeach()
+ endif()
+
+ if(NOT arg_NO-INSTALL)
+ # Librarys/executable
+ if(arg_BIN)
+ if (APPLE)
+ install(TARGETS "${n}"
+ RUNTIME DESTINATION "${opentrack-bin}"
+ BUNDLE DESTINATION "${opentrack-bin}"
+ LIBRARY DESTINATION "${opentrack-bin}/Library"
+ RESOURCE DESTINATION "${opentrack-bin}/opentrack.app/Resource"
+ PERMISSIONS ${opentrack-perms-exec})
+ else()
+ install(TARGETS "${n}"
+ RUNTIME DESTINATION "${opentrack-bin}"
+ LIBRARY DESTINATION "${opentrack-libexec}"
+ PERMISSIONS ${opentrack-perms-exec})
+ endif()
+ else()
+ # Plugins
+ install(TARGETS "${n}"
+ RUNTIME DESTINATION "${opentrack-libexec}"
+ LIBRARY DESTINATION "${opentrack-libexec}"
+ PERMISSIONS ${opentrack-perms-exec})
+ endif()
+
+ if(MSVC)
+ set(opentrack_install-debug-info FALSE CACHE BOOL "Whether to build and install debug info at install time")
+ if(opentrack_install-debug-info)
+ otr_install_pdb_current_project(${n})
+ endif()
endif()
endif()
- if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE)
- set(l-props "-Wl,--as-needed")
+ if(NOT arg_NO-I18N)
+ otr_i18n_for_target_directory(${n_})
endif()
- set_property(TARGET ${n} APPEND_STRING PROPERTY COMPILE_FLAGS "${c-props} ${arg_COMPILE}")
- set_property(TARGET ${n} APPEND_STRING PROPERTY LINK_FLAGS "${l-props} ${arg_LINK}")
+ set_property(GLOBAL APPEND PROPERTY opentrack-all-modules "${n_}")
+ set_property(GLOBAL APPEND PROPERTY opentrack-all-source-dirs "${CMAKE_CURRENT_SOURCE_DIR}")
- if(NOT arg_STATIC)
- string(REGEX REPLACE "^opentrack-" "" n_ "${n}")
- string(REPLACE "-" "_" n_ ${n_})
- string(TOUPPER "${n_}" n__)
- target_compile_definitions(${n} PRIVATE "BUILD_${n__}")
+ #make_directory("${CMAKE_CURRENT_BINARY_DIR}")
+endfunction()
- if(NOT arg_NO-INSTALL)
- if(arg_BIN AND WIN32)
- set(subdir ".")
- install(TARGETS "${n}" RUNTIME DESTINATION . ${opentrack-perms})
- else()
- set(subdir "${opentrack-hier-pfx}")
- install(TARGETS "${n}" ${opentrack-hier-str} ${opentrack-perms})
- endif()
- otr_install_pdb_current_project()
- endif()
- else()
- target_compile_definitions(${n} PRIVATE "STATIC_LIBRARY=1")
- endif()
-
- set_property(GLOBAL APPEND PROPERTY opentrack-all-modules "${n}")
-
- foreach(i ${opentrack-all-translations})
- set(t "${CMAKE_CURRENT_SOURCE_DIR}/lang/${i}.ts")
- add_custom_command(OUTPUT "${t}"
- COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/lang"
- COMMAND "${Qt5_DIR}/../../../bin/lupdate" -silent -recursive -no-obsolete -locations relative . -ts "${t}"
- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
- DEPENDS ${${n}-cc} ${${n}-hh} ${${n}-ui} ${${n}-rc}
- COMMENT "Running lupdate for ${n}/${i}")
- set(target-name "i18n-lang-${i}-module-${n_orig}")
- add_custom_target(${target-name} DEPENDS "${t}")
- set_property(GLOBAL APPEND PROPERTY "opentrack-ts-targets-${i}" "${target-name}")
- set_property(GLOBAL APPEND PROPERTY "opentrack-ts-files-${i}" "${t}")
+function(otr_add_target_dirs var)
+ set(globs "")
+ foreach(k ${ARGN})
+ list(APPEND globs "${k}/CMakeLists.txt")
endforeach()
+ set(projects "")
+ file(GLOB projects CONFIGURE_DEPENDS ${globs})
+ list(SORT projects)
+ set("${var}" "${projects}" PARENT_SCOPE)
+endfunction()
- if(NOT arg_NO-INSTALL)
- set_property(GLOBAL APPEND PROPERTY opentrack-all-source-dirs "${CMAKE_CURRENT_SOURCE_DIR}")
+function(otr_pdb_for_dll varname path)
+ set("${varname}" "" PARENT_SCOPE)
+ get_filename_component(dir "${path}" DIRECTORY)
+ get_filename_component(name-only "${path}" NAME_WE)
+ set(pdb-path "${dir}/${name-only}.pdb")
+ if(EXISTS "${pdb-path}")
+ set("${varname}" "${pdb-path}" PARENT_SCOPE)
endif()
endfunction()
+function(otr_install_lib target dest)
+ if(WIN32)
+ string(FIND "${target}" "/" idx)
+ if(idx EQUAL -1)
+ get_property(path TARGET "${target}" PROPERTY "LOCATION_${CMAKE_BUILD_TYPE}")
+ else()
+ set(path "${target}")
+ endif()
+ if(path STREQUAL "")
+ message(FATAL_ERROR "Can't find ${target}")
+ endif()
+ string(TOLOWER "${path}" path_)
+ if(NOT path_ MATCHES "\\.(a|lib)$")
+ if(MSVC AND opentrack_install-debug-info)
+ set(pdb-path "")
+ otr_pdb_for_dll(pdb-path "${path}")
+ if(pdb-path)
+ install(FILES "${pdb-path}" DESTINATION "${opentrack-debug}" PERMISSIONS ${opentrack-perms-exec})
+ endif()
+ endif()
+ install(FILES "${path}" DESTINATION "${dest}" PERMISSIONS ${opentrack-perms-exec})
+ endif()
+ endif()
+endfunction()