Skip to content

Commit 87e021e

Browse files
notrojclaude
andcommitted
CMake: fix windres resource compilation with MinGW:
* CMakeLists.txt: TARGET_COMPILE_DEFINITIONS does not correctly handle values with spaces for MinGW windres, which invokes cc1.exe as its preprocessor. Defines like LONG_NAME="Apache HTTP Server htdbm program" get split on spaces, causing "fatal error: HTTP\: No such file or directory" and similar errors. LONG_NAME, BIN_NAME, APP_FILE, and ICON_FILE are only used in build/win32/httpd.rc, so generate per-target wrapper .rc files with these defines baked in as #define directives, then #include the real httpd.rc. This avoids command-line quoting entirely. Also fix TARGET_COMPILE_OPTIONS in the standard_support FOREACH loop which incorrectly referenced ${mod_name} from the outer modules loop instead of ${pgm}. Claude's explanation of the root cause: Root cause: Commit ed4ffd0 replaced the DEFINE_WITH_BLANKS() macro with TARGET_COMPILE_DEFINITIONS(), which correctly handles spaces for the C compiler but NOT for MinGW's windres.exe. The resource compiler invokes cc1.exe as its preprocessor, and -DLONG_NAME="Apache HTTP Server htdbm program" gets split on spaces — each word after Apache gets treated as an input file, causing the fatal error: HTTP\: No such file or directory errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 73e309c commit 87e021e

1 file changed

Lines changed: 50 additions & 34 deletions

File tree

CMakeLists.txt

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ FOREACH(onelib ${APR_LIBRARIES})
142142
ENDIF()
143143
ENDFOREACH()
144144

145+
# Generate a per-target wrapper .rc file with the given preprocessor
146+
# definitions baked in, to avoid passing values with spaces on the
147+
# windres command line where quoting is not handled correctly.
148+
FUNCTION(GENERATE_RC_FILE target_name rc_path_var)
149+
SET(_rc_file "${CMAKE_BINARY_DIR}/rc/${target_name}_httpd.rc")
150+
SET(_content "")
151+
FOREACH(_def ${ARGN})
152+
STRING(APPEND _content "#define ${_def}\n")
153+
ENDFOREACH()
154+
STRING(APPEND _content "#include \"${CMAKE_SOURCE_DIR}/build/win32/httpd.rc\"\n")
155+
FILE(WRITE "${_rc_file}" "${_content}")
156+
SET(${rc_path_var} "${_rc_file}" PARENT_SCOPE)
157+
ENDFUNCTION()
158+
145159
MACRO(GET_MOD_ENABLE_RANK macro_modname macro_mod_enable_val macro_output_rank)
146160
IF(${macro_mod_enable_val} STREQUAL "O")
147161
SET(${macro_output_rank} 0)
@@ -852,7 +866,11 @@ FOREACH (mod ${MODULE_PATHS})
852866
SET(tmp_mod_main_source ${${mod_main_source}})
853867
ENDIF()
854868
SET(all_mod_sources ${tmp_mod_main_source} ${${mod_extra_sources}})
855-
ADD_LIBRARY(${mod_name} SHARED ${all_mod_sources} build/win32/httpd.rc)
869+
GENERATE_RC_FILE(${mod_name} _mod_rc
870+
"LONG_NAME ${mod_name} for Apache HTTP Server"
871+
"BIN_NAME ${mod_name}.so"
872+
)
873+
ADD_LIBRARY(${mod_name} SHARED ${all_mod_sources} ${_mod_rc})
856874
SET(install_modules ${install_modules} ${mod_name})
857875
IF(INSTALL_PDB)
858876
SET(install_modules_pdb ${install_modules_pdb} "$<TARGET_PDB_FILE:${mod_name}>")
@@ -870,10 +888,6 @@ FOREACH (mod ${MODULE_PATHS})
870888
LINK_FLAGS /base:@${PROJECT_BINARY_DIR}/BaseAddr.ref,${mod_name}.so
871889
)
872890
TARGET_LINK_LIBRARIES(${mod_name} ${${mod_extra_libs}} libhttpd ${EXTRA_LIBS} ${APR_LIBRARIES} ${HTTPD_SYSTEM_LIBS})
873-
TARGET_COMPILE_DEFINITIONS(${mod_name} PRIVATE
874-
"LONG_NAME=${mod_name} for Apache HTTP Server"
875-
"BIN_NAME=${mod_name}.so"
876-
)
877891
TARGET_COMPILE_OPTIONS(${mod_name} PRIVATE "${EXTRA_COMPILE_FLAGS}")
878892

