Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing problems with compilation using C++11 compilers #24

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c554273
Fixing problems with compilation with C++11 compilers
msoos Apr 1, 2015
4d9462e
Remove illegal (and not neccesary) friend definition to fix compilati…
jbransen Jun 19, 2014
3db5894
Fix declaration of Minisat::memUsedPeak for non-Linux systems
rgov Jun 22, 2015
26b58cf
Specify default argument in the declaration not the friend declaration
msoos Mar 19, 2016
25ac527
Fixing Visual Studio build issues
msoos Apr 23, 2017
7d4cb54
Adding appveyor for minisat
msoos Apr 23, 2017
5566d44
Fixing appveyor build
msoos Apr 23, 2017
a98e44f
fixed GCC 6.3 warning: invalid suffix on literal; C++11 requires a sp…
Robbepop Apr 27, 2017
0662095
Merge pull request #1 from Robbepop/master
msoos Apr 27, 2017
99e19fc
Resolve merge conflicts
rgov Mar 7, 2018
29bb7bc
Merge branch 'msoos-master'
rgov Mar 7, 2018
1aa1e87
Fix linking of minisat as dependency library on MacOSX
MartinNowack Jun 29, 2018
a259927
Merge pull request #2 from MartinNowack/patch-1
rgov Jul 2, 2018
dbef978
Quell some clang warnings
bpfoley Feb 12, 2020
47baffb
Merge pull request #4 from bpfoley/clang-warnings
msoos Feb 12, 2020
93da0f0
Fixing static vs. dynamic compile
msoos Feb 28, 2019
a2c6fe6
Export minisat project for other cmake builds
msoos Aug 31, 2020
dd31450
Updating to fix build
msoos Aug 31, 2020
16d13d0
Merge pull request #5 from stp/stp-master
msoos Sep 1, 2020
1193f18
CMakeLists: support different lib dirs
Nov 4, 2019
5f9111f
Removing second STATICCOMPILE
msoos Sep 2, 2020
5b16571
Revert "CMakeLists: support different lib dirs"
msoos Sep 2, 2020
5a38d36
Adding uninstall capability
msoos Sep 2, 2020
37158a3
Fixing exported definitions
msoos Sep 2, 2020
4c8afcd
utils/System.*: use fpu_control only on glibc
xgqt Feb 6, 2023
14c7820
Merge pull request #6 from xgqt/fix_musl
msoos Feb 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 206 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,173 @@ else()
endif()
set(MINISAT_SOVERSION ${MINISAT_SOMAJOR})

# Reference specific library paths used during linking for install
if (POLICY CMP0042)
# Enable `MACOSX_RPATH` by default.
cmake_policy(SET CMP0042 NEW)
endif()
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

#--------------------------------------------------------------------------------------------------
# Dependencies:

find_package(ZLIB)
include_directories(${ZLIB_INCLUDE_DIR})
include_directories(${minisat_SOURCE_DIR})
include (GenerateExportHeader)

#--------------------------------------------------------------------------------------------------
# Compile flags:

add_definitions(-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS)


#--------------------------------------------------------------------------------------------------
option(STATICCOMPILE "Compile static library and executable" OFF)

option(BUILD_SHARED_LIBS "Build the shared library" ON)
if (STATICCOMPILE)
set(BUILD_SHARED_LIBS OFF)
endif()

if (NOT BUILD_SHARED_LIBS)
if (NOT MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -static ")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")

# removing -rdynamic that's automatically added
foreach (language CXX C)
set(VAR_TO_MODIFY "CMAKE_SHARED_LIBRARY_LINK_${language}_FLAGS")
string(REGEX REPLACE "(^| )-rdynamic($| )"
" "
replacement
"${${VAR_TO_MODIFY}}")
#message("Original (${VAR_TO_MODIFY}) is ${${VAR_TO_MODIFY}} replacement is ${replacement}")
set(${VAR_TO_MODIFY} "${replacement}" CACHE STRING "Default flags for ${build_config} configuration" FORCE)
endforeach()
endif()
else ()
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
ENDIF("${isSystemDir}" STREQUAL "-1")

