Skip to content

Commit

Permalink
Fix CMakeLists formatting as per recommended practices (#824)
Browse files Browse the repository at this point in the history
* Convert CMake-language commands to lower case

* Remove CMake-language block-end command arguments

* Ignore `share` dir and executables from out-of-source builds too

* Don't git-ignore src/cdogs/enet/include/

* Use include(CTest) which automatically invokes enable_testing()
  • Loading branch information
rootkea authored Oct 17, 2023
1 parent 97dcd9a commit 0daf4c5
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 103 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# executables
*.exe*
*.zip
src/cdogs-sdl
src/cdogs-sdl-editor
cdogs-sdl
cdogs-sdl-editor
cdogs-sdl.opk
# tests
*_test
Expand All @@ -18,6 +18,7 @@ RemoteSystemsTempFiles/
CPack*
_CPack_Packages/
CTestTestfile.cmake
DartConfiguration.tcl
Testing/
install_manifest_Runtime.txt
*.deb
Expand All @@ -36,8 +37,9 @@ build/windows/cdogs.rc

# Linux
bin/
/share/
share/
include/
!src/cdogs/enet/include/

# Visual Studio
enc_temp_folder/
Expand Down Expand Up @@ -108,7 +110,5 @@ tmp
*~*.cdogscpn
Thumbs.db
.config/
src/cdogs/include/
src/cdogs/share/
*.blend1
emscripten/
126 changes: 63 additions & 63 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ cmake_policy(SET CMP0072 NEW)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
project(cdogs-sdl C)

SET(VERSION_MAJOR "1")
SET(VERSION_MINOR "5")
SET(VERSION_PATCH "0")
SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(VERSION_MAJOR "1")
set(VERSION_MINOR "5")
set(VERSION_PATCH "0")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")

# Optionally configure CI files since they are excluded in source archives
if(EXISTS ${CMAKE_SOURCE_DIR}/.github/workflows/cmake.yml.cmake)
CONFIGURE_FILE(
configure_file(
${CMAKE_SOURCE_DIR}/.github/workflows/cmake.yml.cmake
${CMAKE_SOURCE_DIR}/.github/workflows/cmake.yml
@ONLY
)
endif()
if(EXISTS ${CMAKE_SOURCE_DIR}/appveyor.yml.cmake)
CONFIGURE_FILE(
configure_file(
${CMAKE_SOURCE_DIR}/appveyor.yml.cmake
${CMAKE_SOURCE_DIR}/appveyor.yml
@ONLY
)
endif()

# this must be 4 numbers
SET(VERSION_RC "${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},0")
SET(WEBSITE "http://cxong.github.io/cdogs-sdl/")
set(VERSION_RC "${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},0")
set(WEBSITE "http://cxong.github.io/cdogs-sdl/")

option(DEBUG "Enable debug build" OFF)
option(DEBUG_PROFILE "Enable debug profile build" OFF)
Expand All @@ -50,10 +50,10 @@ endif()
if(WIN32)
set(CMAKE_RC_COMPILER_INIT windres)
enable_language(RC)
SET(CMAKE_RC_COMPILE_OBJECT
set(CMAKE_RC_COMPILE_OBJECT
"<CMAKE_RC_COMPILER> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif()
SET(LINKDIR /usr/games)
set(LINKDIR /usr/games)

if(DEBUG)
set(CMAKE_BUILD_TYPE "Debug")
Expand All @@ -74,35 +74,35 @@ if(BUILD_EDITOR)
find_package(OpenGL REQUIRED)
endif()

SET(ENet_LIBRARY enet)
IF(WIN32)
SET(WINDOWS_ENET_DEPENDENCIES "ws2_32;winmm")
SET(ENet_LIBRARIES ${ENet_LIBRARY} ${WINDOWS_ENET_DEPENDENCIES})
ELSE()
SET(ENet_LIBRARIES ${ENet_LIBRARY})
ENDIF()
set(ENet_LIBRARY enet)
if(WIN32)
set(WINDOWS_ENET_DEPENDENCIES "ws2_32;winmm")
set(ENet_LIBRARIES ${ENet_LIBRARY} ${WINDOWS_ENET_DEPENDENCIES})
else()
set(ENet_LIBRARIES ${ENet_LIBRARY})
endif()

IF(NOT USE_SHARED_ENET)
INCLUDE_DIRECTORIES(src/cdogs/enet/include)
ENDIF()
if(NOT USE_SHARED_ENET)
include_directories(src/cdogs/enet/include)
endif()

if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MP -W4 -WX -wd\"4090\" -wd\"4996\" -wd\"4204\"")
if(DEBUG)
ADD_DEFINITIONS(-ZI)
add_definitions(-ZI)
endif()
else()
add_definitions(
-fsigned-char
-Wall -W
-Wstrict-prototypes -Wpointer-arith -Wcast-qual)
if(DEBUG)
ADD_DEFINITIONS(-g)
add_definitions(-g)
if(DEBUG_PROFILE AND CMAKE_COMPILER_IS_GNUCC)
ADD_DEFINITIONS(-p)
add_definitions(-p)
endif()
else()
ADD_DEFINITIONS(-O2)
add_definitions(-O2)
endif()
if(GCW0)
add_definitions(-D__GCWZERO__)
Expand Down Expand Up @@ -147,22 +147,22 @@ if(WIN32)
set(CDOGS_CFG_DIR "C-Dogs SDL/")
else()
set(CDOGS_CFG_DIR ".config/cdogs-sdl/")
ENDIF()
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ".")
IF(UNIX AND NOT APPLE)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/build/linux/cdogs-sdl.cmake ${CMAKE_SOURCE_DIR}/build/linux/cdogs-sdl)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/build/linux/cdogs-sdl PROPERTIES GENERATED TRUE)
ENDIF()
IF(WIN32)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/build/windows/cdogs.rc.cmake ${CMAKE_SOURCE_DIR}/build/windows/cdogs.rc)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/build/windows/cdogs.rc PROPERTIES GENERATED TRUE)
ENDIF()
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/src/cdogs/sys_config.h.cmake ${CMAKE_SOURCE_DIR}/src/cdogs/sys_config.h)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/src/cdogs/sys_config.h PROPERTIES GENERATED TRUE)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ".")
if(UNIX AND NOT APPLE)
configure_file(${CMAKE_SOURCE_DIR}/build/linux/cdogs-sdl.cmake ${CMAKE_SOURCE_DIR}/build/linux/cdogs-sdl)
set_source_files_properties(${CMAKE_SOURCE_DIR}/build/linux/cdogs-sdl PROPERTIES GENERATED TRUE)
endif()
if(WIN32)
configure_file(${CMAKE_SOURCE_DIR}/build/windows/cdogs.rc.cmake ${CMAKE_SOURCE_DIR}/build/windows/cdogs.rc)
set_source_files_properties(${CMAKE_SOURCE_DIR}/build/windows/cdogs.rc PROPERTIES GENERATED TRUE)
endif()
configure_file(${CMAKE_SOURCE_DIR}/src/cdogs/sys_config.h.cmake ${CMAKE_SOURCE_DIR}/src/cdogs/sys_config.h)
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/cdogs/sys_config.h PROPERTIES GENERATED TRUE)
include_directories(src src/cdogs)