879893
# Extra defines?
@@ -894,7 +908,11 @@ FOREACH (mod ${MODULE_PATHS})
894908
ENDFOREACH()
895909

896910
########### HTTPD LIBRARIES ############
897-
ADD_LIBRARY(libhttpd SHARED ${LIBHTTPD_SOURCES} build/win32/httpd.rc)
911+
GENERATE_RC_FILE(libhttpd _libhttpd_rc
912+
"LONG_NAME Apache HTTP Server Core"
913+
"BIN_NAME libhttpd.dll"
914+
)
915+
ADD_LIBRARY(libhttpd SHARED ${LIBHTTPD_SOURCES} ${_libhttpd_rc})
898916
SET_TARGET_PROPERTIES(libhttpd PROPERTIES
899917
LINK_FLAGS /base:@${PROJECT_BINARY_DIR}/BaseAddr.ref,libhttpd.dll
900918
)
@@ -904,25 +922,23 @@ IF(INSTALL_PDB)
904922
ENDIF()
905923
TARGET_LINK_LIBRARIES(libhttpd ${EXTRA_LIBS} ${APR_LIBRARIES} ${PCRE_LIBRARIES} ${HTTPD_SYSTEM_LIBS})
906924
TARGET_COMPILE_DEFINITIONS(libhttpd PRIVATE
907-
"LONG_NAME=Apache HTTP Server Core"
908-
"BIN_NAME=libhttpd.dll"
909925
"AP_DECLARE_EXPORT"
910926
)
911927
TARGET_COMPILE_OPTIONS(libhttpd PRIVATE ${PCRE_CFLAGS} ${EXTRA_COMPILE_FLAGS})
912928
ADD_DEPENDENCIES(libhttpd test_char_header)
913929

