Skip to content

Commit

Permalink
Indented USE_PRECOMPILED_HEADERS blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeckebans committed Aug 27, 2024
1 parent e54fc22 commit 747878e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 104 deletions.
69 changes: 34 additions & 35 deletions neo/idlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,50 +101,49 @@ if(MSVC)

add_library(idlib ${ID_SOURCES_ALL} ${ID_INCLUDES_ALL})
else()
if (USE_PRECOMPILED_HEADERS)
foreach( src_file ${ID_PRECOMPILED_SOURCES} )
#message(STATUS "-include precompiled.h for ${src_file}")
set_source_files_properties(
${src_file}
PROPERTIES
COMPILE_FLAGS "-include ${CMAKE_CURRENT_SOURCE_DIR}/precompiled.h"
)
endforeach()
endif()

include_directories(.)

if (USE_PRECOMPILED_HEADERS)
# precompiled magic for GCC/clang, adapted from https://gist.github.com/573926
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
SET(_compiler_FLAGS "${${_flags_var_name}} -std=c++${CMAKE_CXX_STANDARD}")
GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS " -I${item}")
ENDFOREACH(item)
endif()
foreach( src_file ${ID_PRECOMPILED_SOURCES} )
#message(STATUS "-include precompiled.h for ${src_file}")
set_source_files_properties(
${src_file}
PROPERTIES
COMPILE_FLAGS "-include ${CMAKE_CURRENT_SOURCE_DIR}/precompiled.h"
)
endforeach()

GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
LIST(APPEND _compiler_FLAGS ${_directory_flags})

SEPARATE_ARGUMENTS(_compiler_FLAGS)
# precompiled magic for GCC/clang, adapted from https://gist.github.com/573926
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
SET(_compiler_FLAGS "${${_flags_var_name}} -std=c++${CMAKE_CXX_STANDARD}")
GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS " -I${item}")
ENDFOREACH(item)

GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
LIST(APPEND _compiler_FLAGS ${_directory_flags})

SEPARATE_ARGUMENTS(_compiler_FLAGS)

if (USE_PRECOMPILED_HEADERS)
if(OPTICK)
LIST(APPEND _compiler_FLAGS -DUSE_OPTICK=1)
else()
LIST(APPEND _compiler_FLAGS -DUSE_OPTICK=0)
endif()
add_custom_target(precomp_header_idlib ALL
COMMAND ${CMAKE_CXX_COMPILER} ${_compiler_FLAGS} -x c++-header precompiled.h -o precompiled.h.gch
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Creating idlib/precompiled.h.gch for idlib"
)
if(OPTICK)
LIST(APPEND _compiler_FLAGS -DUSE_OPTICK=1)
else()
LIST(APPEND _compiler_FLAGS -DUSE_OPTICK=0)
endif()

add_custom_target(precomp_header_idlib ALL
COMMAND ${CMAKE_CXX_COMPILER} ${_compiler_FLAGS} -x c++-header precompiled.h -o precompiled.h.gch
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Creating idlib/precompiled.h.gch for idlib"
)
endif()

add_library(idlib ${ID_SOURCES_ALL} ${ID_INCLUDES_ALL})

if (USE_PRECOMPILED_HEADERS)
add_dependencies(idlib precomp_header_idlib)
add_dependencies(idlib precomp_header_idlib)
endif()

endif()
Expand Down
139 changes: 70 additions & 69 deletions neo/tools/compilers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,18 @@ if(MSVC)
)

# SRS - disable certain MSVC warnings for select third-party source libraries, consider updating versions in the future?
# C4005: macro redefinition, C4244: type conversion with possible loss of data, C4305: trucation from double to float
set_source_files_properties(
${MC_IMTUI_SOURCES} ${MC_IMGUI_SOURCES}
PROPERTIES
COMPILE_FLAGS "/wd4005 /wd4244 /wd4305" # C4005: macro redefinition, C4244: type conversion with possible loss of data, C4305: trucation from double to float
COMPILE_FLAGS "/wd4005 /wd4244 /wd4305"
)

# C4244, C4267: type conversion with possible loss of data, C4996: declared deprecated
set_source_files_properties(
${PDCURSES_SOURCES} ${WINCON_SOURCES}
PROPERTIES
COMPILE_FLAGS "/wd4244 /wd4267 /wd4996" # C4244, C4267: type conversion with possible loss of data, C4996: declared deprecated
COMPILE_FLAGS "/wd4244 /wd4267 /wd4996"
)

add_executable(rbdmap ${MC_SOURCES_ALL} ${MC_INCLUDES_ALL})
Expand All @@ -290,16 +293,7 @@ if(MSVC)
endif()

else()
if (USE_PRECOMPILED_HEADERS)
foreach( src_file ${MC_PRECOMPILED_SOURCES} )
#message(STATUS "-include precompiled.h for ${src_file}")
set_source_files_properties(
${src_file}
PROPERTIES
COMPILE_FLAGS "-include ${CMAKE_CURRENT_SOURCE_DIR}/precompiled.h"
)
endforeach()
endif()
include_directories(.)

# SRS - disable certain gcc/clang warnings for select third-party source libraries, consider updating versions in the future?
set_source_files_properties(
Expand All @@ -309,72 +303,79 @@ else()
COMPILE_FLAGS "-Wno-stringop-overread -Wno-deprecated-non-prototype"
)