if (APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_INSTALL_RPATH "@loader_path/../lib")
message(STATUS "Using RPATH for dynamic linking")
endif()
endif()

if (NOT MSVC)
add_compile_options( -g)
add_compile_options( -pthread )

add_compile_options("$<$<CONFIG:RELWITHDEBINFO>:-O2>")

add_compile_options("$<$<CONFIG:RELEASE>:-O2>")
add_compile_options("$<$<CONFIG:RELEASE>:-g0>")

add_compile_options("$<$<CONFIG:DEBUG>:-O0>")

if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -O2")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2")
endif()
else()
# see https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx for details
# /ZI = include debug info
# /Wall = all warnings

add_compile_options("$<$<CONFIG:RELWITHDEBINFO>:/O2>")
add_compile_options("$<$<CONFIG:RELWITHDEBINFO>:/ZI>")

add_compile_options("$<$<CONFIG:RELEASE>:/O2>")
add_compile_options("$<$<CONFIG:RELEASE>:/D>")
add_compile_options("$<$<CONFIG:RELEASE>:/NDEBUG>")

add_compile_options("$<$<CONFIG:DEBUG>:/Od>")

if (NOT BUILD_SHARED_LIBS)
# We statically link to reduce dependencies
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
# /MD -- Causes the application to use the multithread-specific
# and DLL-specific version of the run-time library.
# Defines _MT and _DLL and causes the compiler to place
# the library name MSVCRT.lib into the .obj file.
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")

# /MDd -- Defines _DEBUG, _MT, and _DLL and causes the application to use the debug multithread-specific and DLL-specific version of the run-time library.
# It also causes the compiler to place the library name MSVCRTD.lib into the .obj file.
if(${flag_var} MATCHES "/MDd")
string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MDd")
endforeach(flag_var)

# Creates a multithreaded executable (static) file using LIBCMT.lib.
add_compile_options(/MT)
endif()

# buffers security check
add_compile_options(/GS)

# Proper warning level
add_compile_options(/W1)

# Disable STL used in DLL-boundary warning
add_compile_options(/wd4251)
add_compile_options(/D_CRT_SECURE_NO_WARNINGS)

# Wall is MSVC's Weverything, so annoying unless used from the start
# and with judiciously used warning disables
# add_compile_options(/Wall)

# /Za = only ansi C98 & C++11
# /Za is not recommended for use, not tested, etc.
# see: http://stackoverflow.com/questions/5489326/za-compiler-directive-does-not-compile-system-headers-in-vs2010
# add_compile_options(/Za)

add_compile_options(/fp:precise)

# exception handling. s = The exception-handling model that catches C++ exceptions only and tells the compiler to assume that functions declared as extern "C" may throw an exception.
# exception handling. c = If used with s (/EHsc), catches C++ exceptions only and tells the compiler to assume that functions declared as extern "C" never throw a C++ exception.
add_compile_options(/EHsc)

#what does this do?
set(DEF_INSTALL_CMAKE_DIR CMake)
endif()
set(MINISAT_EXPORT_NAME "minisatTargets")

# -----------------------------------------------------------------------------
# Add uninstall target for makefiles
# -----------------------------------------------------------------------------
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)


#--------------------------------------------------------------------------------------------------
# Build Targets:

Expand All @@ -44,27 +199,19 @@ set(MINISAT_LIB_SOURCES
minisat/core/Solver.cc
minisat/simp/SimpSolver.cc)

add_library(minisat-lib-static STATIC ${MINISAT_LIB_SOURCES})
add_library(minisat-lib-shared SHARED ${MINISAT_LIB_SOURCES})

target_link_libraries(minisat-lib-shared ${ZLIB_LIBRARY})
target_link_libraries(minisat-lib-static ${ZLIB_LIBRARY})
add_library(minisat ${MINISAT_LIB_SOURCES})
target_link_libraries(minisat ${ZLIB_LIBRARY})

add_executable(minisat_core minisat/core/Main.cc)
add_executable(minisat_simp minisat/simp/Main.cc)

