Skip to content

Commit e337626

Browse files
Jojo-1000enwi
authored andcommitted
Apply CMake fixes for debian packaging.
Thanks @thekhalifa
1 parent 28cfbab commit e337626

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

CMakeLists.txt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
cmake_minimum_required(VERSION 3.10.2)
2-
3-
if(${CMAKE_VERSION} VERSION_LESS 3.11)
4-
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
5-
else()
6-
cmake_policy(VERSION 3.11)
7-
endif()
1+
cmake_minimum_required(VERSION 3.10.2...3.28)
82

93
# Add cmake dir to module path, so Find*.cmake can be found
104
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
@@ -27,11 +21,12 @@ option(hueplusplus_NO_EXTERNAL_LIBRARIES "Do not try to use external libraries"
2721

2822
# Try to find installed packages
2923
if(NOT hueplusplus_NO_EXTERNAL_LIBRARIES)
30-
find_package(MbedTLS)
31-
find_package(nlohmann_json)
24+
# Suppress warnings if libraries are not found, they will be built from submodules
25+
find_package(MbedTLS QUIET)
26+
find_package(nlohmann_json QUIET)
3227
endif()
3328

34-
set(NEED_SUBMODULES NOT (${mbedtls_FOUND} AND ${nlohmann_json_FOUND}))
29+
set(NEED_SUBMODULES NOT (${MbedTLS_FOUND} AND ${nlohmann_json_FOUND}))
3530

3631
option(CLANG_TIDY_FIX "Perform fixes for Clang-Tidy" OFF)
3732
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" DOC "Path to clang-tidy executable")
@@ -92,8 +87,9 @@ if (1 AND APPLE)
9287
set(CMAKE_MACOSX_RPATH 1)
9388
endif()
9489

95-
if(NOT mbedtls_FOUND)
90+
if(NOT MbedTLS_FOUND)
9691
# Build mbedtls if not installed
92+
message(STATUS "MbedTLS was not found, the submodule is used.")
9793
set(USE_STATIC_MBEDTLS_LIBRARY ON)
9894
set(USE_SHARED_MBEDTLS_LIBRARY OFF)
9995
add_subdirectory("lib/mbedtls" EXCLUDE_FROM_ALL)
@@ -112,6 +108,7 @@ endif()
112108

113109
if(NOT nlohmann_json_FOUND)
114110
# Use embedded json
111+
message(STATUS "nlohmann_json was not found, the submodule is used.")
115112
# disable tests for json
116113
set(JSON_BuildTests OFF CACHE INTERNAL "")
117114
add_subdirectory("lib/json" EXCLUDE_FROM_ALL)

src/CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,33 @@ foreach(src ${hueplusplus_SOURCES})
5757
endforeach()
5858
set(hueplusplus_SOURCES ${_srcList} PARENT_SCOPE)
5959

60+
# For install dir variables
61+
include(GNUInstallDirs)
62+
6063
# hueplusplus shared library
6164
add_library(hueplusplusshared SHARED ${hueplusplus_SOURCES})
6265
target_link_libraries(hueplusplusshared PRIVATE MbedTLS::mbedtls)
6366
target_link_libraries(hueplusplusshared PUBLIC nlohmann_json::nlohmann_json)
6467
target_compile_features(hueplusplusshared PUBLIC cxx_std_14)
6568
target_include_directories(hueplusplusshared PUBLIC $<BUILD_INTERFACE:${hueplusplus_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
66-
install(TARGETS hueplusplusshared DESTINATION lib)
69+
6770

6871
# hueplusplus static library
6972
add_library(hueplusplusstatic STATIC ${hueplusplus_SOURCES})
7073
target_link_libraries(hueplusplusstatic PRIVATE MbedTLS::mbedtls)
7174
target_link_libraries(hueplusplusstatic PUBLIC nlohmann_json::nlohmann_json)
7275
target_compile_features(hueplusplusstatic PUBLIC cxx_std_14)
73-
install(TARGETS hueplusplusstatic DESTINATION lib)
76+
if(NOT WIN32)
77+
# On windows, a shared library will also generate a .lib import library, making different names necessary.
78+
# On other platforms the file endings are different, so the names can be the same.
79+
set_target_properties(hueplusplusshared PROPERTIES OUTPUT_NAME hueplusplus SOVERSION 1)
80+
set_target_properties(hueplusplusstatic PROPERTIES OUTPUT_NAME hueplusplus)
81+
endif()
82+
83+
install(TARGETS hueplusplusshared DESTINATION ${CMAKE_INSTALL_LIBDIR})
84+
install(TARGETS hueplusplusstatic DESTINATION ${CMAKE_INSTALL_LIBDIR})
7485
target_include_directories(hueplusplusstatic PUBLIC $<BUILD_INTERFACE:${hueplusplus_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
75-
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" DESTINATION include)
86+
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
7687

7788
# Export the package for use from the build-tree
7889
# (this registers the build-tree with a global CMake-registry)

0 commit comments

Comments
 (0)