# Tests
enable_testing()
include(CTest)

add_subdirectory(src)

Expand Down Expand Up @@ -214,7 +214,7 @@ if(BUILD_EDITOR)
DESTINATION ${CDOGS_BIN_DIR})
endif()

INSTALL(DIRECTORY
install(DIRECTORY
${CMAKE_SOURCE_DIR}/data
${CMAKE_SOURCE_DIR}/missions
${CMAKE_SOURCE_DIR}/dogfights
Expand All @@ -226,52 +226,52 @@ INSTALL(DIRECTORY
if(NOT DEFINED CDOGS_DOC_DIR)
set(CDOGS_DOC_DIR "${DATA_INSTALL_DIR}/doc")
endif()
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/doc/
install(DIRECTORY ${CMAKE_SOURCE_DIR}/doc/
DESTINATION ${CDOGS_DOC_DIR}
)

INSTALL(FILES
install(FILES
${CMAKE_SOURCE_DIR}/README.md
DESTINATION ${DATA_INSTALL_DIR})
IF(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/build/linux/io.github.cxong.cdogs-sdl.desktop DESTINATION ${INSTALL_PREFIX}/share/applications)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/build/linux/io.github.cxong.cdogs-sdl.appdata.xml DESTINATION ${INSTALL_PREFIX}/share/metainfo)
if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU)
install(FILES ${CMAKE_SOURCE_DIR}/build/linux/io.github.cxong.cdogs-sdl.desktop DESTINATION ${INSTALL_PREFIX}/share/applications)
install(FILES ${CMAKE_SOURCE_DIR}/build/linux/io.github.cxong.cdogs-sdl.appdata.xml DESTINATION ${INSTALL_PREFIX}/share/metainfo)
foreach(RES 16 22 32 48 128)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/build/linux/cdogs-icon.${RES}.png
install(FILES ${CMAKE_SOURCE_DIR}/build/linux/cdogs-icon.${RES}.png
DESTINATION ${INSTALL_PREFIX}/share/icons/hicolor/${RES}x${RES}/apps
RENAME io.github.cxong.cdogs-sdl.png)
endforeach(RES)
endforeach()
elseif(WIN32)
# Package for Windows
FILE(GLOB DLLS "${CMAKE_SOURCE_DIR}/dll/*.dll")
FOREACH(DLL ${DLLS})
INSTALL(FILES "${DLL}" DESTINATION ${INSTALL_PREFIX}/bin)
ENDFOREACH()
file(GLOB DLLS "${CMAKE_SOURCE_DIR}/dll/*.dll")
foreach(DLL ${DLLS})
install(FILES "${DLL}" DESTINATION ${INSTALL_PREFIX}/bin)
endforeach()
install(DIRECTORY ${CMAKE_SOURCE_DIR}/build/licenses DESTINATION ${INSTALL_PREFIX})
elseif(APPLE)
set(CMAKE_INSTALL_PREFIX "/Applications/cdogs-sdl")
endif()

# Packaging
SET(CPACK_PACKAGE_NAME "C-Dogs.SDL")
SET(CPACK_PACKAGE_VENDOR "C-Dogs SDL Team")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C-Dogs SDL: Action/Arcade Game")
SET(CPACK_PACKAGE_VERSION ${VERSION})
SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
SET(CPACK_PACKAGE_EXECUTABLES "cdogs-sdl;C-Dogs SDL;cdogs-sdl-editor;Campaign Editor")
set(CPACK_PACKAGE_NAME "C-Dogs.SDL")
set(CPACK_PACKAGE_VENDOR "C-Dogs SDL Team")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C-Dogs SDL: Action/Arcade Game")
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_PACKAGE_EXECUTABLES "cdogs-sdl;C-Dogs SDL;cdogs-sdl-editor;Campaign Editor")
if(WIN32)
SET(CPACK_GENERATOR NSIS ZIP)
SET(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/doc/COPYING.GPL)
set(CPACK_GENERATOR NSIS ZIP)
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/doc/COPYING.GPL)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "C-Dogs SDL")
SET(CPACK_NSIS_MUI_ICON ${CMAKE_SOURCE_DIR}/build/windows/cdogs-icon.ico)
set(CPACK_NSIS_MUI_ICON ${CMAKE_SOURCE_DIR}/build/windows/cdogs-icon.ico)
set(CPACK_NSIS_CREATE_ICONS "SetOutPath '\$INSTDIR\\\\bin'
CreateShortCut '\$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\C-Dogs SDL.lnk' '\$INSTDIR\\\\bin\\\\cdogs-sdl.exe'
CreateShortCut '\$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Campaign Editor.lnk' '\$INSTDIR\\\\bin\\\\cdogs-sdl-editor.exe'")
SET(CPACK_NSIS_MUI_FINISHPAGE_RUN cdogs-sdl.exe)
SET(CPACK_NSIS_URL_INFO_ABOUT ${WEBSITE})
set(CPACK_NSIS_MUI_FINISHPAGE_RUN cdogs-sdl.exe)
set(CPACK_NSIS_URL_INFO_ABOUT ${WEBSITE})
elseif(APPLE)
set(CPACK_GENERATOR "DragNDrop")
set(CPACK_DMG_FORMAT "UDBZ")
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ if(BUILD_EDITOR)
endif()
add_subdirectory(json)
add_subdirectory(proto)
add_subdirectory(tests)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()

set(CDOGS_SDL_SOURCES
ammo_menu.c
Expand Down
6 changes: 3 additions & 3 deletions src/cdogs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ set(CDOGS_HEADERS
XGetopt.h
yajl_utils.h)

IF(NOT USE_SHARED_ENET)
ADD_SUBDIRECTORY(enet)
ENDIF()
if(NOT USE_SHARED_ENET)
add_subdirectory(enet)
endif()

add_subdirectory(c_hashmap)
add_subdirectory(cwolfmap)
Expand Down
58 changes: 29 additions & 29 deletions src/cdogs/yajl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,69 +12,69 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

SET (YAJL_MAJOR 2)
SET (YAJL_MINOR 1)
SET (YAJL_MICRO 1)
set (YAJL_MAJOR 2)
set (YAJL_MINOR 1)
set (YAJL_MICRO 1)

SET (SRCS yajl.c yajl_lex.c yajl_parser.c yajl_buf.c
set (SRCS yajl.c yajl_lex.c yajl_parser.c yajl_buf.c
yajl_encode.c yajl_gen.c yajl_alloc.c
yajl_tree.c yajl_version.c
)
SET (HDRS yajl_parser.h yajl_lex.h yajl_buf.h yajl_encode.h yajl_alloc.h)
SET (PUB_HDRS api/yajl_parse.h api/yajl_gen.h api/yajl_common.h api/yajl_tree.h)
set (HDRS yajl_parser.h yajl_lex.h yajl_buf.h yajl_encode.h yajl_alloc.h)
set (PUB_HDRS api/yajl_parse.h api/yajl_gen.h api/yajl_common.h api/yajl_tree.h)

# useful when fixing lexer bugs.
#ADD_DEFINITIONS(-DYAJL_LEXER_DEBUG)
#add_definitions(-DYAJL_LEXER_DEBUG)

# Ensure defined when building YAJL (as opposed to using it from
# another project). Used to ensure correct function export when
# building win32 DLL.
ADD_DEFINITIONS(-DYAJL_BUILD)
add_definitions(-DYAJL_BUILD)

# set up some paths
SET (libDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
SET (incDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include/yajl)
SET (shareDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/share/pkgconfig)
set (libDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
set (incDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include/yajl)
set (shareDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/share/pkgconfig)

# set the output path for libraries
SET(LIBRARY_OUTPUT_PATH ${libDir})
set(LIBRARY_OUTPUT_PATH ${libDir})

ADD_LIBRARY(yajl_s STATIC ${SRCS} ${HDRS} ${PUB_HDRS})
add_library(yajl_s STATIC ${SRCS} ${HDRS} ${PUB_HDRS})

ADD_LIBRARY(yajl SHARED ${SRCS} ${HDRS} ${PUB_HDRS})
add_library(yajl SHARED ${SRCS} ${HDRS} ${PUB_HDRS})

#### setup shared library version number
SET_TARGET_PROPERTIES(yajl PROPERTIES
set_target_properties(yajl PROPERTIES
DEFINE_SYMBOL YAJL_SHARED
SOVERSION ${YAJL_MAJOR}
VERSION ${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO})

#### ensure a .dylib has correct absolute installation paths upon installation
IF(APPLE)
SET_TARGET_PROPERTIES(yajl PROPERTIES
if(APPLE)
set_target_properties(yajl PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF(APPLE)
endif()

#### build up an sdk as a post build step

# create some directories
FILE(MAKE_DIRECTORY ${libDir})
FILE(MAKE_DIRECTORY ${incDir})
file(MAKE_DIRECTORY ${libDir})
file(MAKE_DIRECTORY ${incDir})

# generate build-time source
SET(dollar $)
CONFIGURE_FILE(api/yajl_version.h.cmake ${incDir}/yajl_version.h)
CONFIGURE_FILE(yajl.pc.cmake ${shareDir}/yajl.pc)
set(dollar $)
configure_file(api/yajl_version.h.cmake ${incDir}/yajl_version.h)
configure_file(yajl.pc.cmake ${shareDir}/yajl.pc)

# copy public headers to output directory
FOREACH (header ${PUB_HDRS})
SET (header ${CMAKE_CURRENT_SOURCE_DIR}/${header})
foreach (header ${PUB_HDRS})
set (header ${CMAKE_CURRENT_SOURCE_DIR}/${header})

EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E copy_if_different ${header} ${incDir})
exec_program(${CMAKE_COMMAND} ARGS -E copy_if_different ${header} ${incDir})

ADD_CUSTOM_COMMAND(TARGET yajl_s POST_BUILD
add_custom_command(TARGET yajl_s POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${header} ${incDir})
ENDFOREACH (header ${PUB_HDRS})
endforeach ()

INCLUDE_DIRECTORIES(${incDir}/..)
include_directories(${incDir}/..)

4 changes: 2 additions & 2 deletions src/proto/nanopb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ if(MSVC AND nanopb_MSVC_STATIC_RUNTIME)
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif()
endforeach()
endif()

if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR)
Expand Down

0 comments on commit 0daf4c5

Please sign in to comment.