diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-01-09 19:14:48 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-01-10 03:18:58 +0100 |
commit | 6388d767f4510a3771909a91ad72ad4963d029db (patch) | |
tree | 3cda0b925d1115873179d32be3a4ca72139cc54a /cmake/opentrack-boilerplate.cmake | |
parent | 7d101a1c2827b5e7a373fb0d0a68099fb692e55a (diff) |
cmake: cleanup, decruft, probably fix mingw
Diffstat (limited to 'cmake/opentrack-boilerplate.cmake')
-rw-r--r-- | cmake/opentrack-boilerplate.cmake | 93 |
1 files changed, 53 insertions, 40 deletions
diff --git a/cmake/opentrack-boilerplate.cmake b/cmake/opentrack-boilerplate.cmake index e4369452..a8da8a23 100644 --- a/cmake/opentrack-boilerplate.cmake +++ b/cmake/opentrack-boilerplate.cmake @@ -28,7 +28,8 @@ endif() function(otr_glob_sources var) set(dir "${CMAKE_CURRENT_SOURCE_DIR}") - file(GLOB ${var}-cc ${dir}/*.cpp ${dir}/*.c) + file(GLOB ${var}-cxx ${dir}/*.cpp) + file(GLOB ${var}-cc ${dir}/*.c) file(GLOB ${var}-hh ${dir}/*.h ${dir}/*.hpp) file(GLOB ${var}-res ${dir}/*.rc) foreach(f ${var}-res) @@ -36,36 +37,22 @@ function(otr_glob_sources var) endforeach() file(GLOB ${var}-ui ${dir}/*.ui) file(GLOB ${var}-rc ${dir}/*.qrc) - set(${var}-all ${${var}-cc} ${${var}-hh} ${${var}-rc} ${${var}-res}) + set(${var}-all ${${var}-cc} ${${var}-cxx} ${${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}}) - endforeach() - set(${n}-all "${${n}-all}" PARENT_SCOPE) -endfunction() - function(otr_fixup_subsystem n) + otr_find_msvc_editbin(editbin-pathname) if(MSVC) set(subsystem WINDOWS) get_property(type TARGET "${n}" PROPERTY TYPE) - set(loc "$<TARGET_FILE:${n}>") 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() @@ -74,33 +61,55 @@ function(otr_compat target) if(NOT MSVC) otr_prop(SOURCE ${${target}-moc} COMPILE_FLAGS "-w -Wno-error") endif() - if(WIN32) - target_link_libraries(${target} dinput8 dxguid strmiids) - endif() - otr_fixup_subsystem(${target}) - set(c-props) - set(l-props) - get_property(linker-lang TARGET ${target} PROPERTY LINKER_LANGUAGE) + get_property(type TARGET "${n}" PROPERTY TYPE) + if (".${TYPE}" STREQUAL ".EXECUTABLE") + otr_fixup_subsystem(${target}) + endif() if(CMAKE_COMPILER_IS_GNUCXX AND NOT MSVC) - set(c-props " -fvisibility=hidden") - if(NOT is-c-only) - if(NOT WIN32 OR NOT ".${CMAKE_CXX_COMPILER_ID}" STREQUAL ".Clang") - set(c-props "${c-props} -fuse-cxa-atexit") - endif() + otr_prop(TARGET ${target} COMPILE_FLAGS "-fvisibility=hidden") + + # gives incorrect result + #get_property(linker-lang TARGET ${target} PROPERTY LINKER_LANGUAGE) + + if (NOT ".${${target}-cxx}" STREQUAL ".") # not a C only target + otr_prop(TARGET ${target} COMPILE_FLAGS "-fuse-cxa-atexit") endif() - endif() - if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE AND NOT MSVC) - set(l-props "-Wl,--as-needed") + if(NOT APPLE) + otr_prop(TARGET ${target} LINK_FLAGS "-Wl,--as-needed") + endif() endif() +endfunction() - otr_prop(TARGET ${target} COMPIcLE_FLAGS "${c-props} ${arg_COMPILE}" - LINK_FLAGS "${l-props} ${arg_LINK}") +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() -include(CMakeParseArguments) +function(otr_find_msvc_editbin varname) + if(MSVC) + # on .sln generator we have no editbin in path + is_sln_generator(is-msvc) + if(is-msvc) + # this is bad but what can we do? searching for vcvarsall.bat + # would be easier, but then we'd have to differentiate x86/amd64 + # cross tools, etc. which is a can of worms and if/else branches. + get_filename_component(linker-dir "${CMAKE_LINKER}" DIRECTORY) + find_file(opentrack_editbin-executable "editbin.exe" "${linker-dir}" "${linker-dir}/.." "${linker-dir}/../..") + otr_escape_string("${editbin-executable}" editbin-executable) + else() + set(opentrack_editbin-executable "editbin") + endif() + mark_as_advanced(FORCE opentrack_editbin-executable) + set("${varname}" "${opentrack_editbin-executable}" PARENT_SCOPE) + endif() +endfunction() function(otr_install_pdb_current_project target) if(MSVC) @@ -108,6 +117,8 @@ function(otr_install_pdb_current_project target) endif() endfunction() +include(CMakeParseArguments) + function(otr_module n_) message(STATUS "module ${n_}") cmake_parse_arguments(arg @@ -182,9 +193,11 @@ function(otr_module n_) else() install(TARGETS "${n}" ${opentrack-hier-str} PERMISSIONS ${opentrack-perms-exec}) endif() - 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}) + 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() |