@@ -27,6 +27,26 @@ find_package(Qt6Widgets REQUIRED)
2727
2828qt_standard_project_setup()
2929
30+ function (qt_deploy executable_name)
31+ if (WIN32 )
32+ qt_generate_deploy_app_script(TARGET ${executable_name}
33+ OUTPUT_SCRIPT script_file
34+ )
35+ install (SCRIPT ${script_file} )
36+ endif ()
37+ endfunction ()
38+
39+ function (install_executable executable_name)
40+ install (TARGETS ${executable_name} )
41+ qt_deploy(${executable_name} )
42+ if (LINUX)
43+ set_target_properties (${executable_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib" )
44+ endif ()
45+ if (APPLE )
46+ set_target_properties (${executable_name} PROPERTIES INSTALL_RPATH "@loader_path/../lib" )
47+ endif ()
48+ endfunction ()
49+
3050if (INCLUDE_WHAT_YOU_USE)
3151 set (CMAKE_CXX_INCLUDE_WHAT_YOU_USE
3252 include -what-you-use
@@ -38,57 +58,45 @@ endif()
3858if (MSVC )
3959 add_compile_options (/W4)
4060else ()
41- add_compile_options (-Wall -Wextra -Wpedantic)
61+ add_compile_options (-Wall -Wextra -Wpedantic $<$<CONFIG:Debug>:-Og> )
4262endif ()
4363
4464if (TRACK_COVERAGE)
45- add_compile_options (-Og)
4665 add_compile_options (--coverage)
4766 add_link_options (--coverage)
4867endif ()
4968
5069qt_add_library(JustlyLibrary SHARED)
5170
52- # disable assertions for release
5371target_compile_features (JustlyLibrary PRIVATE cxx_std_20)
54- add_compile_definitions (JustlyLibrary PUBLIC $<$<CONFIG:Release>:QT_NO_DEBUG=1>)
72+ target_link_libraries (JustlyLibrary PUBLIC Qt6::Core)
73+ target_link_libraries (JustlyLibrary PRIVATE
74+ FluidSynth::libfluidsynth
75+ nlohmann_json::nlohmann_json
76+ nlohmann_json_schema_validator::validator
77+ Qt6::Gui
78+ Qt6::Widgets
79+ )
5580
81+ add_compile_definitions (JustlyLibrary PUBLIC $<$<CONFIG:Release>:QT_NO_DEBUG=1>)
82+ target_compile_definitions (JustlyLibrary PRIVATE JUSTLY_LIBRARY)
5683if (NO_REALTIME_AUDIO)
5784 target_compile_definitions (JustlyLibrary PRIVATE NO_REALTIME_AUDIO)
5885endif ()
5986
6087add_subdirectory (include )
61-
62- target_sources (JustlyLibrary PRIVATE "src/justly.cpp" )
63-
64- target_include_directories (JustlyLibrary PRIVATE src)
65-
66- # add source dir for build but not install interface
6788target_include_directories (JustlyLibrary PUBLIC
6889 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
6990 $<INSTALL_INTERFACE:include >
7091)
7192
72- target_link_libraries (JustlyLibrary PUBLIC Qt6::Core)
73-
74- target_link_libraries (JustlyLibrary PRIVATE
75- FluidSynth::libfluidsynth
76- nlohmann_json::nlohmann_json
77- nlohmann_json_schema_validator::validator
78- Qt6::Gui
79- Qt6::Widgets
80- )
81-
82- # for dllexport instead of dllimport
83- target_compile_definitions (JustlyLibrary PRIVATE JUSTLY_LIBRARY)
93+ target_sources (JustlyLibrary PRIVATE "src/justly.cpp" )
8494
8595install (TARGETS JustlyLibrary
8696 RUNTIME_DEPENDENCY_SET runtime_dependencies
8797 FILE_SET justly_public_headers
8898)
89-
9099if (WIN32 )
91- # on other platforms, these should be system libraries
92100 install (RUNTIME_DEPENDENCY_SET runtime_dependencies
93101 PRE_INCLUDE_REGEXES
94102 glib
@@ -106,43 +114,18 @@ if (WIN32)
106114 vorbisenc
107115 PRE_EXCLUDE_REGEXES .
108116 DIRECTORIES
109- # vcpkg libraries
110117 ${_VCPKG_INSTALLED_DIR} /{VCPKG_TARGET_TRIPLET}/lib
111118 )
112- # not getting picked up as a runtime dependency?
113119 find_package (FLAC REQUIRED)
114120 install (FILES $<TARGET_FILE:FLAC::FLAC> TYPE BIN)
115121endif ()
116-
117- function (qt_deploy executable_name)
118- if (WIN32 )
119- qt_generate_deploy_app_script(TARGET ${executable_name}
120- OUTPUT_SCRIPT script_file
121- )
122- install (SCRIPT ${script_file} )
123- endif ()
124- endfunction ()
125-
126122qt_deploy(JustlyLibrary)
127123install (DIRECTORY ${Justly_SOURCE_DIR} /share/ TYPE DATA)
128124
129- function (install_executable executable_name)
130- install (TARGETS ${executable_name} )
131-
132- qt_deploy(${executable_name} )
133- if (LINUX)
134- set_target_properties (${executable_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib" )
135- endif ()
136- if (APPLE )
137- set_target_properties (${executable_name} PROPERTIES INSTALL_RPATH "@loader_path/../lib" )
138- endif ()
139- endfunction ()
140-
141125qt_add_executable(Justly)
142126target_sources (Justly PRIVATE bin/main.cpp)
143127target_link_libraries (Justly PRIVATE JustlyLibrary Qt6::Core Qt6::Widgets)
144128if (WIN32 )
145- # suppress console window
146129 set_target_properties (Justly PROPERTIES WIN32_EXECUTABLE ON )
147130endif ()
148131install_executable(Justly)
@@ -151,7 +134,6 @@ if (BUILD_TESTS)
151134 qt_add_executable(JustlyTests)
152135 target_sources (JustlyTests PRIVATE tests/test .cpp)
153136 target_include_directories (JustlyTests PRIVATE ${Justly_SOURCE_DIR} )
154-
155137 target_link_libraries (JustlyTests PRIVATE
156138 JustlyLibrary
157139 Qt6::Core
@@ -160,17 +142,13 @@ if (BUILD_TESTS)
160142 Qt6::Widgets
161143 )
162144 install_executable(JustlyTests)
163-
164145 set (test_install_folder ${Justly_SOURCE_DIR} /test_install)
165-
166146 add_custom_target (install_tests ALL
167147 COMMAND cmake --install ${CMAKE_CURRENT_BINARY_DIR}
168148 --prefix ${test_install_folder}
169149 --config $<CONFIG>
170150 )
171151 add_dependencies (install_tests JustlyLibrary Justly JustlyTests)
172-
173- # test the installed app
174152 add_test (NAME run_tests COMMAND ${test_install_folder} /bin/JustlyTests)
175153endif ()
176154
0 commit comments