Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Refactored common cmake settings.
Browse files Browse the repository at this point in the history
DRY (Don't Repeat Yourself) principle: set flags in one place
and reuse from other locations.
  • Loading branch information
Randall Britten committed Mar 30, 2015
1 parent 799e632 commit 54de041
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 12 additions & 0 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
macro(INITIALISE_PROJECT)
if(WIN32)
set(CMAKE_CXX_FLAGS "/W3")
else()
set(CMAKE_CXX_FLAGS "-Wall -W -Werror")
endif()

if (MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc")
endif()

endmacro()
5 changes: 1 addition & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.cmake_minimum_required (VERSION 3.1)

INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake)

set(CELLML_EXPORT_H "${CMAKE_CURRENT_BINARY_DIR}/api/libcellml/libcellml_export.h")
set(LIBCELLML_CONFIG_H "${CMAKE_CURRENT_BINARY_DIR}/libcellml_config.h")
Expand Down Expand Up @@ -97,8 +98,4 @@ install(FILES

install(EXPORT libcellml-targets DESTINATION lib/cmake)

if (MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc")
endif()

set_target_properties(cellml PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
6 changes: 2 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.cmake_minimum_required (VERSION 3.1)

INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake)

# This adds another subdirectory, which has 'project(gtest)'.
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.7.0)

Expand Down Expand Up @@ -46,8 +48,4 @@ target_link_libraries(libcellmlTest cellml)
# test executable.
add_test(libcellmlTest libcellmlTest)

if (MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc")
endif()

set_target_properties(libcellmlTest PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)

2 comments on commit 54de041

@agarny
Copy link
Contributor

@agarny agarny commented on 54de041 Mar 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To include common.cmake is indeed what must be done, but next you need to call the macro, i.e. have something like:

INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake)

INITIALISE_PROJECT()

@codecurve
Copy link
Contributor

@codecurve codecurve commented on 54de041 Mar 30, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.