include_directories(.)

if (USE_PRECOMPILED_HEADERS)
# precompiled magic for GCC/clang, adapted from https://gist.github.com/573926
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
SET(_compiler_FLAGS "${${_flags_var_name}} -std=c++${CMAKE_CXX_STANDARD}")
GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS " -I${item}")
ENDFOREACH(item)
endif()

GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
LIST(APPEND _compiler_FLAGS ${_directory_flags})

SEPARATE_ARGUMENTS(_compiler_FLAGS)

if (USE_PRECOMPILED_HEADERS)
# SRS - USE_OPTICK not useful for rbdmap, but definition required to avoid mismatch with idlib precompiled header
if(OPTICK)
LIST(APPEND _compiler_FLAGS -DUSE_OPTICK=1)
else()
LIST(APPEND _compiler_FLAGS -DUSE_OPTICK=0)
endif()
add_custom_target(precomp_header_rbdmap ALL
COMMAND ${CMAKE_CXX_COMPILER} ${_compiler_FLAGS} -x c++-header precompiled.h -o precompiled.h.gch
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Creating tools/compilers/precompiled.h.gch for rbdmap"
)
foreach( src_file ${MC_PRECOMPILED_SOURCES} )
#message(STATUS "-include precompiled.h for ${src_file}")
set_source_files_properties(
${src_file}
PROPERTIES
COMPILE_FLAGS "-include ${CMAKE_CURRENT_SOURCE_DIR}/precompiled.h"
)
endforeach()

# precompiled magic for GCC/clang, adapted from https://gist.github.com/573926
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
SET(_compiler_FLAGS "${${_flags_var_name}} -std=c++${CMAKE_CXX_STANDARD}")
GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES)
FOREACH(item ${_directory_flags})
LIST(APPEND _compiler_FLAGS " -I${item}")
ENDFOREACH(item)

GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
LIST(APPEND _compiler_FLAGS ${_directory_flags})

SEPARATE_ARGUMENTS(_compiler_FLAGS)

# SRS - USE_OPTICK not useful for rbdmap, but definition required to avoid mismatch with idlib precompiled header
if(OPTICK)
LIST(APPEND _compiler_FLAGS -DUSE_OPTICK=1)
else()
LIST(APPEND _compiler_FLAGS -DUSE_OPTICK=0)
endif()

add_custom_target(precomp_header_rbdmap ALL
COMMAND ${CMAKE_CXX_COMPILER} ${_compiler_FLAGS} -x c++-header precompiled.h -o precompiled.h.gch
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Creating tools/compilers/precompiled.h.gch for rbdmap"
)
endif()

add_executable(rbdmap ${MC_SOURCES_ALL} ${MC_INCLUDES_ALL})
add_dependencies(rbdmap idlib)

if (USE_PRECOMPILED_HEADERS)
add_dependencies(rbdmap precomp_header_rbdmap)

if(WIN32)
set(remove_command "del")
set(idlib_dir_slash "${CMAKE_SOURCE_DIR}\\idlib\\")
else()
set(remove_command "rm")
set(idlib_dir_slash "${CMAKE_SOURCE_DIR}/idlib/")
add_dependencies(rbdmap precomp_header_rbdmap)

if(WIN32)
set(remove_command "del")
set(idlib_dir_slash "${CMAKE_SOURCE_DIR}\\idlib\\")
else()
set(remove_command "rm")
set(idlib_dir_slash "${CMAKE_SOURCE_DIR}/idlib/")
endif()

# SRS - delete precompiled header file after executable is compiled: command line build case
if(CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja")
add_custom_target(rm_precomp_header_rbdmap ALL
COMMAND ${remove_command} "precompiled.h.gch"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "remove tools/compilers/precompiled.h.gch"
)
add_dependencies(rm_precomp_header_rbdmap rbdmap)

# SRS - delete precompiled header files after executable is compiled: IDE build case (e.g. Xcode)
else()
add_custom_command(TARGET rbdmap POST_BUILD
# SRS - added wildcards to remove tmp files from cmake ZERO_CHECK regeneration
COMMAND ${remove_command} "${idlib_dir_slash}precompiled.h*.gch*"
COMMAND ${remove_command} "precompiled.h*.gch*"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "remove idlib/precompiled.h.gch and tools/compilers/precompiled.h.gch"
)
endif()
endif()

# SRS - delete precompiled header file after executable is compiled: command line build case
if(CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja")
add_custom_target(rm_precomp_header_rbdmap ALL
COMMAND ${remove_command} "precompiled.h.gch"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "remove tools/compilers/precompiled.h.gch"
)
add_dependencies(rm_precomp_header_rbdmap rbdmap)

# SRS - delete precompiled header files after executable is compiled: IDE build case (e.g. Xcode)
else()
add_custom_command(TARGET rbdmap POST_BUILD
# SRS - added wildcards to remove tmp files from cmake ZERO_CHECK regeneration
COMMAND ${remove_command} "${idlib_dir_slash}precompiled.h*.gch*"
COMMAND ${remove_command} "precompiled.h*.gch*"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "remove idlib/precompiled.h.gch and tools/compilers/precompiled.h.gch"
)
endif()
endif()
target_link_libraries(rbdmap idlib ${CURSES_NCURSES_LIBRARY} ${ZLIB_LIBRARY})

endif()


0 comments on commit 747878e

Please sign in to comment.