Skip to content

Commit 5222c99

Browse files
committed
Address Copilot review feedback for BUILD_BOTH_LIBRARIES
- Add validation to prevent BUILD_BOTH_LIBRARIES and BUILD_SHARED_LIBS from being used together (with warning message) - Improve documentation for the cpp_dotenv alias, explaining that it points to cpp_dotenv_static when BUILD_BOTH_LIBRARIES is ON
1 parent 9d3f65b commit 5222c99

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ message(STATUS "Building CPP-DOTENV in ${CMAKE_BUILD_TYPE} mode")
1515
# Option to build both static and shared libraries
1616
option(BUILD_BOTH_LIBRARIES "Build both static and shared libraries" OFF)
1717

18+
# Validate that BUILD_BOTH_LIBRARIES and BUILD_SHARED_LIBS are not used together
19+
if(BUILD_BOTH_LIBRARIES AND BUILD_SHARED_LIBS)
20+
message(WARNING "BUILD_BOTH_LIBRARIES and BUILD_SHARED_LIBS should not be used together. BUILD_SHARED_LIBS will be ignored.")
21+
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE)
22+
endif()
23+
1824
#------------------- SUBDIRECTORY ADDITION ------------------------------------
1925

2026
add_subdirectory(common)
@@ -57,7 +63,10 @@ if(BUILD_BOTH_LIBRARIES)
5763
target_include_directories(cpp_dotenv_shared PUBLIC ${CPP_DOTENV_INCLUDE_DIRS})
5864
target_compile_options(cpp_dotenv_shared PRIVATE ${CPP_DOTENV_COMPILE_OPTIONS})
5965

60-
# Alias for compatibility - default to static
66+
# Alias for backward compatibility:
67+
# When BUILD_BOTH_LIBRARIES is ON, the cpp_dotenv target is an alias to
68+
# cpp_dotenv_static. Projects that need the shared library must explicitly
69+
# link against cpp_dotenv_shared instead of cpp_dotenv.
6170
add_library(cpp_dotenv ALIAS cpp_dotenv_static)
6271
else()
6372
# Single library (type determined by BUILD_SHARED_LIBS)

0 commit comments

Comments
 (0)