if(STATIC_BINARIES)
target_link_libraries(minisat_core minisat-lib-static)
target_link_libraries(minisat_simp minisat-lib-static)
else()
target_link_libraries(minisat_core minisat-lib-shared)
target_link_libraries(minisat_simp minisat-lib-shared)
endif()

set_target_properties(minisat-lib-static PROPERTIES OUTPUT_NAME "minisat")
set_target_properties(minisat-lib-shared
target_link_libraries(minisat_core minisat)
target_link_libraries(minisat_simp minisat)

set_target_properties(minisat
PROPERTIES
OUTPUT_NAME "minisat"
OUTPUT_NAME "minisat"
VERSION ${MINISAT_VERSION}
SOVERSION ${MINISAT_SOVERSION})

Expand All @@ -73,11 +220,54 @@ set_target_properties(minisat_simp PROPERTIES OUTPUT_NAME "minisat")
#--------------------------------------------------------------------------------------------------
# Installation targets:

install(TARGETS minisat-lib-static minisat-lib-shared minisat_core minisat_simp
install(TARGETS minisat minisat_core minisat_simp
EXPORT ${MINISAT_EXPORT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

install(DIRECTORY minisat/mtl minisat/utils minisat/core minisat/simp
DESTINATION include/minisat
FILES_MATCHING PATTERN "*.h")

# Setup for export
set(MINISAT_TARGETS_FILENAME "minisatTargets.cmake")
set(MINISAT_CONFIG_FILENAME "minisatConfig.cmake")

# Export targets
export(
TARGETS minisat
FILE "${CMAKE_CURRENT_BINARY_DIR}/${MINISAT_TARGETS_FILENAME}"
)

# Create minisatConfig file
set(EXPORT_TYPE "Build-tree")
set(CONF_INCLUDE_DIRS "${minisat_SOURCE_DIR}/")
configure_file(minisatConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${MINISAT_CONFIG_FILENAME}" @ONLY
)

# Export this package to the CMake user package registry
# Now the user can just use find_package(minisat) on their system
export(PACKAGE minisat)

set(DEF_INSTALL_CMAKE_DIR lib/cmake/minisat)
set(MINISAT_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
"Installation directory for minisat CMake files")

# Create minisatConfig file
set(EXPORT_TYPE "installed")
configure_file(minisatConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${MINISAT_CONFIG_FILENAME}" @ONLY
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${MINISAT_CONFIG_FILENAME}"
DESTINATION "${MINISAT_INSTALL_CMAKE_DIR}"
)

# Install the export set for use with the install-tree
install(
EXPORT ${MINISAT_EXPORT_NAME}
DESTINATION "${MINISAT_INSTALL_CMAKE_DIR}"
)
92 changes: 92 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# branches to build
branches:
# whitelist
only:
- master
- appveyor_debug

# Operating system (build VM template)
os: Visual Studio 2015

# scripts that are called at very beginning, before repo cloning
init:
- git config --global core.autocrlf input


# clone directory
clone_folder: c:\projects\minisat

platform:
- x64
# - x86

environment:
global:
BOOST_ROOT: C:\projects\minisat\boost_1_59_0_install
ZLIB_ROOT: C:\projects\minisat\zlib\myinstall
BUILD_TYPE: Release
MSBUILD_FLAGS: /maxcpucount /nologo

configuration:
- Release

build_script:
#- IF "%PLATFORM%" == "x86" ( SET BOOST_LIBRARYDIR=C:/Libraries/boost_1_59_0/lib32-msvc-14.0)
- IF "%PLATFORM%" == "x86" ( SET CMAKE_GENERATOR="Visual Studio 14 2015")

#- IF "%PLATFORM%" == "x64" ( SET BOOST_LIBRARYDIR=C:/Libraries/boost_1_59_0/lib64-msvc-14.0)
- IF "%PLATFORM%" == "x64" ( SET CMAKE_GENERATOR="Visual Studio 14 2015 Win64")

- echo %PLATFORM%
- echo %BOOST_LIBRARYDIR%
- echo %CMAKE_GENERATOR%
- echo %configuration%
- echo %APPVEYOR_BUILD_FOLDER%
- echo %cd%

# zlib
# TODO check out http://stackoverflow.com/questions/10507893/libzip-with-visual-studio-2010
- cd C:\projects\minisat
- git clone https://github.com/madler/zlib
- cd zlib
- git checkout v1.2.8
- echo %cd%
- mkdir build
- mkdir myinstall
- cd build
- cmake -G %CMAKE_GENERATOR% -DCMAKE_INSTALL_PREFIX=%ZLIB_ROOT% ..
- if %PLATFORM%==x86 call msbuild %MSBUILD_FLAGS% /t:Build /p:Configuration=%CONFIGURATION% /p:Platform="x86" zlib.sln
- if %PLATFORM%==x64 call msbuild %MSBUILD_FLAGS% /t:Build /p:Configuration=%CONFIGURATION% /p:Platform="x64" zlib.sln
- msbuild %MSBUILD_FLAGS% INSTALL.vcxproj
- dir ..\myinstall\

# minisat
- cd C:\projects\minisat
- mkdir build
- mkdir myinstall
- cd build
- cmake -G %CMAKE_GENERATOR% -DCMAKE_INSTALL_PREFIX=%MINISAT_ROOT% -DZLIB_ROOT=%ZLIB_ROOT% ..
- cmake --build . --config %CONFIGURATION%
- dir ..\myinstall\


build:
# project: INSTALL.vcxproj # path to Visual Studio solution or project
parallel: true
verbosity: minimal


# scripts to run after build
after_build:
- 7z a c:\projects\minisat\minisat.zip %APPVEYOR_BUILD_FOLDER%\build -tzip
- cd c:\projects\minisat

artifacts:
- path: minisat.zip
name: minisat.zip

deploy_script:
#- cd c:\projects\minisat
#- curl -T minisat.zip --user %ACCOUNT% https://someplace/

test: off
24 changes: 24 additions & 0 deletions cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_policy(SET CMP0007 NEW) # Suppress warnings see `cmake --help-policy CMP0007`

if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")

file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
list(REVERSE files)
foreach (file ${files})
message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
if (EXISTS "$ENV{DESTDIR}${file}")
execute_process(
COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}"
OUTPUT_VARIABLE rm_out
RESULT_VARIABLE rm_retval
)
if(NOT ${rm_retval} EQUAL 0)
message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
endif (NOT ${rm_retval} EQUAL 0)
else (EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
endif (EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)
10 changes: 5 additions & 5 deletions minisat/core/Solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,11 @@ void Solver::printStats() const
{
double cpu_time = cpuTime();
double mem_used = memUsedPeak();
printf("restarts : %"PRIu64"\n", starts);
printf("conflicts : %-12"PRIu64" (%.0f /sec)\n", conflicts , conflicts /cpu_time);
printf("decisions : %-12"PRIu64" (%4.2f %% random) (%.0f /sec)\n", decisions, (float)rnd_decisions*100 / (float)decisions, decisions /cpu_time);
printf("propagations : %-12"PRIu64" (%.0f /sec)\n", propagations, propagations/cpu_time);
printf("conflict literals : %-12"PRIu64" (%4.2f %% deleted)\n", tot_literals, (max_literals - tot_literals)*100 / (double)max_literals);
printf("restarts : %" PRIu64 "\n", starts);
printf("conflicts : %-12" PRIu64 " (%.0f /sec)\n", conflicts , conflicts /cpu_time);
printf("decisions : %-12" PRIu64 " (%4.2f %% random) (%.0f /sec)\n", decisions, (float)rnd_decisions*100 / (float)decisions, decisions /cpu_time);
printf("propagations : %-12" PRIu64 " (%.0f /sec)\n", propagations, propagations/cpu_time);
printf("conflict literals : %-12" PRIu64 " (%4.2f %% deleted)\n", tot_literals, (max_literals - tot_literals)*100 / (double)max_literals);
if (mem_used != 0) printf("Memory used : %.2f MB\n", mem_used);
printf("CPU time : %g s\n", cpu_time);
}
Expand Down
Loading