@@ -45,6 +45,43 @@ def autogenerated_notice():
4545 return '\n ' .join (s )
4646
4747
48+ def gen_cmake_options_wrappers ():
49+ s = """\n # Options handling utilities
50+ include(CMakeDependentOption)
51+ # Macro for printing an option in a consistent manner
52+ # Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
53+ # Syntax: print_option(<option to print> <was specified>)
54+ macro(print_option variable default)
55+ if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")
56+ message(STATUS "Setting (unspecified) option ${variable}: ${default}")
57+ else()
58+ message(STATUS "Setting option ${variable}: ${${variable}}")
59+ endif()
60+ endmacro()
61+
62+ # Wraps an option with default ON/OFF. Adds nice messaging to option()
63+ # Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
64+ # Syntax: option_with_print(<option name> <description> <default value>)
65+ macro(option_with_print variable msge default)
66+ print_option(${variable} ${default})
67+ option(${variable} ${msge} ${default})
68+ endmacro()
69+
70+ # Wraps an option with a default other than ON/OFF and prints it
71+ # Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
72+ # NOTE: Can't combine with above b/c CMake handles ON/OFF options specially
73+ # NOTE2: CMake variables are always defined so need to further check for if
74+ # they are the NULL string. This is also why we need the force
75+ # Syntax: option_with_default(<option name> <description> <default value>)
76+ macro(option_with_default variable msge default)
77+ print_option(${variable} "${default}")
78+ if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")
79+ set(${variable} "${default}" CACHE STRING ${msge} FORCE)
80+ endif()
81+ endmacro()"""
82+ return s
83+
84+
4885def gen_setup (config , default_build_type , relative_path , setup_script_name ):
4986 """
5087 Generate setup script.
@@ -132,7 +169,7 @@ def gen_cmakelists(project_name, project_language, min_cmake_version, default_bu
132169 s .append ('cmake_minimum_required(VERSION {0} FATAL_ERROR)' .format (min_cmake_version ))
133170
134171 s .append ('\n # project name' )
135- s .append ('project({0} {1})' .format (project_name , project_language ))
172+ s .append ('project({0} LANGUAGES {1})' .format (project_name , project_language ))
136173
137174 s .append ('\n # do not rebuild if rules (compiler flags) change' )
138175 s .append ('set(CMAKE_SKIP_RULE_DEPENDENCY TRUE)' )
@@ -148,6 +185,8 @@ def gen_cmakelists(project_name, project_language, min_cmake_version, default_bu
148185 s .append (' set(CMAKE_BUILD_TYPE "{0}")' .format (_build_type ))
149186 s .append ('endif()' )
150187
188+ s .append (gen_cmake_options_wrappers ())
189+
151190 if len (modules ) > 0 :
152191 s .append ('\n # directories which hold included cmake modules' )
153192
@@ -159,7 +198,7 @@ def gen_cmakelists(project_name, project_language, min_cmake_version, default_bu
159198 rel_cmake_module_path = os .path .join (relative_path , directory )
160199 # on windows cmake corrects this so we have to make it wrong again
161200 rel_cmake_module_path = rel_cmake_module_path .replace ('\\ ' , '/' )
162- s .append ('set(CMAKE_MODULE_PATH ${{ CMAKE_MODULE_PATH}} ${{PROJECT_SOURCE_DIR}}/{0})' .format (rel_cmake_module_path ))
201+ s .append ('list(APPEND CMAKE_MODULE_PATH ${{PROJECT_SOURCE_DIR}}/{0})' .format (rel_cmake_module_path ))
163202
164203 if len (modules ) > 0 :
165204 s .append ('\n # included cmake modules' )
0 commit comments