914930
########### HTTPD EXECUTABLES ##########
915-
ADD_EXECUTABLE(httpd server/main.c build/win32/httpd.rc)
931+
GENERATE_RC_FILE(httpd _httpd_rc
932+
"APP_FILE"
933+
"LONG_NAME Apache HTTP Server"
934+
"BIN_NAME httpd.exe"
935+
"ICON_FILE ${CMAKE_SOURCE_DIR}/build/win32/apache.ico"
936+
)
937+
ADD_EXECUTABLE(httpd server/main.c ${_httpd_rc})
916938
SET(install_targets ${install_targets} httpd)
917939
IF(INSTALL_PDB)
918940
SET(install_bin_pdb ${install_bin_pdb} $<TARGET_PDB_FILE:httpd>)
919941
ENDIF()
920-
TARGET_COMPILE_DEFINITIONS(httpd PRIVATE
921-
"APP_FILE"
922-
"LONG_NAME=Apache HTTP Server"
923-
"BIN_NAME=httpd.exe"
924-
"ICON_FILE=${CMAKE_SOURCE_DIR}/build/win32/apache.ico"
925-
)
926942
TARGET_COMPILE_OPTIONS(httpd PRIVATE "${EXTRA_COMPILE_FLAGS}")
927943
SET_TARGET_PROPERTIES(httpd PROPERTIES
928944
LINK_FLAGS "/stack:0x40000"
@@ -944,48 +960,48 @@ SET(htpasswd_extra_sources support/passwd_common.c)
944960

945961
FOREACH(pgm ${standard_support})
946962
SET(extra_sources ${pgm}_extra_sources)
947-
ADD_EXECUTABLE(${pgm} support/${pgm}.c ${${extra_sources}} build/win32/httpd.rc)
963+
GENERATE_RC_FILE(${pgm} _pgm_rc
964+
"APP_FILE"
965+
"LONG_NAME Apache HTTP Server ${pgm} program"
966+
"BIN_NAME ${pgm}.exe"
967+
)
968+
ADD_EXECUTABLE(${pgm} support/${pgm}.c ${${extra_sources}} ${_pgm_rc})
948969
SET(install_targets ${install_targets} ${pgm})
949970
IF(INSTALL_PDB)
950971
SET(install_bin_pdb ${install_bin_pdb} $<TARGET_PDB_FILE:${pgm}>)
951972
ENDIF()
952-
TARGET_COMPILE_DEFINITIONS(${pgm} PRIVATE
953-
"APP_FILE"
954-
"LONG_NAME=Apache HTTP Server ${pgm} program"
955-
"BIN_NAME=${pgm}.exe"
956-
)
957-
TARGET_COMPILE_OPTIONS(${mod_name} PRIVATE "${EXTRA_COMPILE_FLAGS}")
973+
TARGET_COMPILE_OPTIONS(${pgm} PRIVATE "${EXTRA_COMPILE_FLAGS}")
958974
TARGET_LINK_LIBRARIES(${pgm} ${EXTRA_LIBS} ${APR_LIBRARIES})
959975
ENDFOREACH()
960976

961-
ADD_EXECUTABLE(ab support/ab.c build/win32/httpd.rc)
977+
GENERATE_RC_FILE(ab _ab_rc
978+
"APP_FILE"
979+
"LONG_NAME Apache HTTP Server ab program"
980+
"BIN_NAME ab.exe"
981+
)
982+
ADD_EXECUTABLE(ab support/ab.c ${_ab_rc})
962983
SET(install_targets ${install_targets} ab)
963984
IF(INSTALL_PDB)
964985
SET(install_bin_pdb ${install_bin_pdb} $<TARGET_PDB_FILE:ab>)
965986
ENDIF()
966987
SET(tmp_includes ${HTTPD_INCLUDE_DIRECTORIES})
967988
SET_TARGET_PROPERTIES(ab PROPERTIES INCLUDE_DIRECTORIES "${tmp_includes}")
968-
TARGET_COMPILE_DEFINITIONS(ab PRIVATE
969-
"APP_FILE"
970-
"LONG_NAME=Apache HTTP Server ab program"
971-
"BIN_NAME=ab.exe"
972-
)
973989
TARGET_LINK_LIBRARIES(ab ${EXTRA_LIBS} ${APR_LIBRARIES} Ws2_32.lib)
974990

975991
IF(OPENSSL_FOUND)
976-
ADD_EXECUTABLE(abs support/ab.c build/win32/httpd.rc)
992+
GENERATE_RC_FILE(abs _abs_rc
993+
"APP_FILE"
994+
"LONG_NAME Apache HTTP Server ab/SSL program"
995+
"BIN_NAME abs.exe"
996+
)
997+
ADD_EXECUTABLE(abs support/ab.c ${_abs_rc})
977998
SET(install_targets ${install_targets} abs)
978999
IF(INSTALL_PDB)
9791000
SET(install_bin_pdb ${install_bin_pdb} $<TARGET_PDB_FILE:abs>)
9801001
ENDIF()
9811002
SET_TARGET_PROPERTIES(abs PROPERTIES COMPILE_DEFINITIONS HAVE_OPENSSL)
9821003
SET(tmp_includes ${HTTPD_INCLUDE_DIRECTORIES} ${OPENSSL_INCLUDE_DIR})
9831004
SET_TARGET_PROPERTIES(abs PROPERTIES INCLUDE_DIRECTORIES "${tmp_includes}")
984-
TARGET_COMPILE_DEFINITIONS(abs PRIVATE
985-
"APP_FILE"
986-
"LONG_NAME=Apache HTTP Server ab/SSL program"
987-
"BIN_NAME=abs.exe"
988-
)
9891005
TARGET_LINK_LIBRARIES(abs ${EXTRA_LIBS} ${APR_LIBRARIES} ${OPENSSL_LIBRARIES} Ws2_32.lib)
9901006
ENDIF()
9911007

0 commit comments

Comments
 (0)