2014-03-16 22:40:59 +00:00
function ( enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME )
set ( files ${ SOURCE_VARIABLE_NAME } )
# Generate a unique filename for the unity build translation unit
set ( unit_build_file ${ CMAKE_CURRENT_BINARY_DIR } /ub_ ${ UB_SUFFIX } .cpp )
# Exclude all translation units from compilation
set_source_files_properties ( ${ files } PROPERTIES HEADER_FILE_ONLY true )
# Open the ub file
FILE ( WRITE ${ unit_build_file } "// Unity Build generated by CMake\n" )
# Add include statement for each translation unit
foreach ( source_file ${ files } )
FILE ( APPEND ${ unit_build_file } "#include <${source_file}>\n" )
endforeach ( source_file )
# Complement list of translation units with the name of ub
set ( ${ SOURCE_VARIABLE_NAME } ${ ${SOURCE_VARIABLE_NAME } } ${ unit_build_file } PARENT_SCOPE )
endfunction ( enable_unity_build )
2011-10-22 11:55:06 +00:00
macro ( add_openmw_dir dir )
2014-03-16 22:40:59 +00:00
set ( files )
set ( cppfiles )
foreach ( u ${ ARGN } )
# Add cpp and hpp to OPENMW_FILES
file ( GLOB ALL "${dir}/${u}.[ch]pp" )
foreach ( f ${ ALL } )
list ( APPEND files "${f}" )
list ( APPEND OPENMW_FILES "${f}" )
endforeach ( f )
# Add cpp to unity build
file ( GLOB ALL "${dir}/${u}.cpp" )
foreach ( f ${ ALL } )
list ( APPEND cppfiles "${f}" )
endforeach ( f )
endforeach ( u )
if ( OPENMW_UNITY_BUILD )
enable_unity_build ( ${ dir } "${cppfiles}" )
list ( APPEND OPENMW_FILES ${ CMAKE_CURRENT_BINARY_DIR } /ub_ ${ dir } .cpp )
endif ( )
source_group ( "apps\\openmw\\${dir}" FILES ${ files } )
2011-10-22 11:55:06 +00:00
endmacro ( add_openmw_dir )
2011-11-06 08:30:15 +00:00
macro ( add_component_dir dir )
2014-03-16 22:40:59 +00:00
set ( files )
set ( cppfiles )
foreach ( u ${ ARGN } )
file ( GLOB ALL "${dir}/${u}.[ch]pp" )
foreach ( f ${ ALL } )
list ( APPEND files "${f}" )
list ( APPEND COMPONENT_FILES "${f}" )
endforeach ( f )
# Add cpp to unity build
file ( GLOB ALL "${dir}/${u}.cpp" )
foreach ( f ${ ALL } )
list ( APPEND cppfiles "${f}" )
endforeach ( f )
endforeach ( u )
if ( OPENMW_UNITY_BUILD )
enable_unity_build ( ${ dir } "${cppfiles}" )
list ( APPEND COMPONENT_FILES ${ CMAKE_CURRENT_BINARY_DIR } /ub_ ${ dir } .cpp )
endif ( )
source_group ( "components\\${dir}" FILES ${ files } )
2011-11-06 08:30:15 +00:00
endmacro ( add_component_dir )
2012-07-03 22:26:57 +00:00
2013-01-27 21:40:38 +00:00
macro ( add_component_qt_dir dir )
set ( files )
foreach ( u ${ ARGN } )
2013-02-27 22:44:20 +00:00
file ( GLOB ALL "${dir}/${u}.[ch]pp" )
2013-01-27 21:40:38 +00:00
foreach ( f ${ ALL } )
list ( APPEND files "${f}" )
list ( APPEND COMPONENT_FILES "${f}" )
endforeach ( f )
2013-02-27 22:44:20 +00:00
file ( GLOB MOC_H "${dir}/${u}.hpp" )
2013-01-27 21:40:38 +00:00
foreach ( fi ${ MOC_H } )
list ( APPEND COMPONENT_MOC_FILES "${fi}" )
endforeach ( fi )
endforeach ( u )
source_group ( "components\\${dir}" FILES ${ files } )
endmacro ( add_component_qt_dir )
2012-07-20 21:31:49 +00:00
macro ( copy_all_files source_dir destination_dir files )
foreach ( f ${ files } )
2012-07-03 22:26:57 +00:00
get_filename_component ( filename ${ f } NAME )
2012-07-20 21:31:49 +00:00
configure_file ( ${ source_dir } / ${ f } ${ destination_dir } / ${ filename } COPYONLY )
2012-07-03 22:26:57 +00:00
endforeach ( f )
endmacro ( copy_all_files )
2013-02-03 12:30:40 +00:00
macro ( add_file project type file )
list ( APPEND ${ project } ${ type } ${ file } )
endmacro ( add_file )
macro ( add_unit project dir unit )
add_file ( ${ project } _HDR ${ comp } "${dir}/${unit}.hpp" )
add_file ( ${ project } _SRC ${ comp } "${dir}/${unit}.cpp" )
endmacro ( add_unit )
macro ( add_qt_unit project dir unit )
add_file ( ${ project } _HDR ${ comp } "${dir}/${unit}.hpp" )
add_file ( ${ project } _HDR_QT ${ comp } "${dir}/${unit}.hpp" )
add_file ( ${ project } _SRC ${ comp } "${dir}/${unit}.cpp" )
endmacro ( add_qt_unit )
macro ( add_hdr project dir unit )
add_file ( ${ project } _HDR ${ comp } "${dir}/${unit}.hpp" )
endmacro ( add_hdr )
macro ( add_qt_hdr project dir unit )
add_file ( ${ project } _HDR ${ comp } "${dir}/${unit}.hpp" )
add_file ( ${ project } _HDR_QT ${ comp } "${dir}/${unit}.hpp" )
endmacro ( add_qt_hdr )
macro ( opencs_units dir )
foreach ( u ${ ARGN } )
add_qt_unit ( OPENCS ${ dir } ${ u } )
endforeach ( u )
endmacro ( opencs_units )
macro ( opencs_units_noqt dir )
foreach ( u ${ ARGN } )
add_unit ( OPENCS ${ dir } ${ u } )
endforeach ( u )
2013-02-03 15:18:17 +00:00
endmacro ( opencs_units_noqt )
2013-02-03 12:30:40 +00:00
macro ( opencs_hdrs dir )
foreach ( u ${ ARGN } )
add_qt_hdr ( OPENCS ${ dir } ${ u } )
endforeach ( u )
endmacro ( opencs_hdrs )
macro ( opencs_hdrs_noqt dir )
foreach ( u ${ ARGN } )
add_hdr ( OPENCS ${ dir } ${ u } )
endforeach ( u )
2013-02-03 15:18:17 +00:00
endmacro ( opencs_hdrs_noqt )
2017-09-08 21:17:42 +00:00
2017-09-09 16:22:55 +00:00
include ( CMakeParseArguments )
2017-09-08 21:17:42 +00:00
macro ( openmw_add_executable target )
2017-09-09 16:22:55 +00:00
set ( OMW_ADD_EXE_OPTIONS WIN32 MACOSX_BUNDLE EXCLUDE_FROM_ALL )
set ( OMW_ADD_EXE_VALUES )
set ( OMW_ADD_EXE_MULTI_VALUES )
cmake_parse_arguments ( OMW_ADD_EXE "${OMW_ADD_EXE_OPTIONS}" "${OMW_ADD_EXE_VALUES}" "${OMW_ADD_EXE_MULTI_VALUES}" ${ ARGN } )
if ( OMW_ADD_EXE_WIN32 )
set ( OMW_ADD_EXE_WIN32_VALUE WIN32 )
endif ( OMW_ADD_EXE_WIN32 )
if ( OMW_ADD_EXE_MACOSX_BUNDLE )
set ( OMW_ADD_EXE_MACOSX_BUNDLE_VALUE MACOSX_BUNDLE )
endif ( OMW_ADD_EXE_MACOSX_BUNDLE )
if ( OMW_ADD_EXE_EXCLUDE_FROM_ALL )
set ( OMW_ADD_EXE_EXCLUDE_FROM_ALL_VALUE EXCLUDE_FROM_ALL )
endif ( OMW_ADD_EXE_EXCLUDE_FROM_ALL )
2017-09-10 02:18:22 +00:00
# AnyOldName3 says: I have no idea why or if it's even supposed to happen, but somehow entering this macro confuses CMake about which policies should be set. They are restored here.
cmake_policy ( SET CMP0003 NEW )
cmake_policy ( SET CMP0020 NEW )
2017-09-09 16:22:55 +00:00
2017-09-10 02:18:22 +00:00
add_executable ( ${ target } ${ OMW_ADD_EXE_WIN32_VALUE } ${ OMW_ADD_EXE_MACOSX_BUNDLE_VALUE } ${ OMW_ADD_EXE_EXCLUDE_FROM_ALL_VALUE } ${ OMW_ADD_EXE_UNPARSED_ARGUMENTS } )
2017-09-09 16:22:55 +00:00
2017-09-08 21:17:42 +00:00
if ( MSVC )
2017-09-09 02:06:03 +00:00
if ( CMAKE_VERSION VERSION_GREATER 3.8 OR CMAKE_VERSION VERSION_EQUAL 3.8 )
2017-09-08 21:17:42 +00:00
set_target_properties ( ${ target } PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$(TargetDir)" )
2017-09-09 02:06:03 +00:00
endif ( CMAKE_VERSION VERSION_GREATER 3.8 OR CMAKE_VERSION VERSION_EQUAL 3.8 )
2017-09-08 21:17:42 +00:00
endif ( MSVC )
endmacro ( openmw_add